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_50Hz_amplitude_scan_130k_turns'
15+ num_turns = 130_000
16+ Qx = 26.31
17+ Qy = 26.25
18+ noise_amp = np .array ([5 , 23 , 56 , 79 , 105 , 132.8 ])
19+
20+ run_files = ['sps_run_50hz_amp_{}_tbt_ripple_130k.py' .format (i + 1 ) for i in range (len (noise_amp ))]
21+
22+ # Define script and folder names
23+ script_names = run_files .copy ()
24+ folder_names = ['sps_50hz_amp_{:.2f}' .format (noise_amp [i ]) for i in range (len (noise_amp ))]
25+ string_array = ['Summed norm. FFT 50 Hz amplitude = {:.2f}' .format (noise_amp [i ]) for i in range (len (noise_amp ))]
26+
27+ # Define arrays with noise levels and components
28+ kqd_amplitudes_array = ['np.array([9.723021321406122e-08, 2.3745188570956088e-07, 2.635005955653469e-07, 2.576444444457593e-07])' ,
29+ 'np.array([3.9812456975596433e-07, 2.2934266041829687e-07, 3.0684040552841907e-07, 4.282823340417963e-07])' ,
30+ 'np.array([1.1304820191071485e-06, 1.932807549565041e-07, 1.785663243936142e-07, 2.2877348015981624e-08])' ,
31+ 'np.array([1.6389600432376028e-06, 2.5543189963173063e-07, 2.6373035666438227e-07, 3.858885406771151e-07])' ,
32+ 'np.array([2.1225348518782994e-06, 1.6082104536963016e-07, 3.38113714803967e-08, 2.7701780425104516e-08])' ,
33+ 'np.array([2.7151802441949258e-06, 1.5517436224854464e-07, 2.835248658072942e-08, 2.2494477391887813e-08])' ]
34+
35+ kqf_amplitudes_array = ['np.array([1.120060346693208e-07, 2.205204907568259e-07, 3.0521849225806363e-07, 2.747771361555351e-07])' ,
36+ 'np.array([5.696599032489758e-07, 2.0930548316755448e-07, 3.36147508050999e-07, 4.649008644719288e-07])' ,
37+ 'np.array([1.196421521854063e-06, 1.929192734451135e-07, 2.0213194318330352e-07, 2.7282455405952533e-08])' ,
38+ 'np.array([1.6357727190552396e-06, 2.1367992530940683e-07, 3.4807700899364136e-07, 3.98198835682706e-07])' ,
39+ 'np.array([2.221944441771484e-06, 1.2213288869133976e-07, 1.9126094485955036e-08, 6.1088640812556605e-09])' ,
40+ 'np.array([2.7695612061506836e-06, 1.3427566614154784e-07, 3.6387920232527904e-08, 1.4197014230887817e-08])' ]
41+
42+ kqd_phases_array = ['np.array([1.145213, 1.7562652, -1.3936949, 1.5295615])' ,
43+ 'np.array([-1.5430037, -2.9268184, 1.636692, -2.0278132])' ,
44+ 'np.array([1.9029742, -2.7743878, 0.6021359, 1.5541494])' ,
45+ 'np.array([2.9723594, 2.4459786, 2.7609522, 2.6171744])' ,
46+ 'np.array([-3.1252482, -1.628448, -1.258592, -1.878203])' ,
47+ 'np.array([1.1344357, -1.6943372, 2.9972126, -1.3131486])' ]
48+
49+ kqf_phases_array = ['np.array([-2.2178884, -2.043975, 1.6096314, -2.003183])' ,
50+ 'np.array([1.6630147, -1.3794123, -1.2727182, 0.08756675])' ,
51+ 'np.array([0.41851026, 0.7496304, 1.8946044, -1.2702432])' ,
52+ 'np.array([0.21719944, -1.7445294, 0.08148171, 0.14667067])' ,
53+ 'np.array([-0.20396788, 0.5095066, -2.0499842, 1.3687758])' ,
54+ 'np.array([2.5333304, -3.0855007, 1.2785302, 1.9509202])' ]
55+
56+
57+
58+
59+ # Generate the scripts to be submitted
60+ for i , run_file in enumerate (run_files ):
61+
62+ # Write run file for given tune
63+ print ('Generating launch script {}\n ' .format (run_file ))
64+ run_file = open (run_file , 'w' )
65+ run_file .truncate (0 ) # remove existing content, if any
66+ run_file .write (
67+ '''import fma_ions
68+ import numpy as np
69+ output_dir = './'
70+
71+ n_turns = {}
72+ num_part = 20_000
73+
74+ # Desired ripple frequencies and amplitudes
75+ ripple_freqs = np.array([50., 150., 300., 600.])
76+ kqd_amplitudes = {}
77+ kqf_amplitudes = {}
78+ kqd_phases = {}
79+ kqf_phases = {}
80+
81+ beamParams=fma_ions.BeamParameters_SPS()
82+ beamParams.Nb = 78e8
83+ beamParams.exn = 1.74e-6
84+ beamParams.eyn = 2.11e-6
85+
86+ # Tracking on GPU context
87+ sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part)
88+ 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,
89+ apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True, ripple_freqs = ripple_freqs,
90+ kqf_amplitudes = kqf_amplitudes, kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases, SC_adaptive_interval_during_tracking=100)
91+ tbt.to_json(output_dir)
92+ ''' .format (num_turns , kqd_amplitudes_array [i ], kqf_amplitudes_array [i ],
93+ kqd_phases_array [i ], kqf_phases_array [i ], Qx , Qy )
94+ )
95+ run_file .close ()
96+
97+
98+ # Instantiate the submitter class and launch the jobs
99+ sub = fma_ions .Submitter ()
100+ master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}' .format (datetime .datetime .now (), master_name )
101+
102+ # Launch the Python scripts in this folder
103+ for i , script in enumerate (script_names ):
104+ file_name = os .path .join (dir_path , script )
105+ print (f"Submitting { file_name } " )
106+ sub .submit_GPU (file_name , master_job_name = master_job_name , job_name = folder_names [i ])
107+ sub .copy_master_plot_script (folder_names , string_array )
108+ sub .copy_plot_script_emittances_for_scan (master_name , folder_names , scan_array_for_x_axis = noise_amp ,
109+ label_for_x_axis = 'Summed 50 Hz norm. FFT noise amplitude' ,
110+ extra_text_string = '$Q_{x, y}$ = 26.31, 26.19 - q-Gaussian beam\n Frozen SC, IBS, 15% $\\ beta$-beat + non-linear magnet errors' )
0 commit comments