Skip to content

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

@roman-martin

Description

@roman-martin
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions