Skip to content

Commit

Permalink
[TASK] added tests checking calling signature of digital twin
Browse files Browse the repository at this point in the history
Functional tests pending
  • Loading branch information
PierreSchnizer committed Nov 22, 2023
1 parent 11cf5b6 commit 4b900a4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/tests/closed_orbit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
import gtpsa
from thor_scsi.factory import accelerator_from_config
from thor_scsi.utils.closed_orbit import compute_closed_orbit
from thor_scsi.utils import canonical_variables_mapping_default

from thor_scsi.utils.accelerator import (
instrument_with_standard_observers,
extract_orbit_from_standard_observers,
extract_orbit_from_accelerator_with_standard_observers,
)

path = (
Path(os.path.dirname(__file__))
Expand All @@ -28,6 +34,7 @@ def create_acc():


def test10_closed_orbit_for_zero():

calc_config = tslib.ConfigType()
acc = create_acc()

Expand Down Expand Up @@ -56,6 +63,20 @@ def test10_closed_orbit_for_zero():
assert x0.ct == pytest.approx(ct_save, abs=1e-9)


def test20_closed_orbit_for_zero_ovservers():
"""test functions used by twin
just that they execute without error
"""
calc_config = tslib.ConfigType()
acc = create_acc()
observers_non_perturbated = instrument_with_standard_observers(
acc, mapping=canonical_variables_mapping_default
)
result = compute_closed_orbit(acc, calc_config, delta=0e0)
assert result.found_closed_orbit == True
extract_orbit_from_accelerator_with_standard_observers(acc)

def compensate_quadrupole_offset_with_dipole_kick(quad):
dx = quad.get_dx()
assert quad.get_main_multipole_number() == 2
Expand Down
51 changes: 51 additions & 0 deletions python/tests/twiss_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from thor_scsi.utils import canonical_variables_mapping_default
from thor_scsi.utils.linear_optics import compute_Twiss_along_lattice
from thor_scsi.factory import accelerator_from_config
from thor_scsi import lib as tslib
import gtpsa
import pytest
from pathlib import Path
import os.path

desc = gtpsa.desc(6, 1)

path = (
Path(os.path.dirname(__file__))
/ "lattices"
/ "b2_stduser_beamports_blm_tracy_corr.lat"
)


def create_acc():
acc = accelerator_from_config(path)
acc.set_log_level(tslib.accelerator_log_level.warning)
return acc


def test_twiss_without_radiation():
"""Functions as used by digital twin"""
n_dof = 2
calc_config = tslib.ConfigType()
calc_config.radiation = False
calc_config.Cavity_on = False
acc = create_acc()
compute_Twiss_along_lattice(
n_dof, acc, calc_config, desc=desc, mapping=canonical_variables_mapping_default
)


@pytest.mark.skip
def test_twiss_with_radiation():
"""Functions as used by digital twin
just check that it runs
"""
calc_config = tslib.ConfigType()
n_dof = 3
calc_config.radiation = True
calc_config.Cavity_on = True
calc_config.Energy = 2.7
acc = create_acc()
compute_Twiss_along_lattice(
n_dof, acc, calc_config, desc=desc, mapping=canonical_variables_mapping_default
)

0 comments on commit 4b900a4

Please sign in to comment.