-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'examples/monitors' into main
- Loading branch information
Showing
7 changed files
with
181 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
|
||
import xtrack as xt | ||
import xpart as xp | ||
import xobjects as xo | ||
|
||
context = xo.ContextCpu() | ||
|
||
with open('../../test_data/hllhc15_noerrors_nobb/line_and_particle.json') as f: | ||
dct = json.load(f) | ||
line = xt.Line.from_dict(dct['line']) | ||
line.particle_ref = xp.Particles.from_dict(dct['particle']) | ||
|
||
tracker = line.build_tracker() | ||
|
||
num_particles = 50 | ||
particles = xp.generate_matched_gaussian_bunch(tracker=tracker, | ||
num_particles=num_particles, | ||
nemitt_x=2.5e-6, | ||
nemitt_y=2.5e-6, | ||
sigma_z=9e-2) | ||
|
||
num_turns = 30 | ||
tracker.track(particles, num_turns=num_turns, | ||
turn_by_turn_monitor=True # enables all particles for all turns | ||
) | ||
# tracker.record_last_track contains the measured data. For example, | ||
# tracker.record_last_track.x contains the x coordinate for all particles | ||
# and all turns, e.g. tracker.record_last_track.x[3, 5] for the particle | ||
# having particle_id = 3 and for the turn number 5. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
|
||
import xtrack as xt | ||
import xpart as xp | ||
import xobjects as xo | ||
|
||
context = xo.ContextCpu() | ||
|
||
with open('../../test_data/hllhc15_noerrors_nobb/line_and_particle.json') as f: | ||
dct = json.load(f) | ||
line = xt.Line.from_dict(dct['line']) | ||
line.particle_ref = xp.Particles.from_dict(dct['particle']) | ||
|
||
tracker = line.build_tracker() | ||
|
||
num_particles = 50 | ||
particles = xp.generate_matched_gaussian_bunch(tracker=tracker, | ||
num_particles=num_particles, | ||
nemitt_x=2.5e-6, | ||
nemitt_y=2.5e-6, | ||
sigma_z=9e-2) | ||
|
||
num_turns = 30 | ||
monitor = xt.ParticlesMonitor(_context=context, | ||
start_at_turn=5, stop_at_turn=15, | ||
num_particles=num_particles) | ||
tracker.track(particles, num_turns=num_turns, | ||
turn_by_turn_monitor=monitor | ||
) | ||
# tracker.record_last_track contains the measured data. For example, | ||
# tracker.record_last_track.x contains the x coordinate for all particles | ||
# and the selected turns, e.g. tracker.record_last_track.x[3, 5] gives the | ||
# x coordinates for the particle having particle_id = 3 and for the fifth | ||
# recorded turn. The turn indeces that are recorded can be inspected in | ||
# tracker.record_last_track.at_turn |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
|
||
import xtrack as xt | ||
import xpart as xp | ||
import xobjects as xo | ||
|
||
context = xo.ContextCpu() | ||
|
||
with open('../../test_data/hllhc15_noerrors_nobb/line_and_particle.json') as f: | ||
dct = json.load(f) | ||
line = xt.Line.from_dict(dct['line']) | ||
line.particle_ref = xp.Particles.from_dict(dct['particle']) | ||
|
||
tracker = line.build_tracker() | ||
|
||
num_particles = 50 | ||
particles = xp.generate_matched_gaussian_bunch(tracker=tracker, | ||
num_particles=num_particles, | ||
nemitt_x=2.5e-6, | ||
nemitt_y=2.5e-6, | ||
sigma_z=9e-2) | ||
|
||
num_turns = 100 | ||
monitor = xt.ParticlesMonitor(_context=context, | ||
start_at_turn=5, stop_at_turn=10, | ||
n_repetitions=3, # <-- | ||
repetition_period=20, # <-- | ||
num_particles=num_particles) | ||
tracker.track(particles, num_turns=num_turns, | ||
turn_by_turn_monitor=monitor) | ||
|
||
# tracker.record_last_track contains the measured data. For all particles | ||
# variables the first index provides the frame index. | ||
# For example, tracker.record_last_track.x[0, :, :] contains the recorded | ||
# x position for the turns 5 to 10, tracker.record_last_track.x[1, :, :] | ||
# contains the recorded x position for the turns 25 to 30, etc. | ||
# The turn indeces that are recorded can be inspected in | ||
# tracker.record_last_track.at_turn. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
import xtrack as xt | ||
import xpart as xp | ||
import xobjects as xo | ||
|
||
context = xo.ContextCpu() | ||
|
||
with open('../../test_data/hllhc15_noerrors_nobb/line_and_particle.json') as f: | ||
dct = json.load(f) | ||
line = xt.Line.from_dict(dct['line']) | ||
line.particle_ref = xp.Particles.from_dict(dct['particle']) | ||
|
||
num_particles = 50 | ||
monitor_ip5 = xt.ParticlesMonitor(start_at_turn=5, stop_at_turn=15, | ||
num_particles=num_particles) | ||
monitor_ip8 = xt.ParticlesMonitor(start_at_turn=5, stop_at_turn=15, | ||
num_particles=num_particles) | ||
line.insert_element(index='ip5', element=monitor_ip5, name='mymon5') | ||
line.insert_element(index='ip8', element=monitor_ip8, name='mymon8') | ||
|
||
tracker = line.build_tracker() | ||
|
||
particles = xp.generate_matched_gaussian_bunch(tracker=tracker, | ||
num_particles=num_particles, | ||
nemitt_x=2.5e-6, | ||
nemitt_y=2.5e-6, | ||
sigma_z=9e-2) | ||
|
||
num_turns = 30 | ||
monitor = xt.ParticlesMonitor(_context=context, | ||
start_at_turn=5, stop_at_turn=15, | ||
num_particles=num_particles) | ||
tracker.track(particles, num_turns=num_turns) | ||
|
||
# monitor_ip5 contains the data recorded in before the element 'ip5', while | ||
# monitor_ip8 contains the data recorded in before the element 'ip8' | ||
# The element index at which the recording is made can be inspected in | ||
# monitor_ip5.at_element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
import xtrack as xt | ||
import xpart as xp | ||
import xobjects as xo | ||
|
||
context = xo.ContextCpu() | ||
|
||
with open('../../test_data/hllhc15_noerrors_nobb/line_and_particle.json') as f: | ||
dct = json.load(f) | ||
line = xt.Line.from_dict(dct['line']) | ||
line.particle_ref = xp.Particles.from_dict(dct['particle']) | ||
|
||
tracker = line.build_tracker() | ||
|
||
num_particles = 50 | ||
particles = xp.generate_matched_gaussian_bunch(tracker=tracker, | ||
num_particles=num_particles, | ||
nemitt_x=2.5e-6, | ||
nemitt_y=2.5e-6, | ||
sigma_z=9e-2) | ||
|
||
num_turns = 100 | ||
monitor = xt.ParticlesMonitor(_context=context, | ||
start_at_turn=5, stop_at_turn=10, | ||
n_repetitions=3, # <-- | ||
repetition_period=20, # <-- | ||
num_particles=num_particles) | ||
for iturn in range(num_turns): | ||
monitor.track(particles) | ||
tracker.track(particles) | ||
|
||
# monitor contains the measured data. For all particles | ||
# variables the first index provides the frame index. | ||
# For example, monitor.x[0, :, :] contains the recorded | ||
# x position for the turns 5 to 10, monitor.x[1, :, :] | ||
# contains the recorded x position for the turns 25 to 30, etc. | ||
# The turn indeces that are recorded can be inspected in | ||
# monitor.at_turn. |