|
| 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_compensated_50_150_300_600_Hz_ripple_300k_turns_TRANSFER_FUNCTION' |
| 15 | +num_turns = 300_000 # longer run |
| 16 | +Qy = 26.19 |
| 17 | +Qx = 26.31 |
| 18 | + |
| 19 | +# Assume same emittances as Pb, but scaling from 28e8 as the SPS space charge limit |
| 20 | +# 28e8/3.94e8 = 7.1, so use this as scaling factor |
| 21 | + |
| 22 | +no_LEIR_inj = [2, 3, 4, 5, 6, 8] |
| 23 | +Nb_array = ['1.3e8', '1.75e8', '2.215e8', '2.93e8', '3.202e8', '3.94e8'] |
| 24 | +exn_array = ['0.73e-6', '0.89e-6', '1.11e-6', '1.4e-6', '1.75e-6', '2.1e-6'] |
| 25 | +eyn_array = ['0.48e-6', '0.63e-6', '0.74e-6', '0.85e-6', '1.05e-6', '1.175e-6'] |
| 26 | +run_files = ['sps_run_leir_inj_{}.py'.format(i+1) for i in range(len(no_LEIR_inj))] |
| 27 | + |
| 28 | +# Define script and folder names |
| 29 | +script_names = run_files.copy() |
| 30 | +folder_names = ['sps_no_leir_inj_{}'.format(no_LEIR_inj[i]) for i in range(len(no_LEIR_inj))] |
| 31 | +string_array = ['No. LEIR inj. = {}'.format(no_LEIR_inj[i]) for i in range(len(no_LEIR_inj))] |
| 32 | + |
| 33 | +# Generate the scripts to be submitted |
| 34 | +for i, run_file in enumerate(run_files): |
| 35 | + |
| 36 | + # Write run file for given tune |
| 37 | + print('Generating launch script {}\n'.format(run_file)) |
| 38 | + run_file = open(run_file, 'w') |
| 39 | + run_file.truncate(0) # remove existing content, if any |
| 40 | + run_file.write( |
| 41 | + '''import fma_ions |
| 42 | +import numpy as np |
| 43 | +output_dir = './' |
| 44 | +
|
| 45 | +n_turns = {} |
| 46 | +num_part = 20_000 |
| 47 | +
|
| 48 | +beamParams=fma_ions.BeamParameters_SPS() |
| 49 | +beamParams.Nb = {}*7.24399203 |
| 50 | +beamParams.exn = {} |
| 51 | +beamParams.eyn = {} |
| 52 | +
|
| 53 | +# Transfer function factors |
| 54 | +a_50 = 1.0 #1.7170 |
| 55 | +a_150 = 0.5098 |
| 56 | +a_300 = 0.2360 |
| 57 | +a_600 = 0.1095 |
| 58 | +
|
| 59 | +# Desired ripple frequencies and amplitudes - from DCCT measurements 2024-10-30 |
| 60 | +ripple_freqs = np.array([50.0, 150.0, 300.0, 600.0]) |
| 61 | +kqf_amplitudes = np.array([1.79381965522221e-07*a_50, 1.7917856960711038e-07*a_150, 1.717715125357188e-07*a_300, 1.0613897587376263e-07*a_600]) |
| 62 | +kqd_amplitudes = np.array([3.1433458408493135e-07*a_50, 4.125645646596158e-07*a_150, 2.6325770762187453e-07*a_300, 8.302889259074001e-08*a_600]) |
| 63 | +kqf_phases = np.array([2.5699456856082965, -1.2707524434033985, 1.1509405507521766, -2.3897351868985552]) |
| 64 | +kqd_phases = np.array([-1.6168418898711074, -1.5349070763197448, -2.145386063404577, 0.7431459693919794]) |
| 65 | +
|
| 66 | +# Tracking on GPU context |
| 67 | +sps = fma_ions.SPS_Flat_Bottom_Tracker(qx0={:.3f}, qy0={:.3f}, num_turns=n_turns, num_part=num_part) |
| 68 | +tbt = sps.track_SPS(ion_type='O', which_context='gpu', distribution_type='qgaussian', beamParams=beamParams, install_SC_on_line=True, add_beta_beat=True, |
| 69 | + add_non_linear_magnet_errors=True, apply_kinetic_IBS_kicks=True, ibs_step = 2000, add_tune_ripple=True, ripple_freqs = ripple_freqs, |
| 70 | + kqf_amplitudes = kqf_amplitudes, kqd_amplitudes = kqd_amplitudes, kqf_phases=kqf_phases, kqd_phases=kqd_phases, |
| 71 | + SC_adaptive_interval_during_tracking=100) |
| 72 | +tbt.to_json(output_dir) |
| 73 | + '''.format(num_turns, Nb_array[i], exn_array[i], eyn_array[i], Qx, Qy) |
| 74 | + ) |
| 75 | + run_file.close() |
| 76 | + |
| 77 | + |
| 78 | +# Instantiate the submitter class and launch the jobs |
| 79 | +sub = fma_ions.Submitter() |
| 80 | +master_job_name = '{:%Y_%m_%d__%H_%M_%S}_{}'.format(datetime.datetime.now(), master_name) |
| 81 | + |
| 82 | +# Launch the Python scripts in this folder |
| 83 | +for i, script in enumerate(script_names): |
| 84 | + file_name = os.path.join(dir_path, script) |
| 85 | + print(f"Submitting {file_name}") |
| 86 | + sub.submit_GPU(file_name, master_job_name=master_job_name, job_name=folder_names[i]) |
| 87 | +sub.copy_master_plot_script(folder_names, string_array) |
| 88 | +sub.copy_plot_script_emittances_for_scan(master_name, folder_names, scan_array_for_x_axis=Nb_array, |
| 89 | + label_for_x_axis='Injected Pb ions per bunch', |
| 90 | + extra_text_string='$Q_{x, y}$ = 26.31, 26.19 - q-Gaussian beam\\nAdaptive SC, ~10% $\\beta$-beat + non-linear magnet errors') |
| 91 | +''' |
| 92 | +# Old values, but from 2024-11-25 |
| 93 | +kqf_amplitudes = np.array([1.6384433351717334e-08*a_50, 2.1158318710898557e-07*a_150, 3.2779826135772383e-07*a_300, 4.7273849059164697e-07*a_600]) |
| 94 | +kqd_amplitudes = np.array([2.753093584240069e-07*a_50, 4.511100472630622e-07*a_150, 5.796354631307802e-07*a_300, 4.5487568431405856e-07*a_600]) |
| 95 | +kqf_phases = np.array([0.9192671763874849, 0.030176158557178895, 0.5596488397663701, 0.050511945653341016]) |
| 96 | +kqd_phases = np.array([0.9985112397758237, 3.003827454851132, 0.6369886405485959, -3.1126209931146547]) |
| 97 | +''' |
0 commit comments