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