Example #1
0
def test_lhc_creation_best_knowledge():
    _create_input_lhc()
    opt_dict = dict(type="best_knowledge",
                    accel="lhc",
                    year="2018",
                    ats=True,
                    beam=1,
                    nat_tunes=[0.31, 0.32],
                    dpp=0.0,
                    energy=6.5,
                    modifiers=join(BASE_OUTPUT, MODIFIERS_MADX),
                    outputdir=BASE_OUTPUT,
                    writeto=join(BASE_OUTPUT, "job.twiss_best_knowledge.madx"),
                    logfile=join(BASE_OUTPUT, "madx_log_best_knowledge.txt"))
    create_instance_and_model(opt_dict)
    _clean_up(BASE_OUTPUT)
Example #2
0
def test_lhc_creation_relative_modeldir_path(request, tmp_path):
    os.chdir(tmp_path)  # switch cwd to tmp_path
    model_dir_relpath = Path("test_model")
    model_dir_relpath.mkdir()

    optics_file_relpath = Path("opticsfile.24_ctpps2")
    shutil.copy(COMP_MODEL / optics_file_relpath,
                model_dir_relpath / optics_file_relpath)

    accel_opt = dict(
        accel="lhc",
        year="2018",
        ats=True,
        beam=1,
        nat_tunes=[0.31, 0.32],
        dpp=0.0,
        energy=6.5,
        modifiers=[optics_file_relpath],
    )

    # sometimes create_instance_and_model seems to run but does not create twiss-files ...
    accel = create_instance_and_model(outputdir=model_dir_relpath,
                                      type="nominal",
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)

    # ... which is then caught here:
    check_accel_from_dir_vs_options(model_dir_relpath,
                                    accel_opt,
                                    accel,
                                    required_keys=["beam", "year"])
    os.chdir(request.config.invocation_dir)  # return to original cwd
Example #3
0
def test_ps_creation_nominal():
    _create_input_ps()
    opt_dict = dict(type="nominal",
                    accel="ps",
                    nat_tunes=[6.32, 6.29],
                    drv_tunes=[0.325, 0.284],
                    driven_excitation="acd",
                    dpp=0.0,
                    energy=1.4,
                    modifiers=join(BASE_OUTPUT, MODIFIERS_MADX),
                    fullresponse=True,
                    outputdir=BASE_OUTPUT,
                    writeto=join(BASE_OUTPUT, "job.twiss.madx"),
                    logfile=join(BASE_OUTPUT, "madx_log.txt"))
    create_instance_and_model(opt_dict)
    _clean_up(BASE_OUTPUT)
Example #4
0
def test_lhc_creation_modifier_nonexistent(tmp_path):
    accel_opt = dict(
        accel="lhc",
        year="2018",
        ats=True,
        beam=1,
        nat_tunes=[0.31, 0.32],
        dpp=0.0,
        energy=6.5,
        modifiers=[COMP_MODEL / "opticsfile.non_existent"],
    )
    with pytest.raises(AcceleratorDefinitionError) as creation_error:
        create_instance_and_model(outputdir=tmp_path,
                                  type="nominal",
                                  logfile=tmp_path / "madx_log.txt",
                                  **accel_opt)
    assert "opticsfile.non_existent" in str(creation_error.value)
Example #5
0
def test_booster_creation_nominal():
    iotools.create_dirs(BASE_OUTPUT)
    iotools.write_string_into_new_file(join(BASE_OUTPUT, MODIFIERS_MADX), "\n")
    opt_dict = dict(type="nominal",
                    accel="psbooster",
                    ring=1,
                    nat_tunes=[4.21, 4.27],
                    drv_tunes=[0.205, 0.274],
                    driven_excitation="acd",
                    dpp=0.0,
                    energy=0.16,
                    modifiers=join(BASE_OUTPUT, MODIFIERS_MADX),
                    fullresponse=True,
                    outputdir=BASE_OUTPUT,
                    writeto=join(BASE_OUTPUT, "job.twiss.madx"),
                    logfile=join(BASE_OUTPUT, "madx_log.txt"))
    create_instance_and_model(opt_dict)
    _clean_up(BASE_OUTPUT)
