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

Particles.copy() does not properly copy particle.lost_particles #58

Open
roman-martin opened this issue Oct 22, 2020 · 0 comments
Open

Comments

@roman-martin
Copy link

import pysixtrack
import numpy as np

p1 = pysixtrack.Particles(state=np.array([0,0,1,1]))
p2 = p1.copy()

assert len(p1.lost_particles) == 0
assert len(p2.lost_particles) == 0

p1.remove_lost_particles()

assert len(p1.lost_particles) == 1
assert len(p2.lost_particles) == 0

Although we don't do anything with p2 after copying it from p1, cleaning up p1 changes p2.lost_particles.

This is because in Particle.copy() we only do a .copy (or slice copy) if the __dict__ item is of type np.array or dict. Unfortunately particle.lost_particles is of type list. Now we could include lists (an other mutables) to the check. However, the index that is also used, means something VERY different for x, px, etc than it does for lost_particles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant