Model

Manager

This module provides high-level functions to manage most functionality of model. It contains entrypoint wrappers to get accelerator classes or their instances.

omc3.model.manager.get_accelerator(opt, other_opt) Accelerator[source]
Returns (opt.accel, help_requested):

opt.accel is the Accelerator instance of the desired accelerator, as given at the commandline.

omc3.model.manager.get_accelerator_class(opt, other_opt) type[Accelerator][source]

Returns only the accelerator-class (non-instanciated). Only opt.accel is needed.

omc3.model.manager.get_parsed_opt(opt, other_opt) dict[source]

Get all accelerator related options as a dict.

Constants

This module provides high-level functions to manage most functionality of model. Specific constants to be used in model, to help with consistency.

class omc3.model.constants.Fetcher(*values)[source]

Accelerator

This module provides high-level classes to define most functionality of model.accelerators. It contains entrypoint the parent Accelerator class as well as other support classes.

class omc3.model.accelerators.accelerator.AccElementTypes[source]

Defines the strings for the element types BPMS, MAGNETS and ARC_BPMS.

class omc3.model.accelerators.accelerator.Accelerator(opt)[source]

Abstract class to serve as an interface to implement the rest of the accelerators.

classmethod get_correctors_variables(frm=None, to=None, classes=None)[source]

Returns the set of corrector variables between frm and to, with classes in classes. None means select all.

classmethod get_dir() Path[source]

Default directory for accelerator. Should be overwritten if more specific.

classmethod get_element_types_mask(list_of_elements: list[str], types) ndarray[source]

Returns a boolean mask for elements in list_of_elements that belong to any of the specified types. Needs to handle: bpm, magnet, arc_bpm (see AccElementTypes)

Parameters:
  • list_of_elements -- list of elements.

  • types -- the kinds of elements to look for.

Returns:

A boolean array of elements of specified kinds.

get_exciter_bpm(plane: str, commonbpms: list[str])[source]

Returns the BPM next to the exciter. The Accelerator instance knows already which excitation method is used.

Parameters:
  • plane -- X or Y.

  • commonbpms -- list of common BPMs (e.g. intersection of input BPMs.

Returns:

tuple(int, str), str)`

Return type:

`((index, bpm_name), exciter_name)

classmethod get_file(filename: str) Path[source]

Default location for accelerator files. Should be overwritten if more specific.

classmethod get_variables(frm=None, to=None, classes=None)[source]

Gets the variables with elements in the given range and the given classes. None means everything.

verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

exception omc3.model.accelerators.accelerator.AcceleratorDefinitionError[source]

Raised when an Accelerator instance is wrongly used, for example by calling a method that should have been overwritten.

ESRF

Accelerator-Class for the ESRF machine.

Model Creation Keyword Args:

--Optional--

  • dpp (float):

    Deltap/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.esrf.Esrf(*args, **kwargs)[source]
class omc3.model.accelerators.generic.Generic(*args, **kwargs)[source]

LHC

Accelerator-Class for the LHC collider.

Model Creation Keyword Args:

--Required--

  • beam (int):

    Beam to use.

    choices: (1, 2)

  • year (str):

    Year of the optics (or hllhc1.3).

    choices: ('2012', '2015', '2016', '2017', '2018', '2022', 'hllhc1.3')

--Optional--

  • ats:

    Marks ATS optics

    action: store_true

  • dpp (float):

    Delta p/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.lhc.Lhc(*args, **kwargs)[source]

Accelerator class for the Large Hadron Collider.

get_exciter_bpm(plane: str, commonbpms: list[str]) tuple[str, str][source]

Returns the name of the BPM closest to the exciter (i.e. ADT or AC-Dipole) as well as the name of the exciter element.

get_ips() Iterator[tuple[str]][source]

Returns an iterable with this accelerator’s IPs.

Returns:

(ip name, left BPM name, right BPM name)

Return type:

An iterator returning tuples with

get_variables(frm: float = None, to: float = None, classes: Iterable[str] = None)[source]

Gets the variables with elements in the given range and the given classes. None means everything.

sort_variables_by_location(variables: Iterable[str], frm: float | None = None, to: str | None = None) list[str][source]

Sorts the variables by location and filters them between frm and to. If frm is larger than to it loops back around to the start the accelerator. This is a useful function for the LHC that’s why it is “public” but it is not part of the Accelerator-Class Interface.

