Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxed passmethod coherence tests when loading files #600

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions pyat/at/load/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, family_name, energy, periodicity=1, **kwargs):
'BndMPoleSymplectic4RadPass': elt.Dipole,
'BndMPoleSymplectic4Pass': elt.Dipole,
'QuadLinearPass': elt.Quadrupole,
'StrMPoleSymplectic4Pass': elt.Multipole,
'StrMPoleSymplectic4RadPass': elt.Multipole,
'CorrectorPass': elt.Corrector,
'CavityPass': elt.RFCavity, 'RFCavityPass': elt.RFCavity,
'ThinMPolePass': elt.ThinMultipole,
Expand Down Expand Up @@ -213,8 +215,8 @@ def element_from_dict(elem_dict: dict, index: Optional[int] = None,
def sanitise_class(index, cls, elem_dict):
"""Checks that the Class and PassMethod of the element are a valid
combination. Some Classes and PassMethods are incompatible and
would raise errors during calculation if left, so we raise an error
here with a more helpful message.
would raise errors during calculation, so we send a
warning here.

Args:
index: element index
Expand All @@ -230,7 +232,7 @@ def err(message, *args):
msg = ''.join(('Error in element', location,
'PassMethod {0} '.format(pass_method),
message.format(*args), '\n{0}'.format(elem_dict)))
return AttributeError(msg)
return AtWarning(msg)

class_name = cls.__name__
pass_method = elem_dict.get('PassMethod')
Expand All @@ -240,18 +242,12 @@ def err(message, *args):
file_name = pass_method + _ext_suffix
file_path = os.path.join(integrators.__path__[0], file_name)
if not os.path.isfile(os.path.realpath(file_path)):
raise err("does not have a {0} file.".format(file_name))
warn(err(" is missing {0}.".format(file_name)))
elif (pass_method == 'IdentityPass') and (length != 0.0):
raise err("is not compatible with length {0}.", length)
warn(err("is not compatible with length {0}.", length))
elif pass_to_class is not None:
if not issubclass(cls, pass_to_class):
raise err("is not compatible with Class {0}.", class_name)
elif issubclass(cls, (elt.Marker, elt.Monitor, RingParam)):
if pass_method != 'IdentityPass':
raise err("is not compatible with Class {0}.", class_name)
elif cls == elt.Drift:
if pass_method != 'DriftPass':
raise err("is not compatible with Class {0}.", class_name)
warn(err("is not compatible with Class {0}.", class_name))

cls = find_class(elem_dict, quiet=quiet)
if check:
Expand Down
9 changes: 3 additions & 6 deletions pyat/test/test_load_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,12 @@ def test_find_Element(elem_kwargs):
'FamName': 'fam'},
{'Class': 'Marker', 'PassMethod': 'StrMPoleSymplectic4Pass',
'FamName': 'fam'},
{'Class': 'Monitor', 'PassMethod': 'StrMPoleSymplectic4Pass',
'FamName': 'fam'},
{'Class': 'RingParam', 'PassMethod': 'StrMPoleSymplectic4Pass',
'Energy': 3E9, 'FamName': 'fam'},
{'Class': 'Drift', 'PassMethod': 'StrMPoleSymplectic4Pass',
'Length': 1.0, 'FamName': 'fam'},
{'Class': 'Drift', 'PassMethod': 'InvalidPass'}))
{'Class': 'Drift', 'PassMethod': 'InvalidPass',
'Length': 1.0, 'FamName': 'fam'}))
def test_sanitise_class_error(elem_kwargs):
with pytest.raises(AttributeError):
with pytest.warns(AtWarning):
element_from_dict(elem_kwargs)


Expand Down