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 = 'Q26_O_ions_bunch_intensity_scan_adaptive_sc_ibs_with_comp_50_150_300_600_Hz_ripple_130k_turns_TRANSFER_FUNCTION_INT_SCAN_2025_06_17_MD'
15+ num_turns = 130_000 # corresponds to about 3 s for SPS ions at flat bottom
16+ Qx = 26.31
17+ Qy = 26.25
18+
19+ # Use measured 2025-06-17 O8+ SPS values
20+ Nb_array = ['18.5e8' , '21.125e8' , '45.375e8' , '53e8' , '67.25e8' ]
21+ exn_array = ['0.63e-6' , '0.75e-6' , '1.62e-6' , '1.55e-6' , '1.74e-6' ]
22+ eyn_array = ['0.5e-6' , '0.66e-6' , '1.67e-6' , '1.68e-6' , '2.11e-6' ]
23+ run_files = ['sps_oxygen_Nb_scan_{}.py' .format (i + 1 ) for i in range (len (Nb_array ))]
24+
25+ # Define script and folder names
26+ script_names = run_files .copy ()
27+ folder_names = ['sps_oxygen_Nb_scan_{}' .format (i ) for i in range (len (Nb_array ))]
28+ string_array = ['SPS oxygen case = {}' .format (i ) for i in range (len (Nb_array ))]
29+
30+ # Generate the scripts to be submitted
31+ for i , run_file in enumerate (run_files ):
32+
33+ # Write run file for given tune
34+ print ('Generating launch script {}\n ' .format (run_file ))
35+ run_file = open (run_file , 'w' )
36+ run_file .truncate (0 ) # remove existing content, if any
37+ run_file .write (
38+ '''import fma_ions
39+ import numpy as np
40+ output_dir = './'
41+
42+ n_turns = {}
43+ num_part = 20_000
44+
45+ beamParams=fma_ions.BeamParameters_SPS()
46+ beamParams.Nb = {}
47+ beamParams.exn = {}
48+ beamParams.eyn = {}
49+
50+ # Transfer function factors
51+ a_50 = 1.0 #1.7170
52+ a_150 = 0.5098
53+ a_300 = 0.2360
54+ a_600 = 0.1095
55+
56+ # Desired ripple frequencies and amplitudes - from DCCT measurements 2024-10-30
57+ ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0])
58+ kqf_amplitudes = np.array([1.79381965522221e-07*a_50, 1.7917856960711038e-07*a_150, 1.717715125357188e-07*a_300, 1.0613897587376263e-07*a_600])
59+ kqd_amplitudes = np.array([3.1433458408493135e-07*a_50, 4.125645646596158e-07*a_150, 2.6325770762187453e-07*a_300, 8.302889259074001e-08*a_600])
60+ kqf_phases = np.array([2.5699456856082965, -1.2707524434033985, 1.1509405507521766, -2.3897351868985552])
61+ kqd_phases = np.array([-1.6168418898711074, -1.5349070763197448, -2.145386063404577, 0.7431459693919794])
62+
63+ # Tracking on GPU context
64+ sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
65+ tbt = sps.track_SPS(ion_type='O', which_context='gpu', distribution_type='qgaussian', beamParams=beamParams, install_SC_on_line=True, add_beta_beat=True,
66+ add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True, ripple_freqs = ripple_freqs,
67+ kqf_amplitudes = kqf_amplitudes, kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases,
68+ SC_adaptive_interval_during_tracking=100)
69+ tbt.to_json(output_dir)
70+ ''' .format (num_turns , Nb_array [i ], exn_array [i ], eyn_array [i ], Qx , Qy )
71+ )
72+ run_file .close ()
73+
74+
75+ # Instantiate the submitter class and launch the jobs
76+ sub = fma_ions .Submitter ()
77+ master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}' .format (datetime .datetime .now (), master_name )
78+
79+ # Launch the Python scripts in this folder
80+ for i , script in enumerate (script_names ):
81+ file_name = os .path .join (dir_path , script )
82+ print (f"Submitting { file_name } " )
83+ sub .submit_GPU (file_name , master_job_name = master_job_name , job_name = folder_names [i ])
84+ sub .copy_master_plot_script (folder_names , string_array )
85+ sub .copy_plot_script_emittances_for_scan (master_name , folder_names , scan_array_for_x_axis = Nb_array ,
86+ label_for_x_axis = 'Injected Pb ions per bunch' ,
87+ 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