fault module
Define the class Fault.
Its purpose is to hold information on a failure and to fix it.
Todo
not clear what happens here. separate __init__ in several functions
Todo
store DesignSpace as attribute rather than Variable Constraint compute_constraints
- class Fault(reference_elts, reference_simulation_output, files_from_full_list_of_elements, wtf, design_space_factory, broken_elts, failed_elements, compensating_elements, list_of_elements_factory, objective_factory_class=None)[source]
Bases:
objectHandle and fix a single failure.
- Parameters:
failed_elements (list[Element]) – Holds the failed elements.
compensating_elements (list[Element]) – Holds the compensating elements.
elts (ListOfElements) – Holds the portion of the linac that will be computed again and again in the optimization process. It is as short as possible, but must contain all
failed_elements,compensating_elementsandelt_eval_objectives.variables (list[Variable]) – Holds information on the optimization variables.
constraints (list[Constraint] | None) – Holds infomation on the optimization constraints.
- compute_constraints : Callable[[SimulationOutput], np.ndarray] | None
Compute the constraint violation for a given
SimulationOutput.
- compute_residuals : Callable[[SimulationOutput], np.ndarray]
A function that takes in a
SimulationOutputand returns the residuals of every objective w.r.t the reference one.
- Parameters:
reference_elts (
ListOfElements)reference_simulation_output (
SimulationOutput)design_space_factory (
DesignSpaceFactory)broken_elts (
ListOfElements)list_of_elements_factory (
ListOfElementsFactory)objective_factory_class (
type[ObjectiveFactory] |None, default:None)
- __init__(reference_elts, reference_simulation_output, files_from_full_list_of_elements, wtf, design_space_factory, broken_elts, failed_elements, compensating_elements, list_of_elements_factory, objective_factory_class=None)[source]
Create the Fault object.
- Parameters:
reference_elts (ListOfElements) – List of elements of the reference linac. In particular, these elements hold the original element settings.
reference_simulation_output (SimulationOutput) – Nominal simulation.
files_from_full_list_of_elements (dict) –
filesattribute from the linac under fixing. Used to set calculation paths.wtf (dict[str, str | int | bool | list[str] | list[float]]) – What To Fit dictionary. Holds information on the fixing method.
design_space_factory (DesignSpaceFactory) – An object to easily create the proper
DesignSpace.failed_elements (list[Element]) – Holds the failed elements.
compensating_elements (list[Element]) – Holds the compensating elements.
elts (list[Element]) – Holds the portion of the linac that will be computed again and again in the optimization process. It is as short as possible, but must contain all altered elements as well as the elements where objectives will be evaluated.
objective_factory_class (type[ObjectiveFactory] | None, optional) – If provided, will override the
objective_preset. Used to let user define it’s ownObjectiveFactorywithout altering the source code.broken_elts (
ListOfElements)list_of_elements_factory (
ListOfElementsFactory)
- fix(optimisation_algorithm)[source]
Fix the
Fault. Setself.optimized_cavity_settings.- Parameters:
optimisation_algorithm (OptimisationAlgorithm) – The optimization algorithm to be used, already initialized.
- Returns:
self.opti_sol – Useful information, such as the best solution.
- Return type:
- property info: dict
Return the dictionary holding information on the solution.
Deprecated since version 0.8.2: Prefer using the
opti_solattribute.
- property optimized_cavity_settings: SetOfCavitySettings
Get the best settings.
- update_elements_status(optimisation, success=None)[source]
Update status of compensating and failed elements.