Parameters:
  • variables (Iterable) -- Names of variables to sort

  • frm (float) -- S-position to filter from

  • to (float) -- S-position to filter to

verify_object() None[source]

Verifies if everything is defined which should be defined. Will Raise an AcceleratorDefinitionError if one of the checks is invalid.

PS

Accelerator-Class for the PS machine.

Model Creation Keyword Args:

--Optional--

  • dpp (float):

    Deltap/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.ps.Ps(*args, **kwargs)[source]

Parent Class for PS-types.

get_exciter_bpm(plane, bpms)[source]

Returns the BPM next to the exciter. The Accelerator instance knows already which excitation method is used.

Parameters:
  • plane -- X or Y.

  • commonbpms -- list of common BPMs (e.g. intersection of input BPMs.

Returns:

tuple(int, str), str)`

Return type:

`((index, bpm_name), exciter_name)

get_file(filename: str) Path[source]

Get filepaths for PS files.

verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

PS Booster

Accelerator-Class for the PSB machine.

Model Creation Keyword Args:

--Optional--

  • dpp (float):

    Deltap/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • ring (int):

    Ring to use.

    choices: (1, 2, 3, 4)

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.psbooster.Psbooster(*args, **kwargs)[source]

Parent Class for Psbooster-types.

get_exciter_bpm(plane, bpms)[source]

Returns the BPM next to the exciter. The Accelerator instance knows already which excitation method is used.

Parameters:
  • plane -- X or Y.

  • commonbpms -- list of common BPMs (e.g. intersection of input BPMs.

Returns:

tuple(int, str), str)`

Return type:

`((index, bpm_name), exciter_name)

verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

SuperKEKB

Accelerator-Class for the SuperKEKB machine.

Model Creation Keyword Args:

--Required--

  • ring (str):

    HER or LER ring.

    choices: ('ler', 'her')

--Optional--

  • dpp (float):

    Deltap/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.skekb.SKekB(*args, **kwargs)[source]

KEK’s SuperKEKB accelerator.

verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

Iota

Accelerator-Class for the Iota machine.

Model Creation Keyword Args:

--Optional--

  • dpp (float):

    Deltap/p to use.

    default: 0.0

  • driven_excitation (str):

    Denotes driven excitation by AC-dipole (acd) or by ADT (adt)

    choices: ('acd', 'adt')

  • drv_tunes (float):

    Driven tunes without integer part.

  • energy (float):

    Energy in Tev.

  • model_dir (str):

    Path to model directory; loads tunes and excitation from model!

  • modifiers (str):

    Path to the optics file to use (modifiers file).

  • nat_tunes (float):

    Natural tunes without integer part.

  • particle (str):

    Particle type.

    choices: ('p', 'e')

  • xing:

    If True, x-ing angles will be applied to model

    action: store_true

class omc3.model.accelerators.iota.Iota(*args, **kwargs)[source]
classmethod verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

PETRA

Accelerator-Class for the PETRA machine. Model creation not implemented yet.

class omc3.model.accelerators.petra.Petra(opt)[source]
get_exciter_bpm(plane, commonbpms)[source]

Returns the BPM next to the exciter. The Accelerator instance knows already which excitation method is used.

Parameters:
  • plane -- X or Y.

  • commonbpms -- list of common BPMs (e.g. intersection of input BPMs.

Returns:

tuple(int, str), str)`

Return type:

`((index, bpm_name), exciter_name)

verify_object()[source]

Verifies that this instance of an Accelerator is properly instantiated.

LHC Model Creator

This module provides convenience functions for model creation of the LHC.

class omc3.model.model_creators.lhc_model_creator.LhcBestKnowledgeCreator(accel: Lhc, *args, **kwargs)[source]
get_base_madx_script() str[source]

Returns the base LHC madx script.

get_madx_script() str[source]

Get madx script to create a LHC model.

prepare_options(opt) bool[source]

Use the fetcher to list choices if requested.

prepare_run()[source]

Prepares the model creation MAD-X run. It should check that the appropriate directories are created, and that macros and other files are in place. Should also check that all necessary data for model creation is available in the accelerator instance.

Here implemented are some usual defaults, so that an implementation of the model-creator might run these easily with super() if desired.

Parameters:

accel (Accelerator) -- Accelerator Instance used for the model creation.

