failures.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: ListOfElements, reference_simulation_output: SimulationOutput, files_from_full_list_of_elements: dict[str, Any], wtf: dict[str, Any], design_space_factory: DesignSpaceFactory, broken_elts: ListOfElements, failed_elements: list[Element], compensating_elements: list[Element], list_of_elements_factory: ListOfElementsFactory)
Bases:
object
Handle and fix a single failure.
- elts
Holds the portion of the linac that will be computed again and again in the optimisation process. It is as short as possible, but must contain all
failed_elements
,compensating_elements
andelt_eval_objectives
.- Type:
- constraints
Holds infomation on the optimisation constraints.
- Type:
list[Constraint] | None
- 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
SimulationOutput
and returns the residues of every objective w.r.t the reference one.
- __init__(reference_elts: ListOfElements, reference_simulation_output: SimulationOutput, files_from_full_list_of_elements: dict[str, Any], wtf: dict[str, Any], design_space_factory: DesignSpaceFactory, broken_elts: ListOfElements, failed_elements: list[Element], compensating_elements: list[Element], list_of_elements_factory: ListOfElementsFactory) None
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) –
files
attribute 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 optimisation process. It is as short as possible, but must contain all altered elements as well as the elements where objectives will be evaluated.
- fix(optimisation_algorithm: OptimisationAlgorithm) tuple[bool, dict]
Fix the
Fault
. Setoptimized_cavity_settings
.- Parameters:
optimisation_algorithm (OptimisationAlgorithm) – The optimisation algorithm to be used, already initialized.
- Returns:
success (bool) – Indicates convergence of the
OptimisationAlgorithm
.self.info (dict) – Useful information, such as the best solution.
- classmethod from_pickle(pickler: MyPickler, path: Path | str) Self
Instantiate object from previously pickled file.
- pickle(pickler: MyPickler, path: Path | str | None = None) Path
Pickle (save) the object.
This is useful for debug and temporary saves; do not use it for long time saving.
- update_elements_status(optimisation: str, success: bool | None = None) None
Update status of compensating and failed elements.