accinv.loco module¶
- class accinv.loco.Loco(model_and_jacobian_method: Union[tuple[accinv.model.Model, Type[accinv.jacobian.NumericalJacobianMethod]], tuple[accinv.model.OpticsModel, Type[accinv.jacobian.AnalyticalJacobianMethod]], tuple[accinv.model.Model, accinv.jacobian.ComputeJacobianFunction]], *, hbpms: Collection[str], hsteerers: Collection[str], vbpms: Collection[str], vsteerers: Collection[str], orm_measurement: OrmMeasurement, quadrupoles: Optional[Collection[str]] = None, multipoles: Optional[Collection[str]] = None, fit_gain_errors: bool = True, parameters: Optional[Collection[ParameterGroup]] = None, remove_coupling_blocks_from_orm: bool = False, optimizer: Optional[Optimizer] = None, compute_orm_kwargs: Optional[dict[str, Any]] = None, customize_residuals: Optional[CustomizeResiduals] = None, customize_jacobian: Optional[CustomizeJacobian] = None)¶
Bases:
object
Main class for LOCO (linear optics from closed orbits) inverse modeling.
Note
The order in which fitting parameters are appended from shorthand arguments is the same in which they appear in the function signature, i.e. quadrupoles followed by multipoles and gain errors. This is the same order in which the resulting parameter estimates are reported.
Note
Any element or parameter names should be given in lowercase. This is the convention used by the
Model
backends. While lowercase conversion is ensured for the shorthand arguments (e.g. quadrupoles) this is not done for the parameters specified via parameters.- Parameters
model_and_jacobian_method – The accelerator model and the Jacobian method to be used for computations.
hbpms – Names of horizontal BPMs.
hsteerers – Names of horizontal steerers.
vbpms – Names of vertical BPMs.
vsteerers – Names of vertical steerers.
orm_measurement – The measured ORM and uncertainty to be fitted against the model.
quadrupoles – Names of thick quadrupoles which are added as parameters to the fitting. This is a shorthand argument. Internally, the given names are converted to
Quadrupoles
.multipoles – Names of thin multipoles which are then added as parameters to the fitting. This is a shorthand argument. Internally, the given names are converted to
Multipoles
.fit_gain_errors – Flag to indicate whether BPM and steerer gain errors should be fitted. If true (the default), then those gain error parameters are appended to the specified parameters which are not present there yet.
parameters – The parameters to be fitted. If fit_gain_errors is true, then the corresponding parameters will be added automatically, i.e. they should not appear here.
remove_coupling_blocks_from_orm – (optional, default: False) If true, only the main diagonal blocks of the ORM will be used for fitting. This realized by modifying the residuals and Jacobian similar to customize_residuals and customize_jacobian. The selection of main diagonal blocks is inserted before these custom functions which will only receive the main diagonal blocks as arguments.
optimizer – The choice of optimizer for the fitting procedure (defaults to
LeastSquares
).compute_orm_kwargs – Additional keyword arguments for the ORM computation via
Model.compute_orm()
. This includes thekicks
keyword argument which will default toLoco.DEFAULT_STEERER_KICKS
if not specified.customize_residuals – Callable which receives the current parameter guess and the corresponding residuals to return a customized version of the residuals.
customize_jacobian – Callable which receives the current parameter guess and the corresponding Jacobian to return a customized version of the Jacobian.
- DEFAULT_STEERER_KICKS = [0.0001]¶
- build_wrapper() Wrapper ¶
Build the
Wrapper
instance for this LOCO setup.
- check_missing_elements(elements: Mapping[str, Collection[str]]) None ¶
Check if any of the specified elements are missing in the model.
- Parameters
elements – Maps arbitrary labels to names of elements.
- Raises
MissingElementsError – If any of the specified elements are missing.
- run(*, guess: ~typing.Optional[<MagicMock name='mock.ndarray' id='139857761889296'>] = None, maxiter: ~typing.Optional[int] = None) Result ¶
Start the inverse modeling and return the result.
- Parameters
guess – Optional initial guess for the parameter values (defaults to zero).
maxiter – Maximum number of iterations in terms of the Jacobian evaluation.
- Returns
Result
object which contains various information about the fitting result;result.x
are the final parameter values.
- exception accinv.loco.MissingElementsError(type_: str, names: Collection[str], /)¶
Bases:
Exception
- class accinv.loco.OrmMeasurement(orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>, uncertainty: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>)¶
Bases:
object
This class represents the data for an ORM measurement.
- orm: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>¶
- uncertainty: <MagicMock name='mock.NDArray.__getitem__()' id='139857758038624'>¶