copy.deepcopy when inserting elements in a ring #477
simoneliuzzo
started this conversation in
Python AT
Replies: 1 comment
-
No, you should not have to use
Keep in mind that in python everything is a reference. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have spent several hours tracking back this issue. Thanks a lot to @lcarver, who spotted the problem.
I tried to insert elements in the lattice, thin correctors.
I forgot to add copy.deepcopy(element) so all elements were being updated as a family in later computations.
I think I am not the only one that fell into this trap. Below a code snippet:
I find that in pyAT the use of copy.deepcopy() is necessary very often in order. It is in fact a really frequent reason for unreasonable results in my code.
Is there a way to make more clear to the user that an element is not an individual but it is linked to many others?
Is there a way to 'un-link' all magnets in a lattice? (
independent_ring = [copy.deepcopy(el) for el in ring]
)Beta Was this translation helpful? Give feedback.
All reactions