def apply_optics(mad, optics_file): pm.make_links(force=True, links_dict={ 'optics.madx': 'optics_runIII/RunIII_dev/2022_V1/PROTON/' + optics_file }) mad.call('optics.madx')
def build_sequence(mad, beam): slicefactor = 2 pm.make_links(force=True, links_dict={ 'optics_indep_macros.madx': 'tools/optics_indep_macros.madx', 'macro.madx': ('/afs/cern.ch/user/s/sterbini/public/' 'tracking_tools/tools/macro.madx'), 'optics_runII': '/afs/cern.ch/eng/lhc/optics/runII', 'optics_runIII': '/afs/cern.ch/eng/lhc/optics/runIII', }) mylhcbeam = int(beam) mad.input('ver_lhc_run = 3') mad.input(f'mylhcbeam = {beam}') mad.input('option, -echo,warn, -info;') # optics dependent macros mad.call('macro.madx') # optics independent macros mad.call('optics_indep_macros.madx') assert mylhcbeam in [1, 2, 4], "Invalid mylhcbeam (it should be in [1, 2, 4])" if mylhcbeam in [1, 2]: mad.call('optics_runII/2018/lhc_as-built.seq') else: mad.call('optics_runII/2018/lhcb4_as-built.seq') # New IR7 MQW layout and cabling mad.call('optics_runIII/RunIII_dev/IR7-Run3seqedit.madx') # Makethin part if slicefactor > 0: # the variable in the macro is slicefactor mad.input(f'slicefactor={slicefactor};') mad.call('optics_runII/2018/toolkit/myslice.madx') mad.beam() for my_sequence in ['lhcb1', 'lhcb2']: if my_sequence in list(mad.sequence): mad.input( f'use, sequence={my_sequence}; makethin, sequence={my_sequence}, style=teapot, makedipedge=false;' ) else: warnings.warn('The sequences are not thin!') # Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors) for my_sequence in ['lhcb1', 'lhcb2']: if my_sequence in list(mad.sequence): mad.input( f'seqedit, sequence={my_sequence}; flatten; cycle, start=IP3; flatten; endedit;' )
def build_sequence(mad, beam, configuration): optics_version = configuration['optics_version'] # Select beam mad.input(f'mylhcbeam = {beam}') # Make link to optics toolkit pm.make_links( { 'optics_toolkit': f'optics_repository/HLLHCV{optics_version}/toolkit' }, force=True) mad.input(''' ! Specify machine version ver_lhc_run = 0; ''' f'''ver_hllhc_optics = {optics_version};''' f''' ! Get the toolkit call,file= "optics_repository/HLLHCV{optics_version}/toolkit/macro.madx"; ''' ''' ! Build sequence option, -echo,-warn,-info; if (mylhcbeam==4){ call,file="optics_repository/runIII/lhcb4.seq"; } else { call,file="optics_repository/runIII/lhc.seq"; }; option, -echo, warn,-info; ''' f''' !Install HL-LHC call, file= "optics_repository/HLLHCV{optics_version}/hllhc_sequence.madx"; ''' ''' ! Slice nominal sequence exec, myslice; ! Install placeholder elements for errors (set to zero) call, file="errors/HL-LHC/install_MQXF_fringenl.madx"; ! adding fringe place holder call, file="errors/HL-LHC/install_MCBXFAB_errors.madx"; ! adding D1 corrector placeholders in IR1/5 (for errors) call, file="errors/HL-LHC/install_MCBRD_errors.madx"; ! adding D2 corrector placeholders in IR1/5 (for errors) call, file="errors/HL-LHC/install_NLC_errors.madx"; ! adding non-linear corrector placeholders in IR1/5 (for errors) !Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors) if (mylhcbeam<3){ seqedit, sequence=lhcb1; flatten; cycle, start=IP3; flatten; endedit; }; seqedit, sequence=lhcb2; flatten; cycle, start=IP3; flatten; endedit; ''')
def build_sequence(mad, beam): from config import configuration optics_path = configuration['optics_path'] # Select beam mad.input(f'mylhcbeam = {beam}') # Make link to optics toolkit pm.make_links({'optics_toolkit': f'{optics_path}/toolkit'}, force=True) mad.input(''' ! Specify machine version ver_lhc_run = 0; ver_hllhc_optics = 1.4; ! Get the toolkit call, file="%s/toolkit/macro.madx"; ! Build sequence option, -echo,-warn,-info; if (mylhcbeam==4){ call,file="/afs/cern.ch/eng/lhc/optics/runIII/lhcb4.seq"; } else { call,file="/afs/cern.ch/eng/lhc/optics/runIII/lhc.seq"; }; option, -echo, warn,-info; !Install HL-LHC call, file="%s/hllhc_sequence.madx"; ! Slice nominal sequence exec, myslice; ! Install placeholder elements for errors (set to zero) call, file="errors/HL-LHC/install_MQXF_fringenl.madx"; ! adding fringe place holder call, file="errors/HL-LHC/install_MCBXFAB_errors.madx"; ! adding D1 corrector placeholders in IR1/5 (for errors) call, file="errors/HL-LHC/install_MCBRD_errors.madx"; ! adding D2 corrector placeholders in IR1/5 (for errors) !Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors) if (mylhcbeam<3){ seqedit, sequence=lhcb1; flatten; cycle, start=IP3; flatten; endedit; }; seqedit, sequence=lhcb2; flatten; cycle, start=IP3; flatten; endedit; ''' % (optics_path, optics_path))
# Select mode #mode = 'b1_without_bb' mode = 'b1_with_bb' #mode = 'b1_with_bb_legacy_macros' #mode = 'b4_without_bb' #mode = 'b4_from_b2_without_bb' mode = 'b4_from_b2_with_bb' # Tolarances for checks [ip1, ip2, ip5, ip8] tol_beta = [1e-3, 10e-2, 1e-3, 1e-2] tol_sep = [1e-6, 1e-6, 1e-6, 1e-6] pm.make_links(force=True, links_dict={ 'tracking_tools': '/afs/cern.ch/eng/tracking-tools', 'modules': 'tracking_tools/modules', 'tools': 'tracking_tools/tools', 'beambeam_macros': 'tracking_tools/beambeam_macros', 'errors': 'tracking_tools/errors' }) optics_file = 'opticsfile.29' check_betas_at_ips = True check_separations_at_ips = True save_intermediate_twiss = True # Check and load parameters pm.checks_on_parameter_dict(mask_parameters) # Define configuration (
def build_sequence(mad, beam): slicefactor = 8 # for production put slicefactor=8 pm.make_links( force=True, links_dict={ 'optics_indep_macros.madx': 'tools/optics_indep_macros.madx', 'macro.madx': ('/afs/cern.ch/eng/lhc/optics/runII/2018/toolkit/macro.madx'), 'optics_runII': '/afs/cern.ch/eng/lhc/optics/runII', 'optics_runIII': '/afs/cern.ch/eng/lhc/optics/runIII', }) mylhcbeam = int(beam) mad.input('ver_lhc_run = 3') mad.input(f'mylhcbeam = {beam}') mad.input('option, -echo,warn, -info;') # optics dependent macros mad.call('macro.madx') mad.input(''' crossing_save: macro = { on_x1_aux=on_x1;on_sep1_aux=on_sep1;on_a1_aux=on_a1;on_o1_aux=on_o1; on_x2_aux=on_x2;on_sep2_aux=on_sep2;on_a2_aux=on_a2;on_o2_aux=on_o2; on_oe2_aux=on_oe2; on_x5_aux=on_x5;on_sep5_aux=on_sep5;on_a5_aux=on_a5;on_o5_aux=on_o5; on_x8_aux=on_x8;on_sep8_aux=on_sep8;on_a8_aux=on_a8;on_o8_aux=on_o8; on_x2h_aux=on_x2h; on_x2v_aux=on_x2v; on_sep2h_aux=on_sep2h; on_sep2v_aux=on_sep2v; on_x8h_aux=on_x8h; on_x8v_aux=on_x8v; on_sep8h_aux=on_sep8h; on_sep8v_aux=on_sep8v; on_disp_aux=on_disp; on_alice_aux=on_alice; on_lhcb_aux=on_lhcb; }; crossing_disable: macro={ on_x1=0;on_sep1=0;on_a1=0;on_o1=0; on_x2=0;on_sep2=0;on_a2=0;on_o2=0;on_oe2=0; on_x5=0;on_sep5=0;on_a5=0;on_o5=0; on_x8=0;on_sep8=0;on_a8=0;on_o8=0; on_x2h=0; on_x2v=0; on_sep2h=0; on_sep2v=0; on_x8h=0; on_x8v=0; on_sep8h=0; on_sep8v=0; on_disp=0; on_alice=0; on_lhcb=0; }; crossing_restore: macro={ on_x1=on_x1_aux;on_sep1=on_sep1_aux;on_a1=on_a1_aux;on_o1=on_o1_aux; on_x2=on_x2_aux;on_sep2=on_sep2_aux;on_a2=on_a2_aux;on_o2=on_o2_aux; on_oe2=on_oe2_aux; on_x5=on_x5_aux;on_sep5=on_sep5_aux;on_a5=on_a5_aux;on_o5=on_o5_aux; on_x8=on_x8_aux;on_sep8=on_sep8_aux;on_a8=on_a8_aux;on_o8=on_o8_aux; on_x2h=on_x2h_aux; on_x2v=on_x2v_aux; on_sep2h=on_sep2h_aux; on_sep2v=on_sep2v_aux; on_x8h=on_x8h_aux; on_x8v=on_x8v_aux; on_sep8h=on_sep8h_aux; on_sep8v=on_sep8v_aux; on_disp=on_disp_aux; on_alice=on_alice_aux; on_lhcb=on_lhcb_aux; }; ''') # optics independent macros mad.call('optics_indep_macros.madx') assert mylhcbeam in [1, 2, 4], "Invalid mylhcbeam (it should be in [1, 2, 4])" if mylhcbeam in [1, 2]: mad.call('optics_runII/2018/lhc_as-built.seq') else: mad.call('optics_runII/2018/lhcb4_as-built.seq') # New IR7 MQW layout and cabling mad.call('optics_runIII/RunIII_dev/IR7-Run3seqedit.madx') # Makethin part if slicefactor > 0: # the variable in the macro is slicefactor mad.input(f'slicefactor={slicefactor};') mad.call('optics_runII/2018/toolkit/myslice.madx') mad.beam() for my_sequence in ['lhcb1', 'lhcb2']: if my_sequence in list(mad.sequence): mad.input( f'use, sequence={my_sequence}; makethin, sequence={my_sequence}, style=teapot, makedipedge=true;' ) else: warnings.warn('The sequences are not thin!') # Cycling w.r.t. to IP3 (mandatory to find closed orbit in collision in the presence of errors) for my_sequence in ['lhcb1', 'lhcb2']: if my_sequence in list(mad.sequence): mad.input( f'seqedit, sequence={my_sequence}; flatten; cycle, start=IP3; flatten; endedit;' )
import optics_specific_tools as ost python_parameters = ost.get_python_parameters(job_row) mask_parameters = ost.get_mask_parameters(python_parameters) knob_parameters = ost.get_knob_parameters() directory = python_parameters['working_folder'] if not os.path.exists(directory): os.makedirs(directory) os.chdir(directory) # make a local copy in the job's folder of the jobs df and py files if len(sys.argv) > 1: shutil.copyfile(sys.argv[1], './input_jobs_df.pickle') pm.make_links( force=True, links_dict={'parent_folder': python_parameters['parent_folder']}) for ff in glob.glob('parent_folder/*.py'): shutil.copyfile(ff, os.path.split(ff)[1]) Madx = pm.Madxp # Select mode mode = python_parameters['mode'] # mode can be # 'b1_with_bb' # 'b1_with_bb_legacy_macros' # 'b1_without_bb' # 'b4_without_bb' # 'b4_from_b2_without_bb' # 'b4_from_b2_with_bb'