workflow_setup module

Define helper functions to set up LightWin workflow.

set_up_solvers(config: dict[str, dict[str, Any]]) tuple[BeamCalculator, ...]

Create the beam calculators.

Parameters:

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

Returns:

beam_calculators – The objects that will compute the beam propagation.

Return type:

tuple[BeamCalculator, …]

set_up_accelerators(config: dict[str, dict[str, Any]], beam_calculators: tuple[BeamCalculator, ...]) list[Accelerator]

Create the accelerators.

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

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

Returns:

The instantiated Accelerator. If there is no fault defined, we return a single Accelerator. If there is a fault, we return a reference Accelerator and a broken one.

Return type:

list[Accelerator]

set_up_faults(config: dict[str, dict[str, Any]], beam_calculator: BeamCalculator, accelerators: list[Accelerator], objective_factory_class: type[ObjectiveFactory] | None = None, **kwargs) list[FaultScenario]

Create all the Fault, gather them in FaultScenario.

Parameters:
  • config (dict[str, dict[str, Any]]) – 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, optional) – If provided, will override the objective_preset. Used to let user define it’s own ObjectiveFactory without altering the source code.

Returns:

The instantiated fault scenarios.

Return type:

list[FaultScenario]

set_up(config: dict[str, dict[str, Any]], **kwargs) tuple[tuple[BeamCalculator, ...], list[Accelerator], list[FaultScenario] | None, list[SimulationOutput]]

Create all the objects used in a typical LightWin simulation.

Parameters:

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

Returns:

  • beam_calculators (tuple[BeamCalculator, …]) – 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 (list[Accelerator]) – 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_scenarioslist[FaultScenario] | None

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

    ref_simulations_outputslist[SimulationOutput]

    A reference SimulationOutput corresponding to the nominal linac per BeamCalculator.

fix(fault_scenarios: Collection[FaultScenario] | None) None

Fix all the generated faults.

Parameters:

fault_scenarios (list[FaultScenario] | None) – The created failures. Will be None if no "wtf" entry was given in config.

recompute(beam_calculators: Collection[BeamCalculator], references: Collection[SimulationOutput], *accelerators: Accelerator) list[list[SimulationOutput]]

Recompute accelerator after a fix with more precision.

Parameters:
Returns:

A nested list of simulation results.

Return type:

list[list[SimulationOutput]]

run_simulation(config: dict[str, Any], **kwargs) list[FaultScenario] | list[Accelerator]

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]