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_oxygen_ions_artificial_50Hz_amplitude_scan_130k_turns_adaptive_SC'
15+ num_turns = 130_000
16+ Qy = 26.25
17+ Qx = 26.31
18+ k_amp_array = np .array ([1e-6 , 2e-6 , 3e-6 , 4e-6 , 5e-6 , 6e-6 , 7e-6 , 8e-6 ])
19+
20+ run_files = ['sps_run_artificial_50hz_amp_{}_tbt_ripple_scan_short.py' .format (i + 1 ) for i in range (len (k_amp_array ))]
21+
22+ # Define script and folder names
23+ script_names = run_files .copy ()
24+ folder_names = ['sps_artificial_50hz_amp_{}' .format (k_amp_array [i ]) for i in range (len (k_amp_array ))]
25+ string_array = ['Summed norm. FFT 50 Hz amplitude = {}' .format (k_amp_array [i ]) for i in range (len (k_amp_array ))]
26+
27+ # Generate the scripts to be submitted
28+ for i , run_file in enumerate (run_files ):
29+
30+ # Write run file for given tune
31+ print ('Generating launch script {}\n ' .format (run_file ))
32+ run_file = open (run_file , 'w' )
33+ run_file .truncate (0 ) # remove existing content, if any
34+ run_file .write (
35+ '''import fma_ions
36+ import numpy as np
37+ output_dir = './'
38+
39+ n_turns = {}
40+ num_part = 20_000
41+
42+ beamParams=fma_ions.BeamParameters_SPS()
43+ beamParams.Nb = 78e8
44+ beamParams.exn = 1.74e-6
45+ beamParams.eyn = 2.11e-6
46+
47+ # Tracking on GPU context
48+ sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
49+ tbt = sps.track_SPS(ion_type='O', which_context='gpu', distribution_type='qgaussian', beamParams=beamParams, install_SC_on_line=True, add_beta_beat=True, add_non_linear_magnet_errors=True,
50+ apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True,
51+ kqf_amplitudes = np.array([{}]), kqd_amplitudes = np.array([{}]), SC_adaptive_interval_during_tracking=20)
52+ tbt.to_json(output_dir)
53+ ''' .format (num_turns , Qx , Qy , k_amp_array [i ], 1e-7 )
54+ )
55+ run_file .close ()
56+
57+
58+ # Instantiate the submitter class and launch the jobs
59+ sub = fma_ions .Submitter ()
60+ master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}' .format (datetime .datetime .now (), master_name )
61+
62+ # Launch the Python scripts in this folder
63+ for i , script in enumerate (script_names ):
64+ file_name = os .path .join (dir_path , script )
65+ print (f"Submitting { file_name } " )
66+ sub .submit_GPU (file_name , master_job_name = master_job_name , job_name = folder_names [i ])
67+ sub .copy_master_plot_script (folder_names , string_array )
68+ sub .copy_plot_script_emittances_for_scan (master_name , folder_names , scan_array_for_x_axis = k_amp_array ,
69+ label_for_x_axis = 'Summed 50 Hz norm. FFT noise amplitude' ,
70+ extra_text_string = '$Q_{x, y}$ = 26.31, 26.19 - q-Gaussian beam\n Adaptive SC, IBS, 15% $\\ beta$-beat + non-linear magnet errors' )
0 commit comments