Skip to content

Commit 78205df

Browse files
committed
also real ex
1 parent 2b78bc0 commit 78205df

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"""
2+
Launcher script to HTCondor for GPU - generate python scripts for tune 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 = 'SPS_O_ions_Nb_scan_adaptive_sc_ibs_with_comp_50_150_300_600_Hz_ripple_476k_turns_2025_07_03'
15+
num_turns = 476_000
16+
Qx = 26.31
17+
Qy = 26.25
18+
19+
# Measured values from 2025-07-03 MD, reduce emittances by 10% to account for delayed measurement at inj.
20+
exn0 = 0.9*np.array([1.28044905, 1.21522662, 1.09623646, 1.09909263, 1.28992405]) # too big? Maybe assume same as eyn?
21+
eyn0 = 0.9*np.array([0.73679743, 0.84760539, 0.93580759, 1.00084611, 1.20491472])
22+
Nb0 = np.array([16.58413887, 17.75226021, 21.62930679, 26.4480648 , 32.95989609])
23+
24+
# Use measured 2025-06-17 O8+ SPS values
25+
Nb_array = ['{:.2f}e8'.format(Nb) for Nb in Nb0]
26+
exn_array = ['{:.2f}e-6'.format(exn) for exn in exn0]
27+
eyn_array = ['{:.2f}e-6'.format(eyn) for eyn in eyn0]
28+
run_files = ['sps_oxygen_Nb_scan_{}_longer_ex.py'.format(i+1) for i in range(len(Nb_array))]
29+
30+
# Define script and folder names
31+
script_names = run_files.copy()
32+
folder_names = ['sps_oxygen_Nb_scan_{}'.format(i) for i in range(len(Nb_array))]
33+
string_array = ['SPS oxygen case = {}'.format(i) for i in range(len(Nb_array))]
34+
35+
# Generate the scripts to be submitted
36+
for i, run_file in enumerate(run_files):
37+
38+
# Write run file for given tune
39+
print('Generating launch script {}\n'.format(run_file))
40+
run_file = open(run_file, 'w')
41+
run_file.truncate(0) # remove existing content, if any
42+
run_file.write(
43+
'''import fma_ions
44+
import numpy as np
45+
output_dir = './'
46+
47+
n_turns = {}
48+
num_part = 20_000
49+
50+
beamParams=fma_ions.BeamParameters_SPS()
51+
beamParams.Nb = {}
52+
beamParams.exn = {}
53+
beamParams.eyn = {}
54+
55+
# Transfer function factors
56+
a_50 = 1.0 #1.7170
57+
a_150 = 0.5098
58+
a_300 = 0.2360
59+
a_600 = 0.1095
60+
61+
# Desired ripple frequencies and amplitudes - from DCCT measurements 2024-10-30
62+
ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0])
63+
kqf_amplitudes = np.array([1.79381965522221e-07*a_50, 1.7917856960711038e-07*a_150, 1.717715125357188e-07*a_300, 1.0613897587376263e-07*a_600])
64+
kqd_amplitudes = np.array([3.1433458408493135e-07*a_50, 4.125645646596158e-07*a_150, 2.6325770762187453e-07*a_300, 8.302889259074001e-08*a_600])
65+
kqf_phases = np.array([2.5699456856082965, -1.2707524434033985, 1.1509405507521766, -2.3897351868985552])
66+
kqd_phases = np.array([-1.6168418898711074, -1.5349070763197448, -2.145386063404577, 0.7431459693919794])
67+
68+
# Tracking on GPU context
69+
sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
70+
tbt = sps.track_SPS(ion_type='O', which_context='gpu', distribution_type='qgaussian', beamParams=beamParams, install_SC_on_line=True, add_beta_beat=True,
71+
add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True, ripple_freqs = ripple_freqs,
72+
kqf_amplitudes = kqf_amplitudes, kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases,
73+
SC_adaptive_interval_during_tracking=100)
74+
tbt.to_json(output_dir)
75+
'''.format(num_turns, Nb_array[i], exn_array[i], eyn_array[i], Qx, Qy)
76+
)
77+
run_file.close()
78+
79+
80+
# Instantiate the submitter class and launch the jobs
81+
sub = fma_ions.Submitter()
82+
master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}'.format(datetime.datetime.now(), master_name)
83+
84+
# Launch the Python scripts in this folder
85+
for i, script in enumerate(script_names):
86+
file_name = os.path.join(dir_path, script)
87+
print(f"Submitting {file_name}")
88+
sub.submit_GPU(file_name, master_job_name=master_job_name, job_name=folder_names[i])
89+
sub.copy_master_plot_script(folder_names, string_array)
90+
sub.copy_plot_script_emittances_for_scan(master_name, folder_names, scan_array_for_x_axis=Nb_array,
91+
label_for_x_axis='Injected Pb ions per bunch',
92+
extra_text_string='$Q_{x, y}$ = 26.31, 26.25 - q-Gaussian beam\\nAdaptive SC, ~10% $\\beta$-beat + non-linear magnet errors')

0 commit comments

Comments
 (0)