at.load.xsuite#
Using Xsuite .json files with PyAT.#
PyAT can read and write lattice descriptions in Xsuite .json files. If both PyAT and Xsuite are installed, in-memory direct conversion is also possible in both directions.
However, because of intrinsic differences between PyAT and Xsuite, some incompatibilities must be taken into account.
1. Differences between PyAT and Xsuite#
Magnet models#
Xsuite separates the definition of the magnet modelling method (model) and the
definition of the integrator (integrator). It offers a large choice for both.
PyAT combines both in the PassMethod associated with the element. The conversion in
both directions is described below.
Magnet transformations#
PyAT uses a coherent definition of rotations: the positive sign corresponds to a
cork-screw rotation, or in other words an anti-clockwise rotation when facing the axis.
Xsuite has a special definition for the x-axis rotation, opposite to the standard. As a
consequence, the signs of the pitch in AT and rot-x-rad in Xsuite are
opposite. The conversion takes care of that.
Rectangular bending magnets#
A Xsuite RBend magnet corresponds to a standard Dipole if its
rbend_model is set to curved-body. When converted to AT, its PassMethod
will then be set to BndMPoleSymplectic4Pass or ExactSectorBendPass depending
on its model.
It corresponds to a real rectangular magnet if its rbend_model is set to
straight-body. When converted to AT, its PassMethod will then be set to
ExactRectangularBendPass, the only one for rectangular bends.
2. Reading Xsuite files#
PyAT can read both Environment and Line file descriptions.
For Environment files, a use keyword selects the desired
Line.
Xsuite elements converted to PyAT have an additional origin string attribute giving
the class of the original Xsuite element. Xsuite element without equivalent in PyAT are
converted to Marker or Drift depending on their length.
Model and integrator#
Xsuite models equivalent to PyAT “exact” methods are converted to the equivalent
PassMethod:
Xsuite element |
Xsuite model |
AT PassMethod |
|---|---|---|
Drift |
“exact” |
“ExactDriftPass” |
Straight magnets |
“drift-kick-drift-exact” |
“ExactMultipolePass” |
Bend, Rbend in “curved-body” |
“bend-kick-bend” |
“ExactSectorBendPass” |
Rbend in “straight-body” |
“drift-kick-drift-exact” |
“ExactRectangularBendPass” |
All other models are converted to the default element PassMethod.
Longitudinal motion#
The generated AT lattice has longitudinal motion turned off: RF cavities are inactive and synchrotron radiation is turned off.
3. Writing Xsuite files#
Rectangular bending magnets#
An AT Dipole will be converted to a RBend with rbend_model
set to straight-body if its PassMethod is ExactRectangularBendPass. In all
other cases, it will be converted to a Bend.
Model and integrator#
PyAT exact passmethods are converted to the equivalent Xsuite model. Other methods
are converting according to a match_model keyword:
match_modelis False (the default):model,integrator,num_multipole_kicksare set to their default value. This way, the default behaviour in AT is turned into the default behaviour in Xsuite,match_modelis True: a model matching at best the AT model is selected, the integrator is set toyoshida4andnum_multipole_kicksis set equal toNumIntSteps.
This is summarised in this table:
AT element |
AT PassMethod |
Xsuite model, match_model= |
|
|---|---|---|---|
False |
True |
||
Drift |
ExactDriftPass |
“exact” |
|
default |
“adaptive” |
“expanded” |
|
Straight magnet |
ExactMultipolePass |
“drift-kick-drift-exact” |
|
default |
“adaptive” |
“drift-kick-drift-expanded” |
|
Dipole |
ExactSectorBendPass |
“bend-kick-bend” |
|
ExactRectangularBendPass |
“drift-kick-drift-exact” |
||
default |
“adaptive” |
“rot-kick-rot” |
|
Longitudinal motion#
Whatever the 6D status of the AT lattice, the Xsuite lattice will have synchrotron radiation turned off and active RF cavities.
Ignored attributes#
The following AT attributes are ignored in writing Xsuite .json files:
RAperturesEAperturesX0ref. This parameter defines the distance between the magnetic axis of a rectangular bend and the reference trajectory. It only matters for rectangular bends with focusing or higher order multipoles. Xsuite has a similar attributerbend_shiftbut there is no analytical conversion possible between both.RefDZ. This defines the correction of path lengthening for rectangular bends.
Functions
|
Create a |
|
Create a Xsuite |
|
Create a |
|
Save a |
Classes
|
Base class for Xsuite elements. |
|
Line object simulation a Xsuite Line. |
- class XsElement(name, *args, **kwargs)[source]#
Bases:
dictBase class for Xsuite elements.
- classmethod from_at(match_model=False, **atparams)[source]#
Build a XsElement element from an AT element.
- classmethod from_dict(xsparams, name='?', warn=<function XsElement.<lambda>>)[source]#
Build a XsElement from its dictionary representation.
- static static_from_dict(elem_dict, name='?', warn=<function XsElement.<lambda>>)[source]#
Build a XsElement from its dictionary representation.
- class XsLine(elements, **root)[source]#
Bases:
objectLine object simulation a Xsuite Line.
- lattice(**kwargs)#
Create an AT lattice from the XsLine.
- Keyword Arguments:
name (str) – Name of the lattice. Default: Xsuite line name.
particle (Particle) – Circulating particle. Default: Xsuite reference particle
energy (float) – Energy of the lattice [eV]. Default: from Xsuite reference particle
periodicity (int) – Number of periods. Default: 1
* – All other keywords will be set as Lattice attributes
- Returns:
lattice – New
Lattice.
- to_at(**kwargs)[source]#
Create an AT lattice from the XsLine.
- Keyword Arguments:
name (str) – Name of the lattice. Default: Xsuite line name.
particle (Particle) – Circulating particle. Default: Xsuite reference particle
energy (float) – Energy of the lattice [eV]. Default: from Xsuite reference particle
periodicity (int) – Number of periods. Default: 1
* – All other keywords will be set as Lattice attributes
- Returns:
lattice – New
Lattice.
- to_dict()[source]#
Create a Xsuite-compatible dictionary representation of the XsLine.
- Returns:
dict[str, Any] – Dictionary representation of the XsLine.
- to_json(filename=None, compact=False)[source]#
Save the XsLine into a JSON file.
- Parameters:
filename (str | Path | None) – Name of the JSON file. Default: outputs on
sys.stdoutcompact (bool) – If
False(default), the JSON file is pretty-printed with line feeds and indentation. Otherwise, the output is a single line.
- lattice_from_line(line, use=None, **kwargs)[source]#
Create a
Latticeobject from a XsuiteLineorEnvironment.- Parameters:
line (Line) – Xsuite line or environment
use (str) – Name of the line containing the desired lattice. Default:
ring.
- Keyword Arguments:
name (str) – Name of the lattice. Default: Xsuite line name.
particle (Particle) – Circulating particle. Default: Xsuite reference particle
energy (float) – Energy of the lattice [eV]. Default: from Xsuite reference particle
periodicity (int) – Number of periods. Default: 1
* – All other keywords will be set as Lattice attributes
- Returns:
lattice – New
Latticeobject.
- load_xsuite(filename, use=None, **kwargs)[source]#
Create a
Latticefrom a Xsuite JSON file.- Parameters:
- Keyword Arguments:
name (str) – Name of the lattice. Default: Xsuite line name.
particle (Particle) – Circulating particle. Default: Xsuite reference particle
energy (float) – Energy of the lattice [eV]. Default: from Xsuite reference particle
periodicity (int) – Number of periods. Default: 1
* – All other keywords will be set as Lattice attributes
- Returns:
lattice (Lattice) – New
Latticeobject
See also
load_json(), which reads both AT and Xsuite .json files,load_lattice()for a generic lattice-loading function,Lattice.load()for a generic lattice factory method.
- save_xsuite(lattice, filename=None, match_model=False, compact=False)[source]#
Save a
Latticeas a Xsuite JSON file.- Parameters:
lattice (Lattice) – Lattice description
filename (str | Path | None) – Name of the JSON file. Default: outputs on
sys.stdoutmatch_model (bool) – If
True, set the Xsuite model matching at best the AT PassMethod. By default, the Xsuite default model will be used.compact (bool) – If
False(default), the JSON file is pretty-printed with line feeds and indentation. Otherwise, the output is a single line.