Skip to content

Commit

Permalink
Make model creator tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
awegsche committed Nov 3, 2023
1 parent 8c76af8 commit a9f7e6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ jobs:
- name: Install package
run: python -m pip install '.[test]'

- name: Clone acc-models
run: |
git clone -b 2023 https://gitlab.cern.ch/acc-models/acc-models-lhc.git acc-models-lhc-2023
git clone -b 2022 https://gitlab.cern.ch/acc-models/acc-models-lhc.git acc-models-lhc-2022
git clone -b 2018 https://gitlab.cern.ch/acc-models/acc-models-lhc.git acc-models-lhc-2018
git clone -b 2021 https://gitlab.cern.ch/acc-models/acc-models-psb.git acc-models-psb-2021
git clone -b 2021 https://gitlab.cern.ch/acc-models/acc-models-ps.git acc-models-ps-2021
- name: Run Basic Tests
run: python -m pytest -m "not extended and not cern_network"

Expand Down
2 changes: 1 addition & 1 deletion omc3/model_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _find_modifier(modifier, accel_inst: Accelerator):
if modifier_path.exists():
return modifier_path.absolute()

raise FileNotFoundError(f"couldn't find modifier {modifier}. Tried in {accel_inst.model_dir} and {accel_inst.acc_model_path}")
raise FileNotFoundError(f"couldn't find modifier {modifier}. Tried in {accel_inst.model_dir} and {accel_inst.acc_model_path}/{MODIFIER_BRANCH}")


if __name__ == "__main__":
Expand Down
40 changes: 20 additions & 20 deletions tests/unit/test_model_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from omc3.model_creator import create_instance_and_model

INPUTS = Path(__file__).parent.parent / "inputs"
MODEL_CREATOR_INPUT = INPUTS / "model_creation"
COMP_MODEL = INPUTS / "models" / "25cm_beam1"
CODEBASE_PATH = Path(__file__).parent.parent.parent / "omc3"
PS_MODEL = CODEBASE_PATH / "model" / "accelerators" / "ps"
ROOT = Path(os.getcwd()) # there might be a better way

LHC_30CM_MODIFIERS = [Path("R2022a_A30cmC30cmA10mL200cm.madx")]
LHC_40CM_MODIFIERS = [Path("R2018h_A40mC40mA10mL10m.madx")]
LHC_30CM_MODIFIERS = [Path("R2023a_A30cmC30cmA10mL200cm.madx")]
HIGH_BETA_MODIFIERS = [Path("R2018h_A90mC90mA10mL10m.madx")]


