This PR is the companion of lnls-fac/trackcpp#75, which is a retry of PR lnls-fac/trackcpp#74, based on the discussions raised there.
It adds the information of lost positions of tracked particles in line_pass and ring_pass as a separated output.
Besides this change, it also features:
lost_flag is now a list of booleans indicating whether each particle was lost;
lost_turn and lost_element are filled with -1 for surviving particles;
fix bug in line_pass for parallel tracking with number of particles > 1 but < than the number of processes.
Changes in RadiationStates: Now RadiationStates is a namedtuple defined in the Accelerator class. The options are also in title case;
Change name of Exceptions so that they finish with Error instead of Exception (linter suggestion);
Add LossInfo class to concentrate information about particle losses;
Fix find_orbit6: do not change radiation_on to 'Damping' when it is 'Off';
Remove unused auxiliary functions and deprecated tracking functions: names such as linepass, ringpass and elementpass do not exist anymore;
Improve docstring of tracking functions.
Tests
Comparison of tracking results with master branch:
The following comparison was performed against the master branch of trackcpp and pyaccel:
The following code was run on both, master branch of trackcpp and pyaccel and this branch in pyaccel and the branch of lnls-fac/trackcpp#75:
import numpy as np
import pyaccel as pa
from mathphys.functions import load, save
from pymodels import si
mod = si.create_accelerator()
mod = si.fitted_models.vertical_dispersion_and_coupling(mod)
mod.cavity_on = True
mod.radiation_on = 0
mod.vchamber_on = True
print(mod)
eqpar = pa.optics.EqParamsFromBeamEnvelope(mod)
np.random.seed(2030948)
parts = pa.tracking.generate_bunch(1000, eqpar.envelopes[0]*(8e-3/65e-6)**2)
out_line = pa.tracking.line_pass(
mod, parts, indices='closed', element_offset=0, parallel=True,
)
out_ring = pa.tracking.ring_pass(
mod, parts, nr_turns=10, turn_by_turn=True, element_offset=0, parallel=True
)
# on this branch
save(out_line, 'sirius_dev_line', overwrite=True)
save(out_ring, 'sirius_dev_ring', overwrite=True)
# on master branch
# save(out_line, 'sirius_mas_line', overwrite=True)
# save(out_ring, 'sirius_mas_ring', overwrite=True)
then, the following comparison was made (must be in the current branches of this PR):
import numpy as np
from mathphys.functions import load, save
out_dev_line = load('sirius_dev_line')
out_dev_ring = load('sirius_dev_ring')
out_mas_line = load('sirius_mas_line')
out_mas_ring = load('sirius_mas_ring')
print(out_mas_line[0].tobytes() == out_dev_line[0].tobytes())
print(out_mas_ring[0].tobytes() == out_dev_ring[0].tobytes())
and the equalities hold.
Test of output shapes:
I also performed a test to check if the shape of the tracking results and the lost positions were consistent when different parameters of the tracking functions were used. The following code was used:
from itertools import product
import numpy as np
import pyaccel as pa
from mathphys.functions import load, save
from pymodels import si
mod = si.create_accelerator()
mod = si.fitted_models.vertical_dispersion_and_coupling(mod)
mod.cavity_on = True
mod.radiation_on = 0
mod.vchamber_on = True
print(mod)
parts = np.array([
[-11.8e-3, 1e-5, 0, 0, 0, 0],
[1e-4, 0, 0, 0, 0, 0]
]).T
print('ring_pass')
idcs = True, False
para = True, False
nrpt = 1, 2
for idx, par, nrp in product(idcs, para, nrpt):
out = pa.tracking.ring_pass(
mod, parts[:, :nrp], nr_turns=2, turn_by_turn=idx, element_offset=0, parallel=par
)
print(
idx,
par,
nrp,
out[0].shape,
out[1].lost_pos.shape,
)
print('line_pass')
idcs = 'closed', None
para = True, False
nrpt = 1, 2
for idx, par, nrp in product(idcs, para, nrpt):
out = pa.tracking.line_pass(
mod, parts[:, :nrp], indices=idx, element_offset=0, parallel=par,
)
print(
idx,
par,
nrp,
out[0].shape,
out[1].lost_pos.shape
)
Description
This PR is the companion of lnls-fac/trackcpp#75, which is a retry of PR lnls-fac/trackcpp#74, based on the discussions raised there. It adds the information of lost positions of tracked particles in
line_pass
andring_pass
as a separated output.Besides this change, it also features:
lost_flag
is now a list of booleans indicating whether each particle was lost;lost_turn
andlost_element
are filled with-1
for surviving particles;line_pass
for parallel tracking with number ofparticles > 1
but<
than the number of processes.RadiationStates
: NowRadiationStates
is a namedtuple defined in theAccelerator
class. The options are also in title case;LossInfo
class to concentrate information about particle losses;find_orbit6
: do not changeradiation_on
to'Damping'
when it is'Off'
;linepass
,ringpass
andelementpass
do not exist anymore;Tests
Comparison of tracking results with master branch:
The following comparison was performed against the master branch of trackcpp and pyaccel: The following code was run on both, master branch of trackcpp and pyaccel and this branch in pyaccel and the branch of lnls-fac/trackcpp#75:
then, the following comparison was made (must be in the current branches of this PR):
and the equalities hold.
Test of output shapes:
I also performed a test to check if the shape of the tracking results and the lost positions were consistent when different parameters of the tracking functions were used. The following code was used:
resulting in: