fault_scenario module
Define a list-based class holding all the Fault to fix.
We also define fault_scenario_factory(), a factory function creating all
the required FaultScenario objects.
- class FaultScenario(ref_acc, fix_acc, beam_calculator, wtf, design_space_factory, fault_idx, comp_idx=None, info_other_sol=None, objective_factory_class=None, **kwargs)[source]
-
A class to hold all fault related data.
- Parameters:
ref_acc (
Accelerator)fix_acc (
Accelerator)beam_calculator (
BeamCalculator)design_space_factory (
DesignSpaceFactory)fault_idx (
Sequence[int] |list[str] |Sequence[Sequence[int]] |list[list[str]])comp_idx (
Sequence[Sequence[int]] |list[list[str]] |None, default:None)objective_factory_class (
type[ObjectiveFactory] |None, default:None)
- __init__(ref_acc, fix_acc, beam_calculator, wtf, design_space_factory, fault_idx, comp_idx=None, info_other_sol=None, objective_factory_class=None, **kwargs)[source]
Create the
FaultScenarioand theFaultobjects.- Parameters:
ref_acc (
Accelerator) – The reference linac (nominal or baseline).fix_acc (
Accelerator) – The broken linac to be fixed.beam_calculator (
BeamCalculator) – The solver that will be called during the optimisation process.wtf (
dict[str,Any]) – What To Fit dictionary. Holds information on the fixing method.design_space_factory (
DesignSpaceFactory) – An object to easily create the properDesignSpace.fault_idx (
Sequence[int] |list[str] |Sequence[Sequence[int]] |list[list[str]]) – List containing the position of the errors. Ifstrategyis manual, it is a list of lists (faults already gathered).comp_idx (
Sequence[Sequence[int]] |list[list[str]] |None, default:None) – List containing the position of the compensating cavities. Ifstrategyis manual, it must be provided.info_other_sol (
list[dict] |None, default:None) – Contains information on another fit, for comparison purposes.objective_factory_class (
type[ObjectiveFactory] |None, default:None) – If provided, will override theobjective_preset. Used to let user define it’s ownObjectiveFactorywithout altering the source code.
- Return type:
None
- property _reference_simulation_output: SimulationOutput
Determine wich
SimulationOutputis the reference.
- _wrap_fix(fault, simulation_output)[source]
Fix the fault and recompute propagation with new settings.
- Orchestrates:
build
DesignSpacebuild
ObjectiveFactory(objectives + residuals routine)create
OptimisationAlgorithm(solver) using factories aboverun
Fault.fix()postprocess and logging
- Parameters:
fault (
Fault) – The fault to fix.simulation_output (
SimulationOutput) – The most recent simulation, that includes the compensation settings of allFaultupstream offault.
- Return type:
- Returns:
Most recent simulation, that includes the compensation settings of upstream
Faultas well as of this one.
- _prepare_fix_objects(fault, simulation_output)[source]
Create objects to instantiate the
OptimisationAlgorithm.In particular: - build
DesignSpace- buildObjectiveFactory- extractListOfElementscorresponding to zone to recomputethis
subset_eltsis kept as aFaultattribute.
create
OptimisationAlgorithm. - ifskip_optimizationisTrue, we ratherinstantiate the special
PredefinedSolution.
- Parameters:
fault (
Fault) – The fault to fix.simulation_output (
SimulationOutput) – The most recent simulation, that includes the compensation settings of allFaultupstream offault.
- Return type:
- Returns:
Object that will fix the failure.
- _evaluate_fit_quality(save=True, id_solver_ref=None, id_solver_fix=None)[source]
Compute some quantities on the whole linac to see if fit is good.
- Parameters:
save (
bool, default:True) – To tell if you want to save the evaluation.id_solver_ref (
str|None, default:None) – Id of the solver from which you want reference results. The default is None. In this case, the first solver is taken (beam_calc_param).id_solver_fix (
str|None, default:None) – Id of the solver from which you want fixed results. The default is None. In this case, the solver is the same as for reference.
- Return type:
- _set_evaluation_elements(additional_elt=None)[source]
Set a the proper list of where to check the fit quality.
- _simulations_that_should_be_compared(id_solver_ref, id_solver_fix)[source]
Get proper
SimulationOutputfor comparison.- Parameters:
- Return type:
- 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.
- _mark_cavities_to_rephase()[source]
Change the status of cavities after first failure.
Only cavities with a reference phase different from
"phi_0_abs"are altered.Todo
Could probably be simpler.
- Return type:
- _ensure_phi0_is_preserved()[source]
Transfer the reference phases from reference linac to broken.
If the absolute initial phases are not kept between reference and broken linac, it comes down to rephasing the linac. This is what we want to avoid when
BeamCalculator.reference_phase_policyis set to"phi_0_abs".If the linac was already fixed, we simply skip this step.
- Return type:
- property _reference_phase_policy: Literal['phi_0_abs', 'phi_0_rel', 'phi_s', 'as_in_original_dat']
Give reference phase policy of
BeamCalculator.
- _resolve_reference_phase(reference_cavity)[source]
Get the reference phase matching the reference phase policy.
According to the value of
BeamCalculator.reference_phase_policy:"phi_0_abs","phi_0_rel","phi_s": take this reference.`"as_in_original_dat": take reference fromreference_cavity.
- class FaultScenarioFactory(accelerators, beam_calc, design_space, objective_factory_class=None)[source]
Bases:
objectThis objects consistently create
FaultScenario.- Parameters:
accelerators (
dict[int,list[Accelerator]])beam_calc (
BeamCalculator)design_space (
DesignSpaceKw)objective_factory_class (
type[ObjectiveFactory] |None, default:None)
- __init__(accelerators, beam_calc, design_space, objective_factory_class=None)[source]
Init solver parameters for each non-unpickled
Accelerator.- Parameters:
accelerators (
dict[int,list[Accelerator]]) – Dictionary where keys areFaultScenarioindexes, and values are lists of correspondingAccelerator. First index corresponds to reference accelerator (no failure).beam_calc (
BeamCalculator) – The solver that will be called during the optimisation process.design_space_kw – The design space table from the TOML configuration file.
objective_factory_class (
type[ObjectiveFactory] |None, default:None) – If provided, will override theobjective_preset. Used to let user define it’s ownObjectiveFactorywithout altering the source code.design_space (
DesignSpaceKw)
- Returns:
Holds all the initialized
FaultScenarioobjects, holding their already initialiedFaultobjects.- Return type:
None
- create(failed, compensating_manual=None, **wtf)[source]
- Overloads:
self, failed (NESTED_ELEMENTS_ID), compensating_manual (None), wtf → list[FaultScenario]
self, failed (list[NESTED_ELEMENTS_ID]), compensating_manual (list[NESTED_ELEMENTS_ID]), wtf → list[FaultScenario]
- Parameters:
- Return type:
Instantiate fault scenarios.
- Parameters:
failed (
Sequence[Sequence[int]] |list[list[str]] |list[Sequence[Sequence[int]] |list[list[str]]]) – Index or name of the failed cavities.compensating_manual (
list[Sequence[Sequence[int]] |list[list[str]]] |None, default:None) – List of compensating cavities associated withfailed.wtf – The WhatToFit table of the
TOMLconfiguration file.
- Return type:
- fault_scenario_factory(accelerators, beam_calc, wtf, design_space, objective_factory_class=None, **kwargs)[source]
Create the
FaultScenarioobjects (factory template).Deprecated since version 0.14.1: Prefer the more flexible:
factory = FaultScenarioFactory( accelerators=accelerators, beam_calc=beam_calc, design_space=design_space, objective_factory_class=objective_factory_class, ) fault_scenarios = factory.create(**wtf)
- Parameters:
accelerators (
list[Accelerator]) – Holds all the linacs. The first one must be the reference linac, while all the others will be to be fixed.beam_calc (
BeamCalculator) – The solver that will be called during the optimisation process.wtf (
dict[str,Any]) – The WhatToFit table of the TOML configuration file.design_space_kw – The design space table from the TOML configuration file.
objective_factory_class (
type[ObjectiveFactory] |None, default:None) – If provided, will override theobjective_preset. Used to let user define it’s ownObjectiveFactorywithout altering the source code.
- Return type:
- Returns:
Holds all the initialized
FaultScenarioobjects, holding their already initialiedFaultobjects.
- _force_element_to_index_method_creation(accelerator, beam_calculator)[source]
Run a first simulation to link
Elementwith their index.Note
To initalize a
Fault, you need a sub|LOE|. To create the latter, you need a_element_to_indexmethod. It can only be created if you know the number of steps in everyElement. So, forTraceWin, we run a first simulation.- Parameters:
accelerator (
Accelerator)beam_calculator (
BeamCalculator)
- Return type: