Skip to content

Commit 0483f7c

Browse files
committed
Qy scan for oxygen
1 parent 28295b4 commit 0483f7c

File tree

2 files changed

+168
-0
lines changed

2 files changed

+168
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Launcher script to HTCondor for GPU - generate python scripts for SPS oxygen Qy scan
3+
"""
4+
import fma_ions
5+
import os
6+
import pathlib
7+
import numpy as np
8+
import datetime
9+
10+
# Find path of script being run
11+
dir_path = pathlib.Path(__file__).parent.absolute()
12+
13+
# Define run files and which parameters to change
14+
master_name = 'Qy_scan_oxygen_ibs_50_150_300_600_Hz_ripple_adaptive_sc_WITH_TRANSFER_FUNCTION_130k_turns'
15+
num_turns = 130_000 # corresponds to 3s for SPS ions at flat bottom
16+
Qx = 26.31
17+
Qy_range = np.arange(26.12, 26.27, 0.01)
18+
run_files = ['sps_oxygen_run_{}_tbt_qx_26dot31.py'.format(i+1) for i in range(len(Qy_range))]
19+
20+
# Define script and folder names
21+
script_names = run_files.copy()
22+
folder_names = ['sps_Qx_{:.2f}_Qy_{:.2f}'.format(Qx, Qy_range[i]) for i in range(len(Qy_range))]
23+
string_array = ['Qy = {:.2f}, Qx = {:.2f} space charge'.format(Qy_range[i], Qx) for i in range(len(Qy_range))]
24+
25+
# Generate the scripts to be submitted
26+
for i, run_file in enumerate(run_files):
27+
28+
# Write run file for given tune
29+
print('Generating launch script {}\n'.format(run_file))
30+
run_file = open(run_file, 'w')
31+
run_file.truncate(0) # remove existing content, if any
32+
run_file.write(
33+
'''import fma_ions
34+
import numpy as np
35+
output_dir = './'
36+
37+
n_turns = {}
38+
num_part = 20_000
39+
40+
beamParams=fma_ions.BeamParameters_SPS()
41+
beamParams.Nb = 75.2e8
42+
beamParams.exn = 1.74e-6
43+
beamParams.eyn = 2.11e-6
44+
45+
# Transfer function factors
46+
a_50 = 1.0 #1.7170
47+
a_150 = 0.5098
48+
a_300 = 0.2360
49+
a_600 = 0.1095
50+
51+
# Desired ripple frequencies and amplitudes
52+
ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0])
53+
kqf_amplitudes = np.array([1.6384433351717334e-08*a_50, 2.1158318710898557e-07*a_150, 3.2779826135772383e-07*a_300, 4.7273849059164697e-07*a_600])
54+
kqd_amplitudes = np.array([2.753093584240069e-07*a_50, 4.511100472630622e-07*a_150, 5.796354631307802e-07*a_300, 4.5487568431405856e-07*a_600])
55+
kqf_phases = np.array([0.9192671763874849, 0.030176158557178895, 0.5596488397663701, 0.050511945653341016])
56+
kqd_phases = np.array([0.9985112397758237, 3.003827454851132, 0.6369886405485959, -3.1126209931146547])
57+
58+
59+
# Tracking on GPU context
60+
sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
61+
tbt = sps.track_SPS(ion_type='O', beamParams=beamParams, which_context='gpu', distribution_type='qgaussian', install_SC_on_line=True, add_beta_beat=True,
62+
add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000,
63+
add_tune_ripple=True, ripple_freqs = ripple_freqs, kqf_amplitudes = kqf_amplitudes,
64+
kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases,
65+
SC_adaptive_interval_during_tracking=20)
66+
tbt.to_json(output_dir)
67+
'''.format(num_turns, Qx, Qy_range[i])
68+
)
69+
run_file.close()
70+
71+
72+
# Instantiate the submitter class and launch the jobs
73+
sub = fma_ions.Submitter()
74+
master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}'.format(datetime.datetime.now(), master_name)
75+
76+
# Launch the Python scripts in this folder
77+
for i, script in enumerate(script_names):
78+
file_name = os.path.join(dir_path, script)
79+
print(f"Submitting {file_name}")
80+
sub.submit_GPU(file_name, master_job_name=master_job_name, job_name=folder_names[i])
81+
sub.copy_master_plot_script(folder_names, string_array)
82+
sub.copy_plot_script_emittances_for_scan(master_name, folder_names, scan_array_for_x_axis=Qy_range,
83+
label_for_x_axis='Injected Pb ions per bunch',
84+
extra_text_string='$Q_{x}$ = 26.31 - q-Gaussian beam\\nAdaptive SC, ~10% $\\beta$-beat + non-linear magnet errors')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Launcher script to HTCondor for GPU - generate python scripts for SPS oxygen Qy scan
3+
"""
4+
import fma_ions
5+
import os
6+
import pathlib
7+
import numpy as np
8+
import datetime
9+
10+
# Find path of script being run
11+
dir_path = pathlib.Path(__file__).parent.absolute()
12+
13+
# Define run files and which parameters to change
14+
master_name = 'Qy_scan_oxygen_ibs_50_150_300_600_Hz_ripple_adaptive_sc_WITH_TRANSFER_FUNCTION_300k_turns_long'
15+
num_turns = 300_000 # corresponds to 9s for SPS ions at flat bottom
16+
Qx = 26.31
17+
Qy_range = np.arange(26.12, 26.27, 0.01)
18+
run_files = ['sps_oxygen_run_{}_tbt_qx_26dot31.py'.format(i+1) for i in range(len(Qy_range))]
19+
20+
# Define script and folder names
21+
script_names = run_files.copy()
22+
folder_names = ['sps_Qx_{:.2f}_Qy_{:.2f}'.format(Qx, Qy_range[i]) for i in range(len(Qy_range))]
23+
string_array = ['Qy = {:.2f}, Qx = {:.2f} space charge'.format(Qy_range[i], Qx) for i in range(len(Qy_range))]
24+
25+
# Generate the scripts to be submitted
26+
for i, run_file in enumerate(run_files):
27+
28+
# Write run file for given tune
29+
print('Generating launch script {}\n'.format(run_file))
30+
run_file = open(run_file, 'w')
31+
run_file.truncate(0) # remove existing content, if any
32+
run_file.write(
33+
'''import fma_ions
34+
import numpy as np
35+
output_dir = './'
36+
37+
n_turns = {}
38+
num_part = 20_000
39+
40+
beamParams=fma_ions.BeamParameters_SPS()
41+
beamParams.Nb = 75.2e8
42+
beamParams.exn = 1.74e-6
43+
beamParams.eyn = 2.11e-6
44+
45+
# Transfer function factors
46+
a_50 = 1.0 #1.7170
47+
a_150 = 0.5098
48+
a_300 = 0.2360
49+
a_600 = 0.1095
50+
51+
# Desired ripple frequencies and amplitudes
52+
ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0])
53+
kqf_amplitudes = np.array([1.6384433351717334e-08*a_50, 2.1158318710898557e-07*a_150, 3.2779826135772383e-07*a_300, 4.7273849059164697e-07*a_600])
54+
kqd_amplitudes = np.array([2.753093584240069e-07*a_50, 4.511100472630622e-07*a_150, 5.796354631307802e-07*a_300, 4.5487568431405856e-07*a_600])
55+
kqf_phases = np.array([0.9192671763874849, 0.030176158557178895, 0.5596488397663701, 0.050511945653341016])
56+
kqd_phases = np.array([0.9985112397758237, 3.003827454851132, 0.6369886405485959, -3.1126209931146547])
57+
58+
59+
# Tracking on GPU context
60+
sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
61+
tbt = sps.track_SPS(ion_type='O', beamParams=beamParams, which_context='gpu', distribution_type='qgaussian', install_SC_on_line=True, add_beta_beat=True,
62+
add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000,
63+
add_tune_ripple=True, ripple_freqs = ripple_freqs, kqf_amplitudes = kqf_amplitudes,
64+
kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases,
65+
SC_adaptive_interval_during_tracking=20)
66+
tbt.to_json(output_dir)
67+
'''.format(num_turns, Qx, Qy_range[i])
68+
)
69+
run_file.close()
70+
71+
72+
# Instantiate the submitter class and launch the jobs
73+
sub = fma_ions.Submitter()
74+
master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}'.format(datetime.datetime.now(), master_name)
75+
76+
# Launch the Python scripts in this folder
77+
for i, script in enumerate(script_names):
78+
file_name = os.path.join(dir_path, script)
79+
print(f"Submitting {file_name}")
80+
sub.submit_GPU(file_name, master_job_name=master_job_name, job_name=folder_names[i])
81+
sub.copy_master_plot_script(folder_names, string_array)
82+
sub.copy_plot_script_emittances_for_scan(master_name, folder_names, scan_array_for_x_axis=Qy_range,
83+
label_for_x_axis='Injected Pb ions per bunch',
84+
extra_text_string='$Q_{x}$ = 26.31 - q-Gaussian beam\\nAdaptive SC, ~10% $\\beta$-beat + non-linear magnet errors')

0 commit comments

Comments
 (0)