-
Notifications
You must be signed in to change notification settings - Fork 33
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
Improvement of the "refpts" argument #547
Conversation
ConsequencesDirectly indexing a Lattice with the new formats also works. Examples:
The three utility functions mentioned above still behave as before, but are now redondant:
CautionThe new features should automatically appear in all functions having a "refpts" argument, without any modifications.
|
CompatibilityA few changes have been made for cleanliness, but can be reverted:
|
There are large modifications to the documentation ( |
pyat/at/lattice/utils.py
Outdated
get_cells(ring, attrname) -> BoolRefpts | ||
get_cells(ring, attrname, attrvalue) -> BoolRefpts | ||
Returns a bool array of element indices, selecting ring elements. | ||
|
||
With minor modifications, this function can be replaced by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you trying to indicate with this comment? You have already mentioned elsewhere that this does not have the same behaviour as Lattice.bool_refpts.
Are we to treat one of these as deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we to treat one of these as deprecated?
I would say so (see below) …
I think a lot of my confusion when reading these changes is due to how the original functions behave. E.g. This pull request 'opens new possibilities', but I wonder whether we should put more effort into directing people to a subset of these functions? Are we able to consider deprecating certain functions, now that we have more experience using pyat? We still haven't made a major version release of pyat. I'm much more interested in hearing your thoughts on this topic, than actually demanding these changes as part of your pull request. Perhaps you already have long-term plans for the full release of pyat that I am not aware of. |
@MJGaughran : You are pointing out some of the reasons driving these changes: We try here to ease a very common task in AT: selecting elements in a lattice, whether you want to act of these elements, or want to define "points of interest" to get results. The present behaviour is the exact copy of the Matlab way: indexing a lattice with either an array of integers or an array of booleans (by the way, the name of So in most usual cases, this requires a 2-step sequence: 1st generate the indexing array with What I propose here is to make this simpler by skipping the 1st step and having all functions having a refpts argument (there are a lot) accept all the various selectors accepted by
I agree with you, a subset of the existing function would now be sufficient. For naming reasons, I would favour using However, I don't think we can still make breaking changes to the interface: there is already too much user code around. But there is a lot to do in the documentation, to, as you said, 'direct people to a subset'. For instance rewrite this. Should we also hide some functions from the API doc ( Now, concerning a 'full release' of PyAT… I'd rather think that we are already in an infinitely evolutive situation. We missed version 1.0.0, but we could jump to it any time… |
To me, the clear interface would include A function such as |
These two forms are exactly the ones used in numpy's advanced indexing. Each has its advantages, depending what you want to do. In particular, boolean array indexing is very convenient, as I showed above. I think we should stick to that!
So I understand that you would rather keep all functions documented as they are now, that's fine for me. If you have ideas to modify and improve the updated documentation, tell me. |
You have made good arguments for picking those. I prefer having verbs in method names but that's only an opinion. My inclination is to mark the other functions as deprecated, regardless of whether we actually come to remove them. Could removing these functions from documentation make it harder to know how to migrate to the preferred methods? |
That makes sense, I take note…
So I'll add a deprecation message in the 3 functions, more precise than the present sentence. |
All this looks fine for me, I support having self explanatory function name in fact the names: However, I am wondering what a deprecation warning means if we do not intend to remove the function, is it really necessary or useful? |
I have to agree with all of Simon's points. A deprecation warning means new users will know to use the improved interface. It means we can drop the older functions from any tutorials etc, and using this module is less confusing. I would have pushed to remove these functions for a major version 2, regardless of what we agreed at this point. |
If this is our intention, it is perhaps a better idea to more carefully construct our preferred interface at this stage, rather than trying to bodge things to keep backwards compatibility. If we can merge in any outstanding behaviour changes for a version 1 release, we can then look towards an improved interface for version 2. |
Trying to summarise your comments: Now (this PR):
On the medium term: I'm very reluctant to remove the useless functions. Backward compatibility is crucial, I'm very concerned by comments like "My code was working 6 months ago and it fails now…". Keep aliases does not cost anything and we can keep the code clean by moving them all to a dedicated module ( On the long term: At some point we can first completely remove the useless functions from the doc |
Ok for me, a separate module to hold deprecated functions is a good compromise. |
@swhite2401 : Ok to leave |
Replacing Lattice.bool_refpts by Lattice.get_bool_refpts everywhere in PyAT means modifying many files. I would not do that in this branch. So I'll move useless files in a |
@swhite2401 and @MJGaughran : Is it ok for you now ? |
@swhite and @MJGaughran: A last question before finalising te thing:
Thanks for your help… |
Hello @lfarv, in fact I do agree with you |
This is major upgrade concerning the definition of the common "refpts" argument.
Up to now, the "refpts" value is restricted to two forms : integer form and boolean form. Three utility functions:
get_cells
,get_refpts
andget_elements
can convert other forms like element FamNames, element types or filter functions to the two basic forms.The refpts argument can be processed by 4 main functions:
uint32_refpts
: sanity check and conversion to the integer formbool_refpts
: sanity check and conversion to the bool formrefpts_count
: count of the selected lattice elementsrefpts_iterator
: iterate through the selected lattice elementsHere we will upgrade these 4 functions to accept any form accepted until now by
get_cells
,get_refpts
... So now, the refpts argument may one of:indexing rules. As a special case, len(lattice) is allowed and refers to the end of the last element,
True
,None
, meaning an empty selection,All
, new keyword meaning "all possible reference points": the entrance of allelements plus the end of the last element,
End
, new keyword selecting the end of the last element,the lattice, e.g.
at.Sextupole
,FamName
attribute matches it.Unix shell-style wildcards are accepted, e.g.
"Q[FD]*"
,filtfunc
such thatfiltfunc(elem)
isTrue
for selected elementsThis opens new possibilities without breaking anything.