factory module

Define a factory to easily create Accelerator.

class AcceleratorFactory(beam_calculators, files, beam, **kwargs)[source]

Bases: object

A class to create accelerators.

Parameters:
__init__(beam_calculators, files, beam, **kwargs)[source]

Facilitate creation of Accelerator objects.

Parameters:
  • beam_calculators (BeamCalculator | Sequence[BeamCalculator | None]) – Objects that will compute propagation of the beam.

  • files (dict[str, Any]) – Configuration entries for the input/output paths.

  • beam (BeamKwargs) – Configuration dictionary holding the initial beam parameters.

  • kwargs – Other configuration dictionaries.

Return type:

None

main_beam_calculator

BeamCalculator that will be used to find compensation settings.

_create_instances(n_objects, is_reference)[source]

Create object.

Parameters:
  • n_objects (int) – Number of objects to create.

  • is_reference (bool) – If the reference accelerator should be created.

Return type:

list[Accelerator]

create_nominal()[source]

Create the nominal linac.

Return type:

Accelerator

create_failed(n_objects)[source]

Create failed linac(s).

Parameters:

n_objects (int)

Return type:

list[Accelerator]

_check_consistency_reference_phase_policies(cavities)[source]

Check that solvers phases are consistent with DAT file.

Parameters:

cavities (Sequence[FieldMap])

Return type:

None

_create_output_dirs(n_objects, with_reference=True)[source]

Create the proper out directories for every Accelerator.

The default structure looks like:

YYYY.MM.DD_HHhMM_SSs_MILLIms/
├── 000000_ref
│   ├── 0_Envelope1D/
│   └── 1_TraceWin/
├── 000001
│   ├── 0_Envelope1D/
│   └── 1_TraceWin/
├── 000002
│   ├── 0_Envelope1D/
│   └── 1_TraceWin/
├── 000003
│   ├── 0_Envelope1D/
│   └── 1_TraceWin/
└── lightwin.log
  • The main YYYY.MM.DD_HHhMM_SSs_MILLIms/ directory is created at the same location as the original DAT file. You can override its name with the project_folder key in the [files] TOML section.

  • In every accelerator_path (eg 000002/), you will find one directory per BeamCalculator. In this example, compensation settings were found with Envelope1D and a second simulation was made with TraceWin.

Parameters:
  • n_objects (int) – Number of Accelerator to create.

  • with_reference (bool, default: True) – If first directory should be the nominal dir called 000000_ref/ .

Return type:

list[Path]

Returns:

Output path for every accelerator: 000000_ref/ (if with_reference), 000001/, …

class NoFault(*args, **kwargs)[source]

Bases: AcceleratorFactory

Create single accelerator without failure.

Deprecated since version 0.15.0: Prefer AcceleratorFactory.

__init__(*args, **kwargs)[source]

Facilitate creation of Accelerator objects.

Parameters:
  • beam_calculators – Objects that will compute propagation of the beam.

  • files – Configuration entries for the input/output paths.

  • beam – Configuration dictionary holding the initial beam parameters.

  • kwargs – Other configuration dictionaries.

Return type:

None

run(*args, **kwargs)[source]
Return type:

Accelerator

class WithFaults(*args, wtf, **kwargs)[source]

Bases: AcceleratorFactory

Create accelerators with failures.

Deprecated since version 0.15.0: Prefer AcceleratorFactory.

Parameters:

wtf (dict[str, Any])

__init__(*args, wtf, **kwargs)[source]

Facilitate creation of Accelerator objects.

Parameters:
  • beam_calculators – Objects that will compute propagation of the beam.

  • files – Configuration entries for the input/output paths.

  • beam – Configuration dictionary holding the initial beam parameters.

  • kwargs – Other configuration dictionaries.

  • wtf (dict[str, Any])

Return type:

None

run_all(*args, **kwargs)[source]
Return type:

list[Accelerator]