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 first BeamCalculator, used for optimisation.

  • beam_calculator_post (dict[str, Any] | None, default: None) – Configuration entries for the second optional BeamCalculator, 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 new BeamCalculatorsFactory, reset the BeamCalculator counter. Use this if you want to change the files or beam without restarting the Python kernel – for example during pytest.

  • config – Other TOML configuration dictionaries.

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:
  • config (ConfigKw) – The full TOML configuration dictionary.

  • beam_calculators (tuple[BeamCalculator, ...]) – The objects that will compute the beam propagation.

Return type:

dict[int, list[Accelerator]]

Returns:

Dictionary where keys are FaultScenario indexes, and values are lists of corresponding Accelerator. 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 in FaultScenario.

Parameters:
  • config (ConfigKw) – 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 (dict[int, list[Accelerator]]) – Dictionary where keys are FaultScenario indexes, and values are lists of corresponding Accelerator. First index corresponds to reference accelerator (no failure).

  • 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 (ConfigKw) – The full TOML configuration 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 FaultScenario indexes, 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 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.

Todo

Maybe in some cases we want to also recompute the unpickled Accelerators.

Parameters:
Return type:

list[list[SimulationOutput]]

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_acc and FaultScenario.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 FaultScenario indexes (0 is for reference). Values are corresponding Accelerator as a list; there is typically one Accelerator in each list, and additional ones are unpickled.

  • fault_scenarios – Returned if failure(s) were defined.