Example #6
0
def test_lhc_creation_nominal():
    _create_input_lhc()
    opt_dict = dict(type="nominal",
                    accel="lhc",
                    year="2018",
                    ats=True,
                    beam=1,
                    nat_tunes=[0.31, 0.32],
                    drv_tunes=[0.298, 0.335],
                    driven_excitation="acd",
                    dpp=0.0,
                    energy=6.5,
                    modifiers=join(BASE_OUTPUT, MODIFIERS_MADX),
                    fullresponse=True,
                    outputdir=BASE_OUTPUT,
                    writeto=join(BASE_OUTPUT, "job.twiss.madx"),
                    logfile=join(BASE_OUTPUT, "madx_log.txt"))
    create_instance_and_model(opt_dict)
    _clean_up(BASE_OUTPUT)
Example #7
0
def test_booster_creation_nominal_free(tmp_path):
    accel_opt = dict(
        accel="psbooster",
        ring=1,
        nat_tunes=[4.21, 4.27],
        dpp=0.0,
        energy=0.16,
        modifiers=None,
    )
    accel = create_instance_and_model(type="nominal",
                                      outputdir=tmp_path,
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)
    check_accel_from_dir_vs_options(tmp_path,
                                    accel_opt,
                                    accel,
                                    required_keys=["ring"])
Example #8
0
def test_ps_creation_nominal_free_2021(tmp_path):
    accel_opt = dict(
        accel="ps",
        nat_tunes=[6.32, 6.29],
        dpp=0.0,
        energy=1.4,
        year=2021,
        modifiers=[PS_MODEL / "2021" / "strength" / "ps_fb_lhc.str"],
    )
    accel = create_instance_and_model(type="nominal",
                                      outputdir=tmp_path,
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)
    check_accel_from_dir_vs_options(tmp_path,
                                    accel_opt,
                                    accel,
                                    required_keys=["year"])
Example #9
0
def test_lhc_creation_best_knowledge(tmp_path):
    (tmp_path /
     LhcBestKnowledgeCreator.EXTRACTED_MQTS_FILENAME).write_text("\n")
    (tmp_path / LhcBestKnowledgeCreator.CORRECTIONS_FILENAME).write_text("\n")
    accel_opt = dict(
        accel="lhc",
        year="2018",
        ats=True,
        beam=1,
        nat_tunes=[0.31, 0.32],
        dpp=0.0,
        energy=6.5,
        modifiers=[COMP_MODEL / "opticsfile.24_ctpps2"],
    )
    accel = create_instance_and_model(outputdir=tmp_path,
                                      type="best_knowledge",
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)
Example #10
0
def test_lhc_creation_nominal_free(tmp_path):
    accel_opt = dict(
        accel="lhc",
        year="2018",
        beam=1,
        nat_tunes=[0.31, 0.32],
        dpp=0.0,
        energy=6.5,
        modifiers=[COMP_MODEL / "opticsfile.24_ctpps2"],
    )
    accel = create_instance_and_model(outputdir=tmp_path,
                                      type="nominal",
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)
    check_accel_from_dir_vs_options(tmp_path,
                                    accel_opt,
                                    accel,
                                    required_keys=["beam", "year"])
Example #11
0
def test_ps_creation_nominal_driven_2018(tmp_path):
    accel_opt = dict(
        accel="ps",
        nat_tunes=[6.32, 6.29],
        drv_tunes=[0.325, 0.284],
        driven_excitation="acd",
        dpp=0.0,
        energy=1.4,
        year=2018,
        modifiers=[
            PS_MODEL / "2018" / "strength" / "PS_LE_LHC_low_chroma.str"
        ],
    )
    accel = create_instance_and_model(type="nominal",
                                      outputdir=tmp_path,
                                      logfile=tmp_path / "madx_log.txt",
                                      **accel_opt)
    check_accel_from_dir_vs_options(tmp_path,
                                    accel_opt,
                                    accel,
                                    required_keys=["year"])