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: 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 residuals of every objective w.r.t the reference one.

Parameters:
__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) – 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.

  • broken_elts (ListOfElements)

  • list_of_elements_factory (ListOfElementsFactory)

fix(optimisation_algorithm)[source]

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, success=None)[source]

Update status of compensating and failed elements.

Parameters:
  • optimisation (str)

  • success (bool | None, default: None)

Return type:

None

pickle(pickler, path=None)[source]

Pickle (save) the object.

This is useful for debug and temporary saves; do not use it for long time saving.

Parameters:
Return type:

Path

classmethod from_pickle(pickler, path)[source]

Instantiate object from previously pickled file.

Parameters:
Return type:

Self