accinv.parameters module

This module contains functionality and utilities for dealing with fitting parameters.

class accinv.parameters.AnalyticalParameterGroup(n: int)

Bases: ParameterGroup

Parameter group which uses analytical formulas for its Jacobian.

These parameters are typically not contained in the model as numerical quantities. Rather, their effect is added during a post-computational step.

build_jacobian(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Build the part of the Jacobian that corresponds to this parameter group.

Parameters

orm – The ORM corresponding to the returned Jacobian.

Returns

The Jacobian. It does not contain the contribution from evaluating the parameters of this group. This contribution can be added via AnalyticalParameterGroup.update_jacobian().

update_jacobian(jacobian: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, x: <MagicMock name='mock.ndarray' id='139857761889296'>, *, column_offset: int) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Update the given jacobian with the given parameter estimates x.

Note

This modifies the given jacobian in-place.

Parameters
  • jacobian – The full Jacobian containing the parts of all parameter groups (including this one) but without the contribution from evaluating the parameters of this group.

  • x – The current estimate of parameter values for this group.

  • column_offset – The offset in number of columns where this parameter group is located within the Jacobian.

Returns

The Jacobian with the contribution from evaluating the parameters of this group added.

update_orm(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, x: <MagicMock name='mock.ndarray' id='139857761889296'>) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Update the given orm with the given parameter estimates x.

Note

This modifies the given orm in-place.

Parameters
  • orm – The ORM without the contribution from evaluating the parameters of this group.

  • x – The current estimate of parameter values for this group.

Returns

The ORM with the contribution from evaluating the parameters of this group added.

class accinv.parameters.GainErrors(n: int, orm_index_builder: OrmIndexBuilder, orm_shape: tuple[int, int])

Bases: AnalyticalParameterGroup

Parameter group representing BPM and steerer gain errors.

Parameters
  • n – See ParameterGroup.

  • orm_index_builder – See OrmIndexBuilder.

  • orm_shape – The shape of the ORM.

build_jacobian(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Build the part of the Jacobian that corresponds to this parameter group.

Parameters

orm – The ORM corresponding to the returned Jacobian.

Returns

The Jacobian. It does not contain the contribution from evaluating the parameters of this group. This contribution can be added via AnalyticalParameterGroup.update_jacobian().

property count: int

The number of parameter values represented by this group.

update_jacobian(jacobian: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, x: <MagicMock name='mock.ndarray' id='139857761889296'>, *, column_offset: int) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Update the given jacobian with the given parameter estimates x.

Note

This modifies the given jacobian in-place.

Parameters
  • jacobian – The full Jacobian containing the parts of all parameter groups (including this one) but without the contribution from evaluating the parameters of this group.

  • x – The current estimate of parameter values for this group.

  • column_offset – The offset in number of columns where this parameter group is located within the Jacobian.

Returns

The Jacobian with the contribution from evaluating the parameters of this group added.

update_orm(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, x: <MagicMock name='mock.ndarray' id='139857761889296'>) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Update the given orm with the given parameter estimates x.

Note

This modifies the given orm in-place.

Parameters
  • orm – The ORM without the contribution from evaluating the parameters of this group.

  • x – The current estimate of parameter values for this group.

Returns

The ORM with the contribution from evaluating the parameters of this group added.

class accinv.parameters.HBpmGainErrors(n: int, orm_shape: tuple[int, int])

Bases: GainErrors

Parameter group representing gain errors of horizontal BPMs.

class accinv.parameters.HSteererGainErrors(n: int, orm_shape: tuple[int, int])

Bases: GainErrors

Parameter group representing gain errors of horizontal steerers.

class accinv.parameters.Multipoles(names: Collection[str], *, delta: float = 1e-07)

Bases: NumericalParameterGroup

Parameter group representing thin multipoles.

This parameter group expects KNL[1] and KSL[1] values as estimates (in that order for each multipole).

Note

The number of parameters represented by this group, count, is twice the number of given sextupoles (KNL and KSL).

Parameters
build_configuration_from_values(x: <MagicMock name='mock.ndarray' id='139857761889296'>) Collection[ParameterUpdate]

Build a parameter configuration from the given values.

Parameters

x – The parameter values for the group.

Returns

The configuration containing the parameter values.

Raises

ValueError – If the number of given values does not match the number of parameters contained in that group.

property count: int

The number of parameter values represented by this group.

class accinv.parameters.NumberParameters(names: Sequence[str], *, delta: float)

Bases: NumericalParameterGroup

Parameter group representing general floating point numbers.

Parameters
build_configuration_from_values(x: <MagicMock name='mock.ndarray' id='139857761889296'>) Collection[ParameterUpdate]

Build a parameter configuration from the given values.

Parameters

x – The parameter values for the group.

Returns

The configuration containing the parameter values.

Raises

ValueError – If the number of given values does not match the number of parameters contained in that group.

property count: int

The number of parameter values represented by this group.

class accinv.parameters.NumericalParameterGroup(n: int, delta: float)

Bases: ParameterGroup

Parameter group which uses numerical estimates for its Jacobian.

Parameters
  • n – See ParameterGroup.

  • delta – The parameters’ delta increment to be used for computing the Jacobian via finite difference approximation.

build_configuration_from_values(x: <MagicMock name='mock.ndarray' id='139857761889296'>) Collection[ParameterUpdate]

Build a parameter configuration from the given values.

Parameters

x – The parameter values for the group.

Returns

The configuration containing the parameter values.

Raises

ValueError – If the number of given values does not match the number of parameters contained in that group.

class accinv.parameters.ParameterGroup(n: int)

Bases: object

This class represents a group of similar parameters.

The number of parameter values represented by this group is available from the count attribute. This can be different from the number of group members (denoted by the argument n). The count depends on the specific implementation of a parameter group.

Parameters

n – The number of group members. One member may represent more than one parameter value.

property count: int

The number of parameter values represented by this group.

class accinv.parameters.Quadrupoles(names: Sequence[str], *, lengths: Sequence[float], delta: float = 1e-07)

Bases: NumericalParameterGroup

Parameter group representing thick quadrupoles.

Note

This parameter group expects DK1L values as estimates, i.e. deviations from the quadrupoles’ nominal integrated strengths K1L. However, the underlying quadrupole elements are varied by their K1 attribute, so these need to be thick quadrupoles.

Parameters
  • names – The names of the quadrupoles.

  • lengths – The lengths of the individual quadrupoles.

  • delta – See NumericalParameterGroup.

build_configuration_from_values(x: <MagicMock name='mock.ndarray' id='139857761889296'>) Collection[ParameterUpdate]

Build a parameter configuration from the given values.

Parameters

x – The parameter values for the group.

Returns

The configuration containing the parameter values.

Raises

ValueError – If the number of given values does not match the number of parameters contained in that group.

property count: int

The number of parameter values represented by this group.

classmethod from_model(model: Model, *, names: Collection[str], delta: float = 1e-07) Quadrupoles
Create a new quadrupoles parameter group by fetching relevant information

from the given model.

Parameters
  • model – The model will be queried for information about the lengths of quadrupoles.

  • names – See Quadrupoles.

  • delta – See Quadrupoles.

Returns

Quadrupoles parameter group.

class accinv.parameters.VBpmGainErrors(n: int, orm_shape: tuple[int, int])

Bases: GainErrors

Parameter group representing gain errors of vertical BPMs.

class accinv.parameters.VSteererGainErrors(n: int, orm_shape: tuple[int, int])

Bases: GainErrors

Parameter group representing gain errors of vertical steerers.

accinv.parameters.update_jacobian_with_gain_errors(jacobian: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, gain_errors: ~typing.Iterable[float], *, hbpms: ~typing.Collection[str], hsteerers: ~typing.Collection[str], vbpms: ~typing.Collection[str], vsteerers: ~typing.Collection[str], column_offset: int) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Convenience function for updating the given jacobian with the given gain_errors.

Note

This updates the given jacobian in-place.

Parameters
  • jacobian – The Jacobian.

  • gain_errors – Iterable object containig the gain errors. The contained errors are assumed to correspond to hbpms, hsteerers, vbpms, vsteerers in that order.

  • hbpms – The names of horizontal BPMs.

  • hsteerers – The names of horizontal steerers.

  • vbpms – The names of vertical BPMs.

  • vsteerers – The names of vertical steerers.

  • column_offset – The column offset from the left of the location where the gain errors are located inside the Jacobian. That is, the column_offset must be the number of columns that are to the left of the gain errors “block”.

Returns

The updated Jacobian. Note that this is the same object as the original jacobian which is updated in-place.

accinv.parameters.update_orm_with_gain_errors(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, gain_errors: ~typing.Iterable[float], *, hbpms: ~typing.Collection[str], hsteerers: ~typing.Collection[str], vbpms: ~typing.Collection[str], vsteerers: ~typing.Collection[str]) <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>

Convenience function for updating the given orm with the given gain_errors.

Note

This updates the given orm in-place.

Parameters
  • orm – The ORM.

  • gain_errors – Iterable object containig the gain errors. The contained errors are assumed to correspond to hbpms, hsteerers, vbpms, vsteerers in that order.

  • hbpms – The names of horizontal BPMs.

  • hsteerers – The names of horizontal steerers.

  • vbpms – The names of vertical BPMs.

  • vsteerers – The names of vertical steerers.

Returns

The updated ORM. Note that this is the same object as the original orm which is updated in-place.