accinv.model module

Module containing accelerator models and corresponding utilities.

Orbit Response Matrix (ORM)

The layout of the ORM is based on the following convention:

  • BPMs appear along the rows (axis=0). First all horizontal BPMs, followed by all vertical BPMs.

  • Steerers appear along the columns (axis=1). First all horizontal steerers, followed by all vertical steerers.

+---HSTEERERS---+---VSTEERERS---+
|               |               |
H               |               |
B               |               |
P               |               |
M               |               |
S               |               |
|               |               |
+---------------+---------------+
|               |               |
V               |               |
B               |               |
P               |               |
M               |               |
S               |               |
|               |               |
+---------------+---------------+
class accinv.model.ArrayElementParameter(name: str, attribute: str = '', *, index: int)

Bases: Parameter[<MagicMock name=’mock.ndarray’ id=’140400410054320’>]

Model parameter representing an array element located at a specific index.

id: ParameterIdentifier
type: ParameterType[D]
class accinv.model.Madx(*, path: Union[Path, str], stdout: Union[int, TextIO, bool] = False)

Bases: OpticsModel

This model uses cpymad as a backend.

compute_orbit(*, hbpms: Collection[str], vbpms: Collection[str], configuration: Optional[Collection[ParameterUpdate]] = None) tuple[<MagicMock name='mock.ndarray' id='140400410054320'>, <MagicMock name='mock.ndarray' id='140400410054320'>]

Compute the orbit at the given horizontal and vertical BPMs.

Parameters
  • hbpms – The names of horizontal BPMs.

  • vbpms – The names of vertical BPMs.

  • configuration – (optional) Temporary parameter updates for the duration of the orbit computation (see Model.temporary_update()).

Returns

The tuple (x_orbit, y_orbit), where x_orbit is the x-orbit at horizontal BPMs and y_orbit is the y-orbit at vertical BPMs.

Raises

UnknownElementError – If any of the specified BPM names is not found in the model.

compute_twiss(configuration: Optional[Collection[ParameterUpdate]] = None) TwissTable

Compute Twiss data.

Parameters

configuration – See Model.temporary_update(). The updates are non-persistent.

Returns

Twiss data as a dictionary.

get_element_names(*containers: Container[str]) tuple[list[str], ...]
For each given container, return a list of element names from the model

that are part of that container.

Parameters

containers – One or multiple objects that support in; element names of the model will be checked against these containers.

Returns

A tuple, one item for each given container, where each item contains the names of all elements for which the corresponding container indicated that it contains that name.

get_parameter(parameter: Parameter[D]) D

Get the current data of the given parameter.

set_parameter(parameter: Parameter[D], new_data: D) None

Set the data of the given parameter to the specified new_data.

class accinv.model.Model

Bases: object

build_configuration_from_parameter_values(*, quadrupoles: Optional[dict[str, float]] = None, quadrupoles_delta_k1l: Optional[dict[str, float]] = None, steerers: Optional[dict[str, float]] = None) list[accinv.model.ParameterUpdate]

Generate a new configuration from the given type-specific parameter values.

Parameters
  • quadrupoles – Replaces the k1 attribute of specified quadrupoles with the specified values.

  • quadrupoles_delta_k1l – Increments the k1 attribute of specified quadrupoles by the specified values (converting K1L to K1).

  • steerers – Replaces the kick attribute of specified steerers with the specified values.

Returns

Configuration object containing the specified parameter updates.

compute_orbit(*, hbpms: Collection[str], vbpms: Collection[str], configuration: Optional[Collection[ParameterUpdate]] = None) tuple[<MagicMock name='mock.ndarray' id='140400410054320'>, <MagicMock name='mock.ndarray' id='140400410054320'>]

Compute the orbit at the given horizontal and vertical BPMs.

Parameters
  • hbpms – The names of horizontal BPMs.

  • vbpms – The names of vertical BPMs.

  • configuration – (optional) Temporary parameter updates for the duration of the orbit computation (see Model.temporary_update()).

Returns

The tuple (x_orbit, y_orbit), where x_orbit is the x-orbit at horizontal BPMs and y_orbit is the y-orbit at vertical BPMs.

Raises

UnknownElementError – If any of the specified BPM names is not found in the model.

compute_orm(*, hbpms: Collection[str], hsteerers: Collection[str], vbpms: Collection[str], vsteerers: Collection[str], kicks: Collection[float], configuration: Optional[Collection[ParameterUpdate]] = None) <MagicMock name='mock.NDArray.__getitem__()' id='140400408980448'>

Compute the ORM for the given [hv]steerers and kicks, observed at the given [hv]bpms.

Parameters
  • hbpms – Collection of horizontal BPM names.

  • hsteerers – Collection of horizontal steerer names.

  • vbpms – Collection of vertical BPM names.

  • vsteerers – Collection of vertical steerer names.

  • kicks – Steerer kick values for which orbits are computed.

  • configuration – See Model.temporary_update(). The updates are non-persistent.

Returns

