-
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
Miscellaneous changes to pyat #103
Conversation
On the note of the numpy bug, it is caused by us trying to create an empty record array in
Edit: I forgot to mention one of our internal modules is pinned to numpy 1.11.1, hence the desire for a workaround. |
We actually do have something that depends on the older version of numpy, so I think we should use this workaround for the time being (with a comment that explains it). |
pyat/at/load/utils.py
Outdated
'../../integrators', | ||
pass_method + extension)) | ||
if not os.path.exists(file_path): | ||
raise AttributeError('PassMethod {0} does not exist.' |
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.
We should report the element index (if available) in the error message, like it is done in err_message
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.
will do
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.
I've updated err_message
so that it can be used here as well.
The generalization of Concerning chromaticity and dispersion values: pushing |
pyat/at/lattice/lattice_object.py
Outdated
warn(AtWarning('Inconsistent energy values, ' | ||
'"energy" set to {0}'.format(energy))) | ||
attributes['energy'] = energy | ||
attributes['energy'] = get_ring_energy(elems) |
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.
There is a problem here:
I made significant modifications to lattice_object
in the plot_preparation
branch. To avoid unnecessary list
copies (build a list
first, and then give it to super(Lattice, self).__init__
, the list
constructor, which will itself build a copy of this list
), full_scan
now accepts any iterable as input and returns an iterator over the elements. So it is executed within super(Lattice, self).__init__
. The gain is most effective when the input to full_scan
is itself an iterator. In such a case, after the first loop over elements, get_ring_energy
will get an empty iterator, and fail.
Example: we have a Lattice ring
, without RingParam
element but with an RFCavity
giving the energy. Let's assume we want to filter this lattice with some condition:
ring2=Lattice([elem for elem in ring if <some condition>])
Here we build a list first, which will be copied by the list constructor. get_ring_energy
will work.
ring2=Lattice(elem for elem in ring if <some condition>)
Here we have no intermediate list, <some condition>
will be tested within the list constructor and get_ring_energy
will fail.
I think we should keep the possibility of accepting any iterable (sequence or iterator) as input, not only a sequence.
For the time being, I suggest to keep lattice_object unchanged to avoid merging problems. Keep all your other modifications as they are, let's merge both branches and start over then with this code factorisation.
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.
Ok, I will revert the modifications to lattice_object
for now. Yes, I am learning that working on multiple branches at once is a recipe for problems, the test on #102 is failing because it relies on changes made here.
I am now happy for this to merge, does anyone have anything else that they would like to add? |
nothing else to say, go on with merging! |
pyat/at/load/utils.py
Outdated
if (pass_method == 'IdentityPass') and (length != 0.0): | ||
raise AttributeError(err_message("length {0}.", length)) | ||
extension = sysconfig.get_config_vars().get('EXT_SUFFIX', '.so') | ||
file_path = os.path.realpath(os.path.join(__file__, |
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.
This feels a bit brittle to me. Could you import the module instead, or is there a reason you don't want to do that?
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.
Whatever method we use we have to do all this messy filepath finding.
If we do a try except to open and read the file then we have to catch different errors, IOError
in python 2 and FileNotFoundError
in python 3. I just thought that was messier than os.path.exists
.
pyat/test/test_lattice_object.py
Outdated
from at.lattice import Lattice, AtWarning, AtError | ||
|
||
|
||
def test_lattice_creation(): |
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.
Some of these tests are really two or three tests bundled into one.
It's probably better to split them. You end up with very long test names, but people do like that style:
http://blog.socosomi.com/dont-be-afraid-of-long-test-names/
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.
Ok, I'll split some of them down.
I made a couple of comments, but generally looks good, thanks. |
A number of changes from my todo list for AT.
A rough summary of the changes:
multi_dot
have been converted to.dot
so that we are consistent throughout pyat.ohmi_envelope
to work with any pyat lattice description.sanitise_class
to ensure the specified pass method exists, also added warnings infind_class_name
if noPassMethod
is given or if the one given doesn't end in 'Pass'.get_mcf
when it is called on the lattice, as we do forlinopt
andohmi_envelope
.Some questions that I still have:
get_twiss
andlinopt
ifget_chrom
isFalse
then we:None
ornumpy.NaN
?at.lattice.utils
andat.load.utils
, they are not in the same directory so there is not an immediate issue, however, because of pyat's import structureat.utils
is valid and returns the lattice utils; is this ambiguity advised or could one of them be sensibly renamed?