Simulation

class liso.simulation.Linac(mps: Optional[int] = None)

Bases: collections.abc.Mapping

A linear accelerator complex for simulation.

The linac class is the abstraction of a linear accelerator. It consists of one or multiple beamlines. These beamlines can be simulated using different codes.

__init__(mps: Optional[int] = None)

Initialization.

Parameters

mps – Number of macro-particles at the start of the simulation.

add_beamline(code: str, *args, **kwargs) None

Add a beamline.

The args and kwargs will be passed to the constructor of the corresponding liso.simulation.beamline.Beamline type.

Parameters

code – Simulation code name (case insensitive) used to simulate the beamline: ‘astra’ or ‘a’ for ASTRA; ‘impactt’ or ‘t’ for IMPACT-T; ‘elegant’ or ‘e’ for ELEGANT.

run(params: dict, *, n_workers: int = 1, timeout: Optional[int] = None) None

Run simulation for all the beamlines.

Parameters
  • params – A dictionary of parameters used in the simulation input file.

  • n_workers – Number of processes used in simulation.

  • timeout – Maximum allowed duration in seconds of thesimulation.

class liso.simulation.beamline.Beamline(name: str, *, template: Optional[str] = None, swd: Optional[str] = None, fin: Optional[str] = None, pin: Optional[str] = None, pout: Optional[str] = None, charge: Optional[float] = None, z0: Optional[float] = None)

Bases: abc.ABC

Beamline abstraction class.

__init__(name: str, *, template: Optional[str] = None, swd: Optional[str] = None, fin: Optional[str] = None, pin: Optional[str] = None, pout: Optional[str] = None, charge: Optional[float] = None, z0: Optional[float] = None) None

Initialization.

Parameters
  • name – Name of the beamline.

  • template – Path of the template of the input file.

  • swd – Path of the simulation working directory. This where the Python subprocess runs.

  • fin – Input file name.

  • pin – Initial particle file name.

  • pout – Final particle file name. It must be located in the same directory as the input file.

  • charge – Bunch charge at the beginning of the beamline. Only used for certain simulation codes (e.g. ImpactT).

  • z0 – Starting z coordinate in meter. Used for concatenated simulation. Default = None, inherit z coordinate from the upstream beamline. However, for instance, when the second beamline is defined from z0 = 0.0, z0 is required to generate a correct initial particle distribution.