at.latticetools.observablelist#
Grouping of Observable objects for fast evaluation.
ObservableList(lattice, …)This container based on
listis in charge of optics computations and provides each individualObservablewith its specific data.
ObservableList provides the evaluate()
method and the following properties:
Classes
|
A reference to a parameter given to the ObservableList.evaluate method. |
|
Handles a list of Observables to be evaluated together. |
- class EvaluationVariable(obslist, key, *args, **kwargs)[source]#
Bases:
ItemVariableA reference to a parameter given to the ObservableList.evaluate method.
The variable drives the default value of a
ObservableList.evaluate()keyword argument.- Parameters:
obslist (ObservableList) – The
ObservableListto control,key – Index or attribute name of the variable. A
strargument is interpreted as a dictionary key. Attribute names must be decorated withattr_(attrname)to distinguish them from directory keys.*args – additional sequence of indices or attribute names allowing to extract elements deeper in the object structure.
- Keyword Arguments:
Example
Create a twiss_in input for computing optics in transfer-line mode:
>>> twiss_in = {"alpha": np.zeros(2), "beta": np.array([9.0, 2.5])}
Create the
ObservableList:>>> obs = at.ObservableList( ... [ ... at.LocalOpticsObservable([0], "beta", plane="x"), ... at.LocalOpticsObservable([0], "beta", plane="y"), ... ], ... ring=ring, ... dp=0.01, ... orbit=np.zeros(6), ... twiss_in=twiss_in, ... )
Create a variable controlling \(\delta\):
>>> v3 = at.EvaluationVariable(obs, "dp") >>> v3.value 0.01
Create a variable controlling \(p_x\):
>>> v2 = at.EvaluationVariable(obs, "orbit", 1) >>> v2.value np.float64(0.0)
Create a variable controlling \(\beta_x\):
>>> v1 = at.EvaluationVariable(obs, "twiss_in", "beta", 0) >>> v1.value np.float64(9.0)
- class ObservableList(obsiter=(), ring=None, **kwargs)[source]#
Bases:
listHandles a list of Observables to be evaluated together.
ObservableListsupports all thelistmethods, like appending, insertion or concatenation with the “+” operator.- Parameters:
obsiter (Iterable[Observable]) – Iterable of
Observablesring (Lattice | None) – Default lattice. It will be used if ring is not provided to the
evaluate()function.
The following keyword arguments define the default values to be used when not given to the
evaluate()method- Keyword Arguments:
orbit (Orbit) – Initial orbit. Avoids looking for the closed orbit if it is already known. Used for
MatrixObservableandLocalOpticsObservabletwiss_in – Initial conditions for transfer line optics. See
get_optics(). Used forLocalOpticsObservabler_in (Orbit) – Initial trajectory, used for
TrajectoryObservable, Default: zeros(6)df (float) – Deviation from the nominal RF frequency. Defaults to
Nonemethod (Callable) – Method for linear optics. Used for
LocalOpticsObservable. Default:linopt6use_mp (bool) – Activate parallel calculation. Used for
RDTObservable, Default:Falsepool_size (int | None) – Number of processes used for parallelization. Used for
RDTObservable, Default:None**kwargs – Other keywords are passed to the evaluation functions.
Example
>>> obslist = ObservableList()
Create an empty Observable list
>>> obslist.append(OrbitObservable(at.Monitor, plane="x")) >>> obslist.append(GlobalOpticsObservable("tune")) >>> obslist.append(EmittanceObservable("emittances", plane="h"))
Add observables for horizontal closed orbit at Monitor locations, tunes and horizontal emittance
>>> obslist.evaluate(ring, initial=True)
Compute the values and mark them as the initial value
>>> obslist.values [array([-3.02189464e-09, 4.50695130e-07, 4.08205818e-07, 2.37899969e-08, -1.31783561e-08, 2.47230794e-08, 2.95310770e-08, -4.05598110e-07, -4.47398092e-07, 2.24850671e-09]), array([3.81563019e-01, 8.54376397e-01, 1.09060730e-04]), 1.320391045951568e-10]
>>> obslist.get_flat_values("tune", "emittances[h]") array([3.815630e-01, 8.543764e-01, 1.090607e-04, 1.320391e-10])
Get a flattened array of tunes and horizontal emittance
- evaluate(ring=None, *, initial=False, **kwargs)[source]#
Compute all the
Observablevalues.- Parameters:
- Keyword Arguments:
orbit (Orbit) – Initial orbit. Avoids looking for the closed orbit if it is already known. Used for
MatrixObservableandLocalOpticsObservabletwiss_in – Initial conditions for transfer line optics. See
get_optics(). Used forLocalOpticsObservabler_in (Orbit) – Initial trajectory, used for
TrajectoryObservable, Default: zeros(6)df (float) – Deviation from the nominal RF frequency. Defaults to
Nonemethod (Callable) – Method for linear optics. Used for
LocalOpticsObservable. Default:linopt6use_mp (bool) – Activate parallel calculation. Used for
RDTObservable, Default:Falsepool_size (int | None) – Number of processes used for parallelization. Used for
RDTObservable, Default:None**kwargs – Other keywords are passed to the evaluation functions.
- get_flat_deviations(*obsid, err=None, order='F')[source]#
Return a 1-D array of deviations from target values.
- get_flat_weighted_deviations(*obsid, err=None, order='F')[source]#
Return a 1-D array of weighted deviations from target values.
- get_flat_weighted_values(*obsid, err=None, order='F')[source]#
Return a 1-D array of Observable weighted values.
- get_weighted_deviations(*obsid, err=None)[source]#
Return the weighted deviations from target values.
- property flat_deviations: ndarray[tuple[Any, ...], dtype[float64]]#
1-D array of deviations from target value
- property flat_shape#
Shape of the flattened values
- property flat_weighted_deviations: ndarray[tuple[Any, ...], dtype[float]]#
1-D array of weighted deviations from target values