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, objective_factory_class: type[ObjectiveFactory] | None = None)

Bases: object

Handle 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_elements and elt_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 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, objective_factory_class: type[ObjectiveFactory] | None = None) 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 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 own ObjectiveFactory without altering the source code.

fix(optimisation_algorithm: OptimisationAlgorithm) OptiSol

Fix the Fault. Set self.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:

OptiSol

property info: dict

Return the dictionary holding information on the solution.

Deprecated since version 0.8.2: Prefer using the opti_sol attribute.

property optimized_cavity_settings: SetOfCavitySettings

Get the best settings.

property success: bool

Get the success status.

update_elements_status(optimisation: str, success: bool | None = None) None

Update status of compensating and failed elements.

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.

classmethod from_pickle(pickler: MyPickler, path: Path | str) Self

Instantiate object from previously pickled file.