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