-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variables, parameters and observables #696
Conversation
The new classes introduce name conflicts with existing
|
Dear @lfarv, this is a very big pull request (26 files!). I have no idea how to "test" it completely. There are many new classes, many new features. How to test each of them in realistic conditions? I may test the matching for example. The known breaking of backward compatibility is also a major issue for me. I am looking at the notebooks in docs/p/notebooks. VERY USEFUL to get trough all this work! Observable.ipynb
parameters.ipynb
I think that it would be wise to make the above lines work as expected from the user (exactly as in the example!) rather than giving a warning.
variables.ipynb
test_variables.ipynb
These notebook examples are really a good way to understand what the code does. Could we have more examples for the use of other classes mentioned in this pull request? MartrixObservable, GlobalLatticeObservable, Trajectory and Gemoetry observables? thank you best regards Simone |
Hi @simoneliuzzo. Very nice review of the present state of things, thanks ! I'll give today the "easy" answers, I'll go step by step later for the rest. Variables
Work in progess, there is now a better version
Just to add vectorised methods corresponding to the individual ones. Examples: Observables
This is a design decision. When reading the code, it makes clear what each object does, and it makes each class more efficient by avoiding "
observables.ipynb gives one example of each of all the available
Of course it can! See in the given examples LocalOpticsObservable(at.Monitor, 'beta', plane='v', statfun=np.amax) to get the maximum vertical β on monitors.
This is triggered by the
Not now. You can always do it in two steps refs = ring.get_bool_index("pattern", regexp=True)
pbs = LocalOpticsObservable(refs, 'beta', ...) It can easily be added. I'll do it. But now, regexp is still not accepted in the dozens of optics functions using a refpts argument. So why accepting it here? |
Hello @lfarv, thanks for reviving this. I completely agree with @simoneliuzzo that this is too big to properly review and the github discussion on such large PR will quickly become a total mess. I would really appreciate that this PR is split as follows (I think this was already requested in the previous PR): We can then validate each development gradually and potentially improve the next ones using the review comments. |
@swhite2401: the split is done. However, variables and parameters are so intricate that any change on parameters in the proposed step 3 would change again the modules approved in step 1. So we go for: |
This replaces #603. We introduce standard ways of parametrising a lattice, varying any quantity and looking at any resulting quantity. There are 3 main classes:
Variables
Variables are references to any scalar quantity. AT includes two predefined
variable classes referring to scalar attributes of lattice elements:
ElementVariable
is associated to an element object, and acts on all occurences of this object. But it will not affect any copy, neither shallow nor deep, of the original object,RefptsVariable
is not associated to an element object, but to an element location in aLattice
. It acts on any copy of the initial lattice. A ring argument must be provided to the set and get methods to identify the lattice.Variable referring to other quantities may be created by:
Variable
base class. Usually this consist in overloading the abstract methods _setfun and _getfun,CustomVariable
class, accepting user-defined get and set functions.Parameters
Parameters are objects of class
Param
which can be used asElement
attributes instead of numeric values.Arithmetic combinations of parameters create new read-only parameters of class
ParamBase
, whose value is permanently kept up-to-date. This is useful to introduce correlation between attributes of different elements.Presently the use of parameters is limited to
Element
attributes, but it may me extended in the future (ex:Lattice
attributes).Observables
Observables provide a unified way accessing a large quantity of figures resulting from various computations on lattices. They may be used in parameter scans, matching, response matrices…
AT provides a number of specific observables sharing a common interface, inherited from the
Observable
base class. They are:OrbitObservable
,GlobalOpticsObservable
: tunes, damping times…,LocalOpticsObservable
: β, η…,MatrixObservable
: Tij…,TrajectoryObservable
: x, px…,EmittanceObservable
: εx…,LatticeObservable
: attributes of lattice elements,GeometryObservable
An Observable has optional
target
,weight
andbounds
attributes for matching. After evaluation, it has the following main properties:value
weighted_value
: value / weightdeviation
: value - targetweighted_deviation
: (value - target)/weightresidual
: ((value - target)/weight)**2Custom Observables may be created by providing the adequate evaluation function.
For evaluation, observables must be grouped in an
ObservableList
which optimises the computation, avoiding redundant function calls.ObservableList
provides theevaluate
method, and thevalues
,deviations
,residuals
andsum_residuals
properties, among others.The documentation for the branch is available here. Please read and comment.