The computed ORM. The left upper block corresponds to horizontal and the right lower block to vertical dimension.

get_element_names(*containers: Container[str]) tuple[list[str], ...]
For each given container, return a list of element names from the model

that are part of that container.

Parameters

containers – One or multiple objects that support in; element names of the model will be checked against these containers.

Returns

A tuple, one item for each given container, where each item contains the names of all elements for which the corresponding container indicated that it contains that name.

get_parameter(parameter: Parameter[D]) D

Get the current data of the given parameter.

get_parameter_value(parameter: Parameter) float

Get the current value of the given parameter.

set_parameter(parameter: Parameter[D], new_data: D) None

Set the data of the given parameter to the specified new_data.

set_parameter_value(parameter: Parameter, new_value: float) None

Set the current value of the given parameter to the specified new_value.

temporary_update(configuration: Optional[Collection[ParameterUpdate]] = None, *, quadrupoles: Optional[dict[str, float]] = None, quadrupoles_delta_k1l: Optional[dict[str, float]] = None, steerers: Optional[dict[str, float]] = None) Iterator[None]

Temporarily update the model’s parameters.

On entrance, the parameters will be set to the specified values. On exit, the parameters will be reset to their original values.

:param See Model.update().:

Returns

A context manager handling the parameter updates.

update(configuration: Optional[Collection[ParameterUpdate]] = None, *, quadrupoles: Optional[dict[str, float]] = None, quadrupoles_delta_k1l: Optional[dict[str, float]] = None, steerers: Optional[dict[str, float]] = None) None

Update the model’s parameters.

Note

If both quadrupoles and quadrupoles_delta_k1l are given, the latter takes into account the already updated values from quadrupoles.

Parameters
  • configuration – Parameter updates. Overrides other specifications.

  • quadrupoles – Keys must be names of quadrupoles and values their desired k1 values.

  • quadrupoles_delta_k1l – These values will be added to the quadrupoles’ current K1L settings (i.e. their integrated strength). Keys must be the quadrupoles’ names.

  • steerers – Keys must be names of steerers and values their desired kick values.

class accinv.model.NumberParameter(name: str, attribute: str = '')

Bases: Parameter[float]

Model parameter representing a single floating point number.

id: ParameterIdentifier
type: ParameterType[D]
class accinv.model.OpticsModel

Bases: Model

compute_beta_beating(quadrupoles_delta_k1l: dict[str, float]) tuple[<MagicMock name='mock.ndarray' id='140400410054320'>, <MagicMock name='mock.ndarray' id='140400410054320'>]

Compute the beta beating for the given quadrupole errors with respect to the current setting.

Parameters

quadrupoles_delta_k1l – See Model.temporary_update(). The updates are non-persistent.

Returns

The tuple (beta_beating_x, beta_beating_y) containing the simulated beta beating for, respectively, mode 1 and mode 2.

compute_tunes(configuration: Optional[Collection[ParameterUpdate]] = None) tuple[float, float]

Compute the tunes for the two decoupled modes.

Parameters

configuration – See Model.temporary_update(). The updates are non-persistent.

Returns

The tuple (Q1, Q2) containing the tunes for, respectively, mode 1 and mode 2.

compute_twiss(configuration: Optional[Collection[ParameterUpdate]] = None) TwissTable

Compute Twiss data.

Parameters

configuration – See Model.temporary_update(). The updates are non-persistent.

Returns

Twiss data as a dictionary.

class accinv.model.ParameterUpdate(parameter: Parameter[D], update_strategy: UpdateStrategy)

Bases: Generic[D]

This class represents the foreseen update of a model parameter’s value.

Parameters
  • parameter – The model parameter to be updated.

  • update_strategy – The update strategy to be used.

apply(old: D) D

Apply the parameter update, producing an updated data structure.

Parameters

old – The old data structure.

Returns

The updated data structure (possibly the same object as old, if mutable).

parameter: Parameter[D]
transform: UpdateStrategy
class accinv.model.TwissTable

Bases: TypedDict

This class represents selected columns from Twiss data computation.

alfx: <MagicMock name='mock.ndarray' id='140400410054320'>
alfy: <MagicMock name='mock.ndarray' id='140400410054320'>
betx: <MagicMock name='mock.ndarray' id='140400410054320'>
bety: <MagicMock name='mock.ndarray' id='140400410054320'>
mux: <MagicMock name='mock.ndarray' id='140400410054320'>
muy: <MagicMock name='mock.ndarray' id='140400410054320'>
name: <MagicMock name='mock.ndarray' id='140400410054320'>
x: <MagicMock name='mock.ndarray' id='140400410054320'>
y: <MagicMock name='mock.ndarray' id='140400410054320'>
exception accinv.model.UnknownElementError(msg: str, *, name: str)

Bases: Exception

name: str
accinv.model.add(new: float) UpdateStrategy

Create an update strategy which adds the given new value to the old values.

accinv.model.replace_with(new: float) UpdateStrategy

Create an update strategy which replaces old values with the given new one.