workflow_setup module
Define helper functions to set up LightWin workflow.
- set_up_solvers(files, beam, beam_calculator, beam_calculator_post=None, reset_factory=False, **config)[source]
Create the beam calculators.
- Parameters:
files (
dict[str,Any]) – Configuration entries for the input/output paths.beam (
BeamKwargs) – Configuration dictionary holding the initial beam parameters.beam_calculator (
dict[str,Any]) – Configuration entries for the firstBeamCalculator, used for optimisation.beam_calculator_post (
dict[str,Any] |None, default:None) – Configuration entries for the second optionalBeamCalculator, used for a more thorough calculation of the beam propagation once the compensation settings are found.reset_factory (
bool, default:False) – Force creation of a newBeamCalculatorsFactory, reset theBeamCalculatorcounter. Use this if you want to change thefilesorbeamwithout restarting the Python kernel – for example duringpytest.config – Other
TOMLconfiguration dictionaries.
- Return type:
- Returns:
The objects that will compute the beam propagation.
- set_up_accelerators(config, beam_calculators)[source]
Create the accelerators.
Note
If an automatic study is asked, the
wtfdictionary is updated to explicitly mention the list of failed cavities.- Parameters:
config (
ConfigKw) – The fullTOMLconfiguration dictionary.beam_calculators (
tuple[BeamCalculator,...]) – The objects that will compute the beam propagation.
- Return type:
dict[int,list[Accelerator]]- Returns:
Dictionary where keys are
FaultScenarioindexes, and values are lists of correspondingAccelerator. First index corresponds to reference accelerator (no failure).
- set_up_faults(config, beam_calculator, accelerators, objective_factory_class=None, **kwargs)[source]
Create all the
Fault, gather them inFaultScenario.- Parameters:
config (
ConfigKw) – The fullTOMLconfiguration dict.beam_calculator (
BeamCalculator) – The object that will be used for the optimization. Usually, a fast solver such asCyEnvelope1D.accelerators (
dict[int,list[Accelerator]]) – Dictionary where keys areFaultScenarioindexes, and values are lists of correspondingAccelerator. First index corresponds to reference accelerator (no failure).objective_factory_class (
type[ObjectiveFactory] |None, default:None) – If provided, will override theobjective_preset. Used to let user define its ownObjectiveFactorywithout altering the source code.
- Return type:
- Returns:
The instantiated fault scenarios.
- set_up(config, **kwargs)[source]
Create all the objects used in a typical LightWin simulation.
- Parameters:
config (
ConfigKw) – The fullTOMLconfiguration dictionary.- Return type:
tuple[tuple[BeamCalculator,...],dict[int,list[Accelerator]],list[FaultScenario] |None,list[SimulationOutput]]- Returns:
beam_calculators – The objects to compute the beam. Typically, they are two: one for the optimization, and a second slower one to run a more precise simulation.
- accelerators – Dictionary where keys are
FaultScenarioindexes, and values are lists of corresponding
Accelerator. First index corresponds to reference accelerator (no failure).- fault_scenarios :
The created failures. Will be None if no
"wtf"entry was given inconfig.- ref_simulations_outputs :
A reference
SimulationOutputcorresponding to the nominal linac perBeamCalculator.
- accelerators – Dictionary where keys are
- fix(fault_scenarios)[source]
Fix all the generated faults.
- Parameters:
fault_scenarios (
Collection[FaultScenario] |None) – The created failures. Will be None if no"wtf"entry was given inconfig.- Return type:
- recompute(beam_calculators, references, accelerators)[source]
Recompute accelerator after a fix with more precision.
Todo
Maybe in some cases we want to also recompute the unpickled Accelerators.
- Parameters:
beam_calculators (
Collection[BeamCalculator]) – One or several beam calculators.references (
Collection[SimulationOutput]) – A referenceSimulationOutputperBeamCalculator, ideally generated by the sameBeamCalculator.accelerators (
dict[int,list[Accelerator]]) – Dictionary where keys areFaultScenarioindexes, and values are lists of correspondingAccelerator. First index corresponds to reference accelerator (no failure).
- Return type:
- Returns:
A nested list of simulation results.
- run_simulation(config, **kwargs)[source]
Compute propagation of beam; if failures are defined, fix them.
- Parameters:
config (
ConfigKw) – The full TOML configuration dict.- Return type:
list[FaultScenario] |dict[int,list[Accelerator]]- Returns:
If no failure is defined, return the created accelerators. If failures were defined, return the full fault scenarios. Note that you can access the accelerator objects with
FaultScenario.ref_accandFaultScenario.fix_acc.
- run_simulation_new(config, **kwargs)[source]
Compute propagation of beam; if failures are defined, fix them.
- Parameters:
config (
ConfigKw) – The full TOML configuration dict.- Return type:
tuple[dict[int,list[Accelerator]],list[FaultScenario] |None]- Returns:
accelerators (dict[int, list[Accelerator]]) – Keys are
FaultScenarioindexes (0 is for reference). Values are correspondingAcceleratoras a list; there is typically oneAcceleratorin each list, and additional ones are unpickled.fault_scenarios – Returned if failure(s) were defined.