Environment¶
- xtrack_tools.env.create_xsuite_environment(sequence_file=None, kinetic_energy=6800, seq_name=None, rerun_madx=False, json_file=None)[source]¶
Create or load an xsuite environment for a given MAD-X sequence.
The environment is generated from a MAD-X sequence file and cached to JSON. If the cached JSON exists and is newer than the sequence file, it will be used unless
rerun_madxis set toTrue.- Parameters:
sequence_file (Path | None) – Path to a MAD-X sequence file.
kinetic_energy (float) – Beam kinetic energy in GeV used to set the particle reference.
seq_name (str | None) – Sequence name inside the environment; defaults to the file stem.
rerun_madx (bool) – Force regeneration of the JSON cache by rerunning MAD-X.
json_file (Path | None) – Optional path for the cached JSON representation.
- Returns:
The loaded
xt.Environmentwith particle reference set.- Raises:
ValueError – If
sequence_fileis not provided.FileNotFoundError – If the sequence file is missing when regeneration is needed.
- Return type:
xt.Environment
- xtrack_tools.env.initialise_env(matched_tunes, magnet_strengths, corrector_table, sequence_file=None, kinetic_energy=6800, seq_name=None, json_file=None, strict_set=True)[source]¶
Initialise an xsuite environment with tune knobs, magnet strengths, and correctors.
- Parameters:
matched_tunes (dict[str, float]) – Mapping of tune knob names to values (e.g.,
dqx_b1_op).magnet_strengths (dict[str, float]) – Mapping of element variable names to strengths, such as
mqy.b5l2.b1.k1.corrector_table (tfs.TfsDataFrame) – TFS table with corrector settings.
sequence_file (Path | None) – Path to the MAD-X sequence file.
kinetic_energy (float) – Beam kinetic energy in GeV.
seq_name (str | None) – Sequence name inside the environment.
json_file (Path | None) – Optional path for cached JSON environment.
strict_set – If
True, validate existing corrector strengths before applying.
- Returns:
The configured
xt.Environmentready for tracking or optics analysis.- Raises:
ValueError – If tune knob names do not match the expected format.
- Return type:
xt.Environment