@pytest.mark.basic
Expand All @@ -31,7 +31,7 @@ def test_booster_creation_nominal_driven(tmp_path):
energy=0.16,
modifiers=None,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "psb",
path=ROOT / "acc-models-psb-2021",
scenario="lhc",
cycle_point="0_injection",
str_file="psb_inj_lhc.str",
Expand All @@ -51,7 +51,7 @@ def test_booster_creation_nominal_free(tmp_path):
energy=0.16,
modifiers=None,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "psb",
path=ROOT/"acc-models-psb-2021",
scenario="lhc",
cycle_point="0_injection",
str_file="psb_inj_lhc.str",
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_ps_creation_nominal_free_2021(tmp_path):
energy=1.4,
year="2021",
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "ps",
path=ROOT/"acc-models-ps-2021",
scenario="lhc",
cycle_point="0_injection",
str_file="ps_inj_lhc.str",
Expand All @@ -131,15 +131,15 @@ def test_ps_creation_nominal_free_2021(tmp_path):
def test_lhc_creation_nominal_driven(tmp_path):
accel_opt = dict(
accel="lhc",
year="2022",
year="2023",
beam=1,
nat_tunes=[0.31, 0.32],
drv_tunes=[0.298, 0.335],
driven_excitation="acd",
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2023",
modifiers=LHC_30CM_MODIFIERS,
)
accel = create_instance_and_model(
Expand All @@ -149,7 +149,7 @@ def test_lhc_creation_nominal_driven(tmp_path):


@pytest.mark.basic
def test_lhc_creation_nominal_free_2018(tmp_path):
def test_lhc_creation_nominal_free_high_beta(tmp_path):
accel_opt = dict(
accel="lhc",
year="2018",
Expand All @@ -158,8 +158,8 @@ def test_lhc_creation_nominal_free_2018(tmp_path):
dpp=0.0,
energy=6500.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2018",
modifiers=LHC_40CM_MODIFIERS
path=ROOT/"acc-models-lhc-2018",
modifiers=HIGH_BETA_MODIFIERS
)
accel = create_instance_and_model(
outputdir=tmp_path, type="nominal", logfile=tmp_path / "madx_log.txt", **accel_opt
Expand All @@ -171,13 +171,13 @@ def test_lhc_creation_nominal_free_2018(tmp_path):
def test_lhc_creation_nominal_free(tmp_path):
accel_opt = dict(
accel="lhc",
year="2022",
year="2023",
beam=1,
nat_tunes=[0.31, 0.32],
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2023",
modifiers=LHC_30CM_MODIFIERS
)
accel = create_instance_and_model(
Expand All @@ -192,14 +192,14 @@ def test_lhc_creation_best_knowledge(tmp_path):
(tmp_path / LhcBestKnowledgeCreator.CORRECTIONS_FILENAME).write_text("\n")
accel_opt = dict(
accel="lhc",
year="2022",
year="2023",
ats=True,
beam=1,
nat_tunes=[0.31, 0.32],
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2023",
b2_errors="MB2022_6500.0GeV_0133cm",
modifiers=LHC_30CM_MODIFIERS
)
Expand All @@ -219,10 +219,10 @@ def test_lhc_creation_relative_modifier_path(tmp_path):
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2023",
modifiers=LHC_30CM_MODIFIERS
)
shutil.copy(MODEL_CREATOR_INPUT / "lhc_2022/operation/optics" / "R2022a_A30cmC30cmA10mL200cm.madx", tmp_path / "R2022a_A30cmC30cmA10mL200cm.madx")
#shutil.copy(MODEL_CREATOR_INPUT / "lhc_2022/operation/optics" / "R2022a_A30cmC30cmA10mL200cm.madx", tmp_path / "R2022a_A30cmC30cmA10mL200cm.madx")

accel = create_instance_and_model(
outputdir=tmp_path, type="nominal", logfile=tmp_path / "madx_log.txt", **accel_opt
Expand All @@ -242,7 +242,7 @@ def test_lhc_creation_modifier_nonexistent(tmp_path):
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2023",
modifiers=[NONEXISTENT]
)
with pytest.raises(FileNotFoundError) as creation_error:
Expand All @@ -260,7 +260,7 @@ def test_lhc_creation_relative_modeldir_path(request, tmp_path):
model_dir_relpath.mkdir()

optics_file_relpath = Path("R2022a_A30cmC30cmA10mL200cm.madx")
shutil.copy(MODEL_CREATOR_INPUT / "lhc_2022/operation/optics" / optics_file_relpath, model_dir_relpath / optics_file_relpath.name)
shutil.copy(ROOT/"acc-models-lhc-2022/operation/optics" / optics_file_relpath, model_dir_relpath / optics_file_relpath.name)

accel_opt = dict(
accel="lhc",
Expand All @@ -271,7 +271,7 @@ def test_lhc_creation_relative_modeldir_path(request, tmp_path):
dpp=0.0,
energy=6800.0,
fetch=PATHFETCHER,
path=MODEL_CREATOR_INPUT / "lhc_2022",
path=ROOT/"acc-models-lhc-2022",
modifiers=[optics_file_relpath],
)

Expand Down

0 comments on commit a9f7e6e

Please sign in to comment.