Skip to content

Commit e577f8f

Browse files
Merge branch 'release/0.23.2'
2 parents 944abe1 + 66eb424 commit e577f8f

20 files changed

+74
-200
lines changed

examples/particles_generation/000_basics.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import xpart as xp
6+
import xtrack as xt
77
import xobjects as xo
88

9-
ctx = xo.ContextCpu()
10-
11-
particles = xp.Particles(_context=ctx,
12-
mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, # 7 TeV
9+
particles = xt.Particles(_context=ctx,
10+
mass0=xt.PROTON_MASS_EV, q0=1, p0c=7e12, # 7 TeV
1311
x=[1e-3, 0], px=[1e-6, -1e-6], y=[0, 1e-3], py=[2e-6, 0],
1412
zeta=[1e-2, 2e-2], delta=[0, 1e-4])

examples/particles_generation/001a_build_particles_set.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
# Build a reference particle
1010
p0 = xp.Particles(mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, x=1, y=3)
1111

12-
# Choose a context
13-
ctx = xo.ContextCpu()
14-
1512
# Built a set of three particles with different y coordinates
16-
particles = xp.build_particles(_context=ctx, particle_ref=p0, y=[1,2,3])
13+
particles = xp.build_particles(particle_ref=p0, y=[1,2,3])
1714

1815
# Inspect
1916
print(particles.p0c[1]) # gives 7e12

examples/particles_generation/001at_build_particles_set_with_tracker.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@
22
# This file is part of the Xpart Package. #
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
5-
import json
65

76
import xpart as xp
87
import xobjects as xo
98
import xtrack as xt
109

11-
ctx = xo.ContextCpu() # choose a context
12-
13-
# Load machine model and built a line
14-
filename = ('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
15-
with open(filename, 'r') as fid:
16-
line = xt.Line.from_dict(json.load(fid)['line'])
17-
line.build_tracker(_context=ctx)
10+
# Get a line
11+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
1812

1913
# Attach a reference particle to the line
20-
line.particle_ref = xp.Particles(p0c=7e12, mass0=xp.PROTON_MASS_EV, q0=1, x =1 , y=3)
14+
line.set_particle_ref('proton', p0c=7e12, x=1, y=3)
2115

2216
# Built a set of three particles with different y coordinates
2317
# (context and particle_ref are taken from the line)

examples/particles_generation/001b_build_particles_shift.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
# Build a reference particle
1010
p0 = xp.Particles(mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, x=1, y=3)
1111

12-
# Choose a context
13-
ctx = xo.ContextCpu()
14-
1512
# Built a set of three particles with different y coordinates
16-
particles = xp.build_particles(mode='shift', particle_ref=p0, y=[1,2,3],
17-
_context=ctx)
13+
particles = xp.build_particles(mode='shift', particle_ref=p0, y=[1,2,3])
1814

1915
# Inspect
2016
print(particles.p0c[1]) # gives 7e12

examples/particles_generation/001bt_build_particles_shift_with_tracker.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@
22
# This file is part of the Xpart Package. #
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
5-
import json
65

76
import xpart as xp
87
import xobjects as xo
98
import xtrack as xt
109

11-
ctx = xo.ContextCpu() # choose a context
12-
13-
# Load machine model and built a line
14-
filename = ('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
15-
with open(filename, 'r') as fid:
16-
line = xt.Line.from_dict(json.load(fid)['line'])
17-
line.build_tracker(_context=ctx)
10+
# Load machine model
11+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
1812

1913
# Attach a reference particle to the line
20-
line.particle_ref = xp.Particles(p0c=7e12, mass0=xp.PROTON_MASS_EV, q0=1, x=1 , y=3)
14+
line.set_particle_ref('proton', p0c=7e12, x=1, y=3)
2115

2216
# Built a set of three particles with different y coordinates
2317
# (context and particle_ref are taken from the line)

examples/particles_generation/001c_build_particles_normalized.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import json
7-
86
import xobjects as xo
97
import xpart as xp
108
import xtrack as xt
119

12-
# Choose a context
13-
ctx = xo.ContextCpu()
14-
15-
# Load machine model (from pymask)
16-
filename = ('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
17-
with open(filename, 'r') as fid:
18-
dct = json.load(fid)
19-
line = xt.Line.from_dict(dct['line'])
20-
line.build_tracker(_context=ctx)
10+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
2111

2212
# Attach a reference particle to the line
23-
line.particle_ref = xp.Particles(mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, x=1, y=3)
13+
line.set_particle_ref('proton', p0c=7e12, x=1, y=3)
2414

2515
# Built a set of three particles with different x coordinates
2616
particles = line.build_particles(

examples/particles_generation/002_halo.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import json
76
import numpy as np
87

98
import xpart as xp
@@ -13,13 +12,9 @@
1312
nemitt_x = 2.5e-6
1413
nemitt_y = 3e-6
1514

16-
# Load machine model (from pymask)
17-
filename = ('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
18-
with open(filename, 'r') as fid:
19-
input_data = json.load(fid)
20-
line = xt.Line.from_dict(input_data['line'])
21-
line.particle_ref = xp.Particles.from_dict(input_data['particle'])
22-
line.build_tracker()
15+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
16+
17+
line.set_particle_ref('proton', p0c=7e12)
2318

2419
# Horizontal plane: generate cut halo distribution
2520
(x_in_sigmas, px_in_sigmas, r_points, theta_points

examples/particles_generation/003_pencil.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import json
76
import numpy as np
87

98
import xpart as xp
@@ -13,13 +12,9 @@
1312
nemitt_x = 2.5e-6
1413
nemitt_y = 3e-6
1514

16-
# Load machine model (from pymask)
17-
filename = ('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
18-
with open(filename, 'r') as fid:
19-
input_data = json.load(fid)
20-
line=xt.Line.from_dict(input_data['line'])
21-
line.particle_ref = xp.Particles.from_dict(input_data['particle'])
22-
line.build_tracker()
15+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
16+
17+
line.set_particle_ref('proton', p0c=7e12)
2318

2419
# Horizontal plane: generate gaussian distribution in normalized coordinates
2520
x_in_sigmas, px_in_sigmas = xp.generate_2D_gaussian(num_particles)

examples/particles_generation/003a_pencil_on_collimator.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import json
76
import numpy as np
87

98
import xpart as xp
@@ -13,17 +12,13 @@
1312
nemitt_x = 2.5e-6
1413
nemitt_y = 3e-6
1514

16-
# Load machine model
17-
filename = ('../../../xtrack/test_data/hllhc15_noerrors_nobb/line_and_particle.json')
18-
with open(filename, 'r') as fid:
19-
input_data = json.load(fid)
20-
line=xt.Line.from_dict(input_data['line'])
21-
line.particle_ref = xp.Particles.from_dict(input_data['particle'])
22-
line.build_tracker()
15+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
16+
17+
line.set_particle_ref('proton', p0c=7e12)
2318

2419
# Location of the collimator
2520
at_element = 'tcp.d6l7.b1'
26-
at_s = line.line.get_s_position(at_element) + 1.
21+
at_s = line.get_s_position(at_element) + 1.
2722
y_cut = 3e-3 # position of the jaw
2823
pencil_dr_sigmas = 3 # width of the pencil
2924
side = '+' # side of the pencil

examples/particles_generation/003b_pencil_on_collimator_dispersion.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) CERN, 2021. #
44
# ######################################### #
55

6-
import json
76
import numpy as np
87

98
import xpart as xp
@@ -13,14 +12,9 @@
1312
nemitt_x = 2.5e-6
1413
nemitt_y = 3e-6
1514

16-
# Load machine model
17-
filename = ('../../../xtrack/test_data/hllhc15_noerrors_nobb/line_and_particle.json')
18-
line = xt.Line.from_json(filename)
19-
with open(filename, 'r') as fid:
20-
input_data = json.load(fid)
21-
line = xt.Line.from_dict(input_data['line'])
22-
line.particle_ref = xp.Particles.from_dict(input_data['particle'])
23-
line.build_tracker()
15+
line = xt.load('../../../xtrack/test_data/lhc_no_bb/line_and_particle.json')
16+
17+
line.set_particle_ref('proton', p0c=7e12)
2418

2519
# Location of the collimator
2620
at_element = 'tcp.6l3.b1' # High dispersion
@@ -54,7 +48,7 @@
5448
at_element=at_element, match_at_s=at_s)
5549

5650
# Drift to at_s position for checking
57-
drift_to_at_s = xt.Drift(length=at_s-line.line.get_s_position(at_element))
51+
drift_to_at_s = xt.Drift(length=at_s - line.get_s_position(at_element))
5852
drift_to_at_s.track(particles)
5953

6054
# Checks and plots

0 commit comments

Comments
 (0)