workflow_setup module

Define helper functions to set up LightWin workflow.

set_up_solvers(config)[source]

Create the beam calculators.

Parameters:

config (dict[str, dict[str, Any] | BeamKwargs]) – The full TOML configuration dictionary.

Return type:

tuple[BeamCalculator, ...]

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 wtf dictionary is updated to explicitly mention the list of failed cavities.

Parameters:
Return type:

list[Accelerator]

Returns:

A nominal Accelerator without failure, and an Accelerator per fault scenario.

set_up_faults(config, beam_calculator, accelerators, objective_factory_class=None, **kwargs)[source]

Create all the Fault, gather them in FaultScenario.

Parameters:
  • config (dict[str, dict[str, Any] | BeamKwargs]) – The full TOML configuration dict.

  • beam_calculator (BeamCalculator) – The object that will be used for the optimization. Usually, a fast solver such as CyEnvelope1D.

  • accelerators (list[Accelerator]) – First object is the reference linac; second object is the one we will break and fix.

  • objective_factory_class (type[ObjectiveFactory] | None, default: None) – If provided, will override the objective_preset. Used to let user define its own ObjectiveFactory without altering the source code.

Return type:

list[FaultScenario]

Returns:

The instantiated fault scenarios.

set_up(config, **kwargs)[source]

Create all the objects used in a typical LightWin simulation.

Parameters:

config (dict[str, dict[str, Any] | BeamKwargs]) – The full TOML configuration dictionary.

Return type:

tuple[tuple[BeamCalculator, ...], 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 – The objects that will store a linac design. Typically, they are two:

    one for the reference linac, and one for the broken/fixed linac.

    fault_scenarios :

    The created failures. Will be None if no "wtf" entry was given in config.

    ref_simulations_outputs :

    A reference SimulationOutput corresponding to the nominal linac per BeamCalculator.

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 in config.

Return type:

None

recompute(beam_calculators, references, *accelerators)[source]

Recompute accelerator after a fix with more precision.

Parameters:
Returns:

A nested list of simulation results.

Return type:

list[list[SimulationOutput]]

run_simulation(config, **kwargs)[source]

Compute propagation of beam; if failures are defined, fix them.

Parameters:

config (dict[str, Any]) – The full TOML configuration dict.

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_acc and FaultScenario.fix_acc.

Return type:

list[FaultScenario] | list[Accelerator]