class omc3.model.model_creators.lhc_model_creator.LhcCorrectionModelCreator(accel: Lhc, twiss_out: Path | str, corr_files: Sequence[Path | str], update_dpp: bool = False)[source]

Creates an updated model from multiple changeparameters inputs (used in iterative correction).

property files_to_check: list[str]

Returns the list of files to check after model creation, should only be used in post_run. Override in subclass if you need to check a different set of files.

get_madx_script() str[source]

Get the madx script for the correction model creator, which updates the model after correcion.

prepare_run() None[source]

Prepares the model creation MAD-X run. It should check that the appropriate directories are created, and that macros and other files are in place. Should also check that all necessary data for model creation is available in the accelerator instance.

Here implemented are some usual defaults, so that an implementation of the model-creator might run these easily with super() if desired.

Parameters:

accel (Accelerator) -- Accelerator Instance used for the model creation.

class omc3.model.model_creators.lhc_model_creator.LhcModelCreator(accel: Lhc, *args, **kwargs)[source]
get_base_madx_script() str[source]

Returns the base LHC madx script.

get_madx_script() str[source]

Get madx script to create a LHC model.

get_update_deltap_script(deltap: float | str) str[source]

Update the dpp in the LHC.

Parameters:

deltap (float | str) -- The dpp to update the LHC to.

prepare_options(opt)[source]

Use the fetcher to list choices if requested.

prepare_run() None[source]

Prepares the model creation MAD-X run. It should check that the appropriate directories are created, and that macros and other files are in place. Should also check that all necessary data for model creation is available in the accelerator instance.

Here implemented are some usual defaults, so that an implementation of the model-creator might run these easily with super() if desired.

Parameters:

accel (Accelerator) -- Accelerator Instance used for the model creation.

class omc3.model.model_creators.lhc_model_creator.LhcSegmentCreator(accel: Accelerator, segment: Segment, measurables: Iterable[Propagable], corrections: MADXInputType = None, *args, **kwargs)[source]
property files_to_check: list[str]

Returns the list of files to check after model creation, should only be used in post_run. Override in subclass if you need to check a different set of files.

get_madx_script()[source]

Returns the MAD-X script used to create the model (directory).

Returns:

The string of the MAD-X script used to used to create the model (directory).

PS Model Creator

This module provides convenience functions for model creation of the PS.

class omc3.model.model_creators.ps_model_creator.PsModelCreator(accel: Accelerator, logfile: Path = None, acc_models_path: Path = None)[source]
get_base_madx_script()[source]

Returns the MAD-X script used to set-up the basic accelerator in MAD-X, without actually creating the twiss-output, as some modifications to the accelerator may come afterwards (depending on which model-creator is calling this).

Returns:

The string of the MAD-X script used to used to set-up the machine.

get_madx_script() str[source]

Returns the MAD-X script used to create the model (directory).

Returns:

The string of the MAD-X script used to used to create the model (directory).

prepare_run() None[source]

Prepares the model creation MAD-X run. It should check that the appropriate directories are created, and that macros and other files are in place. Should also check that all necessary data for model creation is available in the accelerator instance.

Here implemented are some usual defaults, so that an implementation of the model-creator might run these easily with super() if desired.

Parameters:

accel (Accelerator) -- Accelerator Instance used for the model creation.

PS Booster Model Creator

This module provides convenience functions for model creation of the PSB.

class omc3.model.model_creators.psbooster_model_creator.PsboosterModelCreator(accel: Accelerator, logfile: Path = None, acc_models_path: Path = None)[source]
get_base_madx_script()[source]

Returns the MAD-X script used to set-up the basic accelerator in MAD-X, without actually creating the twiss-output, as some modifications to the accelerator may come afterwards (depending on which model-creator is calling this).

Returns:

The string of the MAD-X script used to used to set-up the machine.

get_madx_script() str[source]

Returns the MAD-X script used to create the model (directory).

Returns:

The string of the MAD-X script used to used to create the model (directory).

prepare_run()[source]

Prepares the model creation MAD-X run. It should check that the appropriate directories are created, and that macros and other files are in place. Should also check that all necessary data for model creation is available in the accelerator instance.

Here implemented are some usual defaults, so that an implementation of the model-creator might run these easily with super() if desired.

Parameters:

accel (Accelerator) -- Accelerator Instance used for the model creation.