Skip to content
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

Observable objects #738

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Observable objects #738

wants to merge 14 commits into from

Conversation

lfarv
Copy link
Contributor

@lfarv lfarv commented Feb 16, 2024

This PR introduces Observable objects. Together with Variable objects, they provide a unified and expandable set objects which can be used in matching, response matrices, plots, parameter scans…

ObservableLists optimise the performance in evaluating the observables by grouping the requirements of observables and limiting the computations to the strict minimum.

The initial set of Observables provided here gives access to most of lattice properties. It can be easy extended by providing custom evaluation functions or inheriting from the basic set.

A documentation preview is here, and a demo notebook is provided.

@lfarv lfarv added enhancement Python For python AT code labels Feb 16, 2024
@lfarv lfarv mentioned this pull request Feb 20, 2024
@lfarv lfarv force-pushed the observables branch 2 times, most recently from 59d4a1b to d3584bc Compare March 22, 2024 12:15
Copy link
Contributor

@swhite2401 swhite2401 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lfarv, I started looking at this proposal, and stopped because I think the overall design needs to be improved starting from the decision made for the Variables class.

I would implement a true base class, that does not need any ring and implements an abstract method for the evaluation function such that a signature is not imposed at this stage.
A few details in the code review.

Then I have a question, why defining "Private classes"? What is the motivation for that?

For the rest it seems ok but we can come back to it once the base design is fixed

"""Setup function called when the observable is added to a list"""
pass

def evaluate(self, ring: Lattice, *data, initial: bool = False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base class is general, is ring really needed to evaluate an observable? I would make it optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly why do we request data here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ring" does not appear anymore the definition of the Observable class.

But data is still there: it's necessary for most evaluation functions, and depends on the needs argument. It's empty if no need is specified.

I have no more example of use of this basic observable. Do you have an idea of such an observable which does not depend on ring? Now for observables depending an a ring, it's easier to use more specific classes like RingObservable of ElementObservable

pyat/at/latticetools/observables.py Outdated Show resolved Hide resolved
pyat/at/latticetools/observables.py Show resolved Hide resolved
GEOMETRY = 10


class Observable(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename BaseObservable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be done… But since this can be used directly by users, I find the simple Observable name clearer. I can change if you find ObservableBase better…

pyat/at/latticetools/observables.py Outdated Show resolved Hide resolved
super().__init__(fun, refpts, needs=needs, name=name, **kwargs)


class _GlobalOpticsObservable(Observable):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again why this notation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's not supposed to used directly. If we want it public, on has to find new names for both _GlobalOpticsObservable and GlobalOpticsObservable.

@lfarv
Copy link
Contributor Author

lfarv commented Jun 5, 2024

@swhite2401: I think all your comments have been addressed. Now do you have ideas for user-defined observables for

  • Observable, the base class, with an example independent of any ring,
  • ElementObservable, With an example which does not fall into the more specific classes ?

I would be nice to put these in the documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants