From 45bdee9b6f00ec7e4a815b172951363f98239970 Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Thu, 7 Nov 2024 15:04:16 +0100 Subject: [PATCH 1/7] Created release branch release/v0.5.10rc0. --- pyproject.toml | 2 +- tests/test_version.py | 2 +- xcoll/general.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a63e7dd5..9ec6895a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "xcoll" -version = "0.5.9" +version = "0.5.10rc0" description = "Xsuite collimation package" homepage = "https://github.com/xsuite/xcoll" repository = "https://github.com/xsuite/xcoll" diff --git a/tests/test_version.py b/tests/test_version.py index 8bd5fb0f..29a3fe4b 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -6,4 +6,4 @@ from xcoll import __version__ def test_version(): - assert __version__ == '0.5.9' + assert __version__ == '0.5.10rc0' diff --git a/xcoll/general.py b/xcoll/general.py index 6d6023d5..9d009650 100644 --- a/xcoll/general.py +++ b/xcoll/general.py @@ -12,5 +12,5 @@ # ====================== # Do not change # ====================== -__version__ = '0.5.9' +__version__ = '0.5.10rc0' # ====================== From dde2dd0fa9e90a2e7a2f4935d88befa2872c5e9f Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Thu, 7 Nov 2024 15:09:00 +0100 Subject: [PATCH 2/7] Updated release scripts --- make_release_branch.py | 4 ++-- release.py | 4 ++-- rename_release_branch.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/make_release_branch.py b/make_release_branch.py index f3ac7d96..81021817 100755 --- a/make_release_branch.py +++ b/make_release_branch.py @@ -4,8 +4,8 @@ # Copyright (c) CERN, 2024. # # ######################################### # -from xaux.tools import dev_make_release_branch +from xaux.dev_tools import make_release_branch # sys.tracebacklimit = 0 -dev_make_release_branch("xcoll") +make_release_branch("xcoll") diff --git a/release.py b/release.py index 9c20c265..e8dbba25 100755 --- a/release.py +++ b/release.py @@ -4,8 +4,8 @@ # Copyright (c) CERN, 2024. # # ######################################### # -from xaux.tools import dev_release +from xaux.dev_tools import make_release # sys.tracebacklimit = 0 -dev_release("xcoll") +make_release("xcoll") diff --git a/rename_release_branch.py b/rename_release_branch.py index 222bd34b..4cdaa8d3 100755 --- a/rename_release_branch.py +++ b/rename_release_branch.py @@ -4,8 +4,8 @@ # Copyright (c) CERN, 2024. # # ######################################### # -from xaux.tools import dev_rename_release_branch +from xaux.dev_tools import rename_release_branch # sys.tracebacklimit = 0 -dev_rename_release_branch("xcoll") +rename_release_branch("xcoll") From 9538454012cac73091f1f7e6db853eaabc8d1a2e Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Thu, 7 Nov 2024 19:42:24 +0100 Subject: [PATCH 3/7] Added tilt and others to colldb import installer. Added tilt to colldbs in tests --- tests/data/colldb_lhc_run3.yaml | 2 +- tests/data/colldb_lhc_run3_b1.json | 3 +- tests/data/colldb_lhc_run3_b1.yaml | 2 +- .../data/colldb_lhc_run3_b1_no_families.yaml | 2 +- tests/data/colldb_lhc_run3_b1_no_merge.yaml | 2 +- tests/data/colldb_lhc_run3_ir7.yaml | 4 +- tests/test_colldb.py | 98 ++--- xcoll/beam_elements/base.py | 15 + xcoll/colldb.py | 340 +++++++++--------- 9 files changed, 236 insertions(+), 232 deletions(-) diff --git a/tests/data/colldb_lhc_run3.yaml b/tests/data/colldb_lhc_run3.yaml index 435b6f3f..82753ca2 100644 --- a/tests/data/colldb_lhc_run3.yaml +++ b/tests/data/colldb_lhc_run3.yaml @@ -66,7 +66,7 @@ collimators: tcdqa.b4r6.b1: { <<: *TCDQ } tcsp.a4r6.b1: { <<: *TCSP } tcp.d6l7.b1: { <<: *TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR } + tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } tcp.b6l7.b1: { <<: *TCP7, angle: 127.5 } tcsg.a6l7.b1: { <<: *TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { <<: *CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1.json b/tests/data/colldb_lhc_run3_b1.json index 712dd6d5..d00a420f 100644 --- a/tests/data/colldb_lhc_run3_b1.json +++ b/tests/data/colldb_lhc_run3_b1.json @@ -252,7 +252,8 @@ "tcp.c6l7.b1": { "family": "TCP7", "angle": 0, - "material": "MoGR" + "material": "MoGR", + "tilt": [-250e-6, 250e6] }, "tcp.b6l7.b1": { "family": "TCP7", diff --git a/tests/data/colldb_lhc_run3_b1.yaml b/tests/data/colldb_lhc_run3_b1.yaml index fbc735cb..0dc36d9e 100644 --- a/tests/data/colldb_lhc_run3_b1.yaml +++ b/tests/data/colldb_lhc_run3_b1.yaml @@ -62,7 +62,7 @@ Collimators: tcdqa.b4r6.b1: { <<: *TCDQ } tcsp.a4r6.b1: { <<: *TCSP } tcp.d6l7.b1: { <<: *TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR } + tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } tcp.b6l7.b1: { <<: *TCP7, angle: 127.5 } tcsg.a6l7.b1: { <<: *TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { <<: *CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1_no_families.yaml b/tests/data/colldb_lhc_run3_b1_no_families.yaml index 2cb7847e..b30f61b0 100644 --- a/tests/data/colldb_lhc_run3_b1_no_families.yaml +++ b/tests/data/colldb_lhc_run3_b1_no_families.yaml @@ -30,7 +30,7 @@ tcdqa.c4r6.b1: { gap: 7.3, stage: tertiary, material: C, length: 3, a tcdqa.b4r6.b1: { gap: 7.3, stage: tertiary, material: C, length: 3, angle: 0, parking: 0.025, side: left } tcsp.a4r6.b1: { gap: 7.3, stage: SECONDARY, material: C, Length: 1, angle: 0, parking: 0.025 } TCP.D6l7.B1: { gap: 5, stage: primary, material: MoGR, length: 0.6, angle: 90, parking: 0.025 } -tcp.c6l7.b1: { gap: 5, stage: primary, MATeRIAL: MoGR, length: 0.6, angle: 0, parking: 0.025 } +tcp.c6l7.b1: { gap: 5, stage: primary, MATeRIAL: MoGR, length: 0.6, angle: 0, parking: 0.025, tilt: [-250e-6, 250e6] } tcp.b6l7.b1: { gap: 5, stage: primary, material: C, length: 0.6, angle: 127.5, parking: 0.025 } tcsg.a6l7.b1: { gap: 6.5, stage: secondary, material: C, length: 1, angle: 141.1, parking: 0.025 } tcpcv.a6l7.b1: { gap: null, stage: special, material: Si, length: 0.004, angle: 90, parking: 0.025, side: left, crystal: strip, Bending_radius: 85.10, Width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1_no_merge.yaml b/tests/data/colldb_lhc_run3_b1_no_merge.yaml index 1a8dc394..3532ddbf 100644 --- a/tests/data/colldb_lhc_run3_b1_no_merge.yaml +++ b/tests/data/colldb_lhc_run3_b1_no_merge.yaml @@ -62,7 +62,7 @@ Collimators: tcdqa.b4r6.b1: { family: TCDQ } tcsp.a4r6.b1: { family: TCSP } tcp.d6l7.b1: { family: TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { family: TCP7, angle: 0, material: MoGR } + tcp.c6l7.b1: { family: TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } tcp.b6l7.b1: { family: TCP7, angle: 127.5 } tcsg.a6l7.b1: { family: TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { family: CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_ir7.yaml b/tests/data/colldb_lhc_run3_ir7.yaml index b6a95bac..3b494056 100644 --- a/tests/data/colldb_lhc_run3_ir7.yaml +++ b/tests/data/colldb_lhc_run3_ir7.yaml @@ -15,7 +15,7 @@ emittance: collimators: b1: tcp.d6l7.b1: { <<: *TCP7, angle: 90, material: MoGR, length: 1.565 } - tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR } + tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e-6] } tcp.b6l7.b1: { <<: *TCP7, angle: 127.5 } tcsg.a6l7.b1: { <<: *TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { <<: *CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } @@ -29,7 +29,7 @@ collimators: b2: tcp.d6r7.b2: { <<: *TCP7, angle: 90, material: MoGR, length: 1.565 } - tcp.c6r7.b2: { <<: *TCP7, angle: 0, material: MoGR } + tcp.c6r7.b2: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e-6] } tcp.b6r7.b2: { <<: *TCP7, angle: 127.5 } tcsg.a6r7.b2: { <<: *TCSG7, angle: 141.1 } tcpcv.a6r7.b2: { <<: *CRY7, angle: 90, bending_radius: 74.88, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/test_colldb.py b/tests/test_colldb.py index 011585b4..9f7fdfe6 100644 --- a/tests/test_colldb.py +++ b/tests/test_colldb.py @@ -60,9 +60,9 @@ def test_loading_SixTrack(): colldb_2 = xc.CollimatorDatabase.from_SixTrack(path / 'colldb_lhc_run3_b1.dat', nemitt_x=3.5e-6, nemitt_y=3.5e-6) df1 = colldb_1.to_pandas().reindex(sorted(colldb_1.to_pandas().columns), axis=1) df2 = colldb_2.to_pandas().reindex(sorted(colldb_2.to_pandas().columns), axis=1) - # In SixTrack loader, families are not (yet) loaded - df1 = df1.drop(['family', 'overwritten_keys'], axis=1) - df2 = df2.drop(['family', 'overwritten_keys'], axis=1) + # In SixTrack loader, families, and tilts are not loaded + df1 = df1.drop(['family', 'overwritten_keys', 'tilt'], axis=1) + df2 = df2.drop(['family', 'overwritten_keys', 'tilt'], axis=1) # In SixTrack loader, non-active collimators default to active df1_only_active = df1.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) df1_only_active = df1_only_active.drop('parking', axis=1) @@ -77,9 +77,9 @@ def test_loading_SixTrack_crystals(): colldb_2 = xc.CollimatorDatabase.from_SixTrack(path / 'colldb_lhc_run3_b1.dat', nemitt_x=3.5e-6, nemitt_y=3.5e-6, ignore_crystals=False) df1 = colldb_1.to_pandas().reindex(sorted(colldb_1.to_pandas().columns), axis=1) df2 = colldb_2.to_pandas().reindex(sorted(colldb_2.to_pandas().columns), axis=1) - # In SixTrack loader, families are not (yet) loaded - df1 = df1.drop(['family', 'overwritten_keys'], axis=1) - df2 = df2.drop(['family', 'overwritten_keys'], axis=1) + # In SixTrack loader, families, and tilts are not loaded + df1 = df1.drop(['family', 'overwritten_keys', 'tilt'], axis=1) + df2 = df2.drop(['family', 'overwritten_keys', 'tilt'], axis=1) # In SixTrack loader, non-active collimators default to active df1_only_active = df1.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) df1_only_active = df1_only_active.drop('parking', axis=1) @@ -90,46 +90,46 @@ def test_loading_SixTrack_crystals(): assert df1_only_active.equals(df2_only_active) -def test_dumping(): - colldb_1 = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=1) - colldb_2 = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=2) - colldb_1.to_yaml('out1') - colldb_2.to_yaml('out2') - colldb_3 = xc.CollimatorDatabase.from_yaml('out1.yaml', beam=1) - colldb_4 = xc.CollimatorDatabase.from_yaml('out2.yaml', beam=2) - df1 = colldb_1.to_pandas().reindex(sorted(colldb_1.to_pandas().columns), axis=1) - df2 = colldb_2.to_pandas().reindex(sorted(colldb_2.to_pandas().columns), axis=1) - df3 = colldb_3.to_pandas().reindex(sorted(colldb_3.to_pandas().columns), axis=1) - df4 = colldb_4.to_pandas().reindex(sorted(colldb_4.to_pandas().columns), axis=1) - assert df1.equals(df3) - assert df2.equals(df4) - (Path.cwd() / 'out1.yaml').unlink() - (Path.cwd() / 'out2.yaml').unlink() - - -def test_dumping_from_Sixtrack(): - colldb_yaml = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=1,ignore_crystals=False) - colldb_dat = xc.CollimatorDatabase.from_SixTrack(path / 'colldb_lhc_run3_b1.dat', nemitt_x=3.5e-6, nemitt_y=3.5e-6, ignore_crystals=False) - colldb_dat.to_yaml('ne.to_pandas().lhc_run3') - - colldb_yaml_new = xc.CollimatorDatabase.from_yaml('ne.to_pandas().lhc_run3.yaml', beam=1,ignore_crystals=False) - df_yaml = colldb_yaml.to_pandas().reindex(sorted(colldb_yaml.to_pandas().columns), axis=1) - df_dat = colldb_dat.to_pandas().reindex(sorted(colldb_dat.to_pandas().columns), axis=1) - df_yaml_new = colldb_yaml_new.to_pandas().reindex(sorted(colldb_yaml_new.to_pandas().columns), axis=1) - - df_yaml = df_yaml.drop(['family', 'overwritten_keys', 'parking'], axis=1) - df_yaml_new = df_yaml_new.drop(['family', 'overwritten_keys', 'parking'], axis=1) - df_dat = df_dat.drop(['family', 'overwritten_keys', 'parking'], axis=1) - - df_yaml_new = df_yaml_new.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) - df_yaml = df_yaml.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) - df_dat = df_dat.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) - - df_yaml_new.sort_index(axis=0, inplace=True) - df_dat.sort_index(axis=0, inplace=True) - df_yaml.sort_index(axis=0, inplace=True) - - assert df_dat.equals(df_yaml) - assert df_yaml_new.equals(df_yaml) - assert df_yaml_new.equals(df_dat) - (Path.cwd() / 'ne.to_pandas().lhc_run3.yaml').unlink() \ No newline at end of file +# def test_dumping(): +# colldb_1 = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=1) +# colldb_2 = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=2) +# colldb_1.to_yaml('out1') +# colldb_2.to_yaml('out2') +# colldb_3 = xc.CollimatorDatabase.from_yaml('out1.yaml', beam=1) +# colldb_4 = xc.CollimatorDatabase.from_yaml('out2.yaml', beam=2) +# df1 = colldb_1.to_pandas().reindex(sorted(colldb_1.to_pandas().columns), axis=1) +# df2 = colldb_2.to_pandas().reindex(sorted(colldb_2.to_pandas().columns), axis=1) +# df3 = colldb_3.to_pandas().reindex(sorted(colldb_3.to_pandas().columns), axis=1) +# df4 = colldb_4.to_pandas().reindex(sorted(colldb_4.to_pandas().columns), axis=1) +# assert df1.equals(df3) +# assert df2.equals(df4) +# (Path.cwd() / 'out1.yaml').unlink() +# (Path.cwd() / 'out2.yaml').unlink() + + +# def test_dumping_from_Sixtrack(): +# colldb_yaml = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=1,ignore_crystals=False) +# colldb_dat = xc.CollimatorDatabase.from_SixTrack(path / 'colldb_lhc_run3_b1.dat', nemitt_x=3.5e-6, nemitt_y=3.5e-6, ignore_crystals=False) +# colldb_dat.to_yaml('ne.to_pandas().lhc_run3') + +# colldb_yaml_new = xc.CollimatorDatabase.from_yaml('ne.to_pandas().lhc_run3.yaml', beam=1,ignore_crystals=False) +# df_yaml = colldb_yaml.to_pandas().reindex(sorted(colldb_yaml.to_pandas().columns), axis=1) +# df_dat = colldb_dat.to_pandas().reindex(sorted(colldb_dat.to_pandas().columns), axis=1) +# df_yaml_new = colldb_yaml_new.to_pandas().reindex(sorted(colldb_yaml_new.to_pandas().columns), axis=1) + +# df_yaml = df_yaml.drop(['family', 'overwritten_keys', 'parking', 'tilt'], axis=1) +# df_yaml_new = df_yaml_new.drop(['family', 'overwritten_keys', 'parking', 'tilt'], axis=1) +# df_dat = df_dat.drop(['family', 'overwritten_keys', 'parking', 'tilt'], axis=1) + +# df_yaml_new = df_yaml_new.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) +# df_yaml = df_yaml.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) +# df_dat = df_dat.drop(['tcsg.b4l7.b1', 'tcsg.e5r7.b1', 'tcsg.6r7.b1'], axis=0) + +# df_yaml_new.sort_index(axis=0, inplace=True) +# df_dat.sort_index(axis=0, inplace=True) +# df_yaml.sort_index(axis=0, inplace=True) + +# assert df_dat.equals(df_yaml) +# assert df_yaml_new.equals(df_yaml) +# assert df_yaml_new.equals(df_dat) +# (Path.cwd() / 'ne.to_pandas().lhc_run3.yaml').unlink() diff --git a/xcoll/beam_elements/base.py b/xcoll/beam_elements/base.py index 3997098d..749531ed 100644 --- a/xcoll/beam_elements/base.py +++ b/xcoll/beam_elements/base.py @@ -198,6 +198,13 @@ def __init__(self, **kwargs): to_assign['angle_L'] = kwargs.pop('angle_L', 0) to_assign['angle_R'] = kwargs.pop('angle_R', 0) + # We do not allow any combination of jaw_ and gap_ attributes + # (except when jaw=..., gap=None or jaw=None, gap=... is used, as this is how the colldb installs it) + if 'jaw' in kwargs and kwargs['jaw'] is None: + kwargs.pop('jaw') + if 'gap' in kwargs and kwargs['gap'] is None: + kwargs.pop('gap') + # Set jaw if 'jaw' in kwargs: for key in ['jaw_L', 'jaw_R', 'jaw_LU', 'jaw_LD', 'jaw_RU', 'jaw_RD', 'gap', 'gap_L', 'gap_R']: @@ -1058,6 +1065,14 @@ def __init__(self, **kwargs): # Set angle to_assign['angle'] = kwargs.pop('angle', 0) + # We do not allow any combination of jaw_ and gap_ attributes + # (except when jaw=..., gap=None or jaw=None, gap=... is used, as this is how the colldb installs it) + if 'jaw' in kwargs and kwargs['jaw'] is None: + kwargs.pop('jaw') + if 'gap' in kwargs and kwargs['gap'] is None: + kwargs.pop('gap') + + # Set jaw if 'jaw' in kwargs: for key in ['jaw_U', 'jaw_D', 'gap']: diff --git a/xcoll/colldb.py b/xcoll/colldb.py index c477e959..c2e92deb 100644 --- a/xcoll/colldb.py +++ b/xcoll/colldb.py @@ -358,156 +358,158 @@ def to_pandas(self): return pd.DataFrame(self._collimator_dict).transpose() def to_yaml(self, out, lhc_style=True): - """ - Writes a colldb in memory to disk in the yaml format. - - > colldb_object.write_to_yaml(, lhc_style=Bool) - - if lhc_style == True, it will add comments assuming that the collimators are named - as in the lhc. - - The function can dump b1, b2 and a general bx, however multi-beam functionality is not yet - added to the collmanager. TODO - - If any of the dumped keys contains capital letters (e.g. gap_L), it will not be possible - to load it back into xcoll, since all keys are set to lowercase when importing TODO - """ - # Dumps collimator database to a YAML file with optional LHC style formatting - import re - - # Local helper functions - def _format_dict_entry(key, value, spacing='', mapping=False, key_width=15): - # Formats a dictionary entry into a string for YAML output - formatted_values = ', '.join(f"{k}: {v}" for k, v in value.items()) - formatted_values = re.sub(r'none', 'null', formatted_values, flags=re.IGNORECASE) - # Ensure key has a fixed width for alignment - if mapping: - formatted_key = f'{key}'.ljust(key_width) - else: - formatted_key = f'{key}:'.ljust(key_width) - #formatted_values = formatted_values.ljust(key_width) - return f"{spacing}{formatted_key} {{ {formatted_values} }}\n" - - def _print_values(keys, dct, file, spacing='', mapping=False): - # Writes formatted dictionary entries to a file - for key in keys: - file.write(_format_dict_entry(key, dct[key], spacing=spacing, mapping=mapping)) - - def _print_colls(colls, dcts, beam, file): - # Filters and formats collimator data, then writes to a file - coll_items_to_print = ['<<','gap','angle','material','active','length','side'] - file.write(f' {beam}:\n') - for coll in colls: - coll_dict = dcts.to_pandas().transpose().to_dict()[coll] - fam = coll_dict['family'] - fam_keys = [] - if fam is not None: - fam_keys = dcts._family_dict[fam].keys() - coll_dict = {**{'<<': '*'+fam}, **coll_dict} - temp_items_to_print = [] - if coll_dict['crystal'] and str(coll_dict['crystal'])!='nan': - temp_items_to_print = ['bending_radius','width','height','miscut','crystal'] - # if 'angle_L' in coll_dict and coll_dict['angle_L'] == coll_dict['angle_R']: - # coll_dict.update({'angle': coll_dict['angle_L']}) - # else: - # temp_items_to_print = temp_items_to_print + ['angle_L','angle_R'] - # if coll_dict['gap_L'] == coll_dict['gap_R']: - # coll_dict.update({'gap': coll_dict['gap_L']}) - # elif coll_dict['gap_L'] is None and coll_dict['gap_R'] is not None: - # coll_dict.update({'gap': coll_dict['gap_R']}) - # elif coll_dict['gap_L'] is not None and coll_dict['gap_R'] is None: - # coll_dict.update({'gap': coll_dict['gap_L']}) - # else: - # temp_items_to_print = temp_items_to_print + ['gap_L','gap_R'] - value = {} - overwritten_keys = coll_dict['overwritten_keys'] - for key, val in coll_dict.items(): - if key == 'active_length': - key = 'length' - if (key in coll_items_to_print+temp_items_to_print) and (key not in (set(fam_keys)-set(overwritten_keys))) and (val != 'both'): - value.update({key: val}) - file.write(_format_dict_entry(coll, value, spacing=' ')) - file.write('\n') - - LHC_families = ['tcp3', 'tcsg3', 'tcsm3', 'tcla3', 'tcp7', 'tcsg7', 'tcsm7', 'tcla7', 'tcli', 'tdi', 'tcdq', 'tcstcdq', 'tcth1', 'tcth2', 'tcth5', 'tcth8', 'tctv1', 'tctv2', 'tctv5', 'tctv8', 'tclp', 'tcxrp', 'tcryo', 'tcl4', 'tcl5', 'tcl6', 'tct15', 'tct2', 'tct8', 'tcsp', 'tcld'] - with open(f'{out}.yaml', 'w') as file: - if '_family_dict' in self.__dict__.keys(): - file.write('families:\n') - if lhc_style: - printed_families = [] - fams_in_dict = self._family_dict.keys() - - # Momentum cleaning - file.write(' # Momentum cleaning\n') - sel_fam = [fam for fam in LHC_families if re.match('.*3', fam) and (fam in fams_in_dict)] - printed_families += sel_fam - _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) - - # Betatron cleaning - file.write(' # Betatron cleaning\n') - sel_fam = [fam for fam in LHC_families if re.match('.*7', fam) and (fam in fams_in_dict)] - printed_families += sel_fam - _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) - - # Injection protection - file.write(' # Injection protection\n') - sel_fam = [fam for fam in LHC_families if (fam in ['tcli', 'tdi']) and (fam in fams_in_dict)] - printed_families += sel_fam - _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) - - # Dump protection - file.write(' # Dump protection\n') - sel_fam = [fam for fam in LHC_families if (fam in ['tcdq', 'tcsp', 'tcstcdq']) and (fam in fams_in_dict)] - printed_families += sel_fam - _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) - - # Physics background / debris - file.write(' # Physics background / debris\n') - sel_fam = [fam for fam in LHC_families if ((re.match('tc[lt][0-9dp].*', fam)) or (fam in ['tcryo', 'tcxrp'])) and (fam in fams_in_dict)] - printed_families += sel_fam - _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) - - # Other families - if set(printed_families) != set(fams_in_dict): - file.write(' # Other families\n') - _print_values(set(fams_in_dict) - set(printed_families), self._family_dict, file, spacing=' - &', mapping=True) - else: - file.write(' # Families\n') - _print_values(self._family_dict.keys(), self._family_dict, file, spacing=' - &', mapping=True) - - # Emittance section - ex = self.nemitt_x - ey = self.nemitt_y - file.write(f'\nemittance:\n x: {ex}\n y: {ey}\n') - - # Collimators section - file.write('\ncollimators:\n') - b1_colls, b2_colls, bx_colls = [], [], [] - for coll in self.to_pandas().index: - if coll == 'tclia.4r2' or coll == 'tclia.4l8': # TODO: hardcoded!!! - b1_colls.append(coll) - b2_colls.append(coll) - elif coll[-2:] == 'b1': - b1_colls.append(coll) - elif coll[-2:] == 'b2': - b2_colls.append(coll) - else: - bx_colls.append(coll) - - # Handle special cases for collimators - if (('tclia.4r2' in b1_colls) or ('tclia.4l8' in b1_colls)) and (len(b1_colls) <= 2): - b1_colls = [] - if (('tclia.4r2' in b2_colls) or ('tclia.4l8' in b2_colls)) and (len(b2_colls) <= 2): - b2_colls = [] - - # Print collimators for each beam - if len(b1_colls) > 0: - _print_colls(b1_colls, self, 'b1', file) - if len(b2_colls) > 0: - _print_colls(b2_colls, self, 'b2', file) - if len(bx_colls) > 0: - _print_colls(bx_colls, self, 'bx', file) - print('WARNING -- some collimators could not be assigned to b1 or b2. Tracking might not work with those collimators. Please manually change the output file if necessary.') + raise NotImplementedError("This functionality needs to be updated to be compatible with tilts and read " + + "the families from the colldb instead of hard-coding them!") + # """ + # Writes a colldb in memory to disk in the yaml format. + + # > colldb_object.write_to_yaml(, lhc_style=Bool) + + # if lhc_style == True, it will add comments assuming that the collimators are named + # as in the lhc. + + # The function can dump b1, b2 and a general bx, however multi-beam functionality is not yet + # added to the collmanager. TODO + + # If any of the dumped keys contains capital letters (e.g. gap_L), it will not be possible + # to load it back into xcoll, since all keys are set to lowercase when importing TODO + # """ + # # Dumps collimator database to a YAML file with optional LHC style formatting + # import re + + # # Local helper functions + # def _format_dict_entry(key, value, spacing='', mapping=False, key_width=15): + # # Formats a dictionary entry into a string for YAML output + # formatted_values = ', '.join(f"{k}: {v}" for k, v in value.items()) + # formatted_values = re.sub(r'none', 'null', formatted_values, flags=re.IGNORECASE) + # # Ensure key has a fixed width for alignment + # if mapping: + # formatted_key = f'{key}'.ljust(key_width) + # else: + # formatted_key = f'{key}:'.ljust(key_width) + # #formatted_values = formatted_values.ljust(key_width) + # return f"{spacing}{formatted_key} {{ {formatted_values} }}\n" + + # def _print_values(keys, dct, file, spacing='', mapping=False): + # # Writes formatted dictionary entries to a file + # for key in keys: + # file.write(_format_dict_entry(key, dct[key], spacing=spacing, mapping=mapping)) + + # def _print_colls(colls, dcts, beam, file): + # # Filters and formats collimator data, then writes to a file + # coll_items_to_print = ['<<','gap','angle','material','active','length','side'] + # file.write(f' {beam}:\n') + # for coll in colls: + # coll_dict = dcts.to_pandas().transpose().to_dict()[coll] + # fam = coll_dict['family'] + # fam_keys = [] + # if fam is not None: + # fam_keys = dcts._family_dict[fam].keys() + # coll_dict = {**{'<<': '*'+fam}, **coll_dict} + # temp_items_to_print = [] + # if coll_dict['crystal'] and str(coll_dict['crystal'])!='nan': + # temp_items_to_print = ['bending_radius','width','height','miscut','crystal'] + # # if 'angle_L' in coll_dict and coll_dict['angle_L'] == coll_dict['angle_R']: + # # coll_dict.update({'angle': coll_dict['angle_L']}) + # # else: + # # temp_items_to_print = temp_items_to_print + ['angle_L','angle_R'] + # # if coll_dict['gap_L'] == coll_dict['gap_R']: + # # coll_dict.update({'gap': coll_dict['gap_L']}) + # # elif coll_dict['gap_L'] is None and coll_dict['gap_R'] is not None: + # # coll_dict.update({'gap': coll_dict['gap_R']}) + # # elif coll_dict['gap_L'] is not None and coll_dict['gap_R'] is None: + # # coll_dict.update({'gap': coll_dict['gap_L']}) + # # else: + # # temp_items_to_print = temp_items_to_print + ['gap_L','gap_R'] + # value = {} + # overwritten_keys = coll_dict['overwritten_keys'] + # for key, val in coll_dict.items(): + # if key == 'active_length': + # key = 'length' + # if (key in coll_items_to_print+temp_items_to_print) and (key not in (set(fam_keys)-set(overwritten_keys))) and (val != 'both'): + # value.update({key: val}) + # file.write(_format_dict_entry(coll, value, spacing=' ')) + # file.write('\n') + + # LHC_families = ['tcp3', 'tcsg3', 'tcsm3', 'tcla3', 'tcp7', 'tcsg7', 'tcsm7', 'tcla7', 'tcli', 'tdi', 'tcdq', 'tcstcdq', 'tcth1', 'tcth2', 'tcth5', 'tcth8', 'tctv1', 'tctv2', 'tctv5', 'tctv8', 'tclp', 'tcxrp', 'tcryo', 'tcl4', 'tcl5', 'tcl6', 'tct15', 'tct2', 'tct8', 'tcsp', 'tcld'] + # with open(f'{out}.yaml', 'w') as file: + # if '_family_dict' in self.__dict__.keys(): + # file.write('families:\n') + # if lhc_style: + # printed_families = [] + # fams_in_dict = self._family_dict.keys() + + # # Momentum cleaning + # file.write(' # Momentum cleaning\n') + # sel_fam = [fam for fam in LHC_families if re.match('.*3', fam) and (fam in fams_in_dict)] + # printed_families += sel_fam + # _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) + + # # Betatron cleaning + # file.write(' # Betatron cleaning\n') + # sel_fam = [fam for fam in LHC_families if re.match('.*7', fam) and (fam in fams_in_dict)] + # printed_families += sel_fam + # _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) + + # # Injection protection + # file.write(' # Injection protection\n') + # sel_fam = [fam for fam in LHC_families if (fam in ['tcli', 'tdi']) and (fam in fams_in_dict)] + # printed_families += sel_fam + # _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) + + # # Dump protection + # file.write(' # Dump protection\n') + # sel_fam = [fam for fam in LHC_families if (fam in ['tcdq', 'tcsp', 'tcstcdq']) and (fam in fams_in_dict)] + # printed_families += sel_fam + # _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) + + # # Physics background / debris + # file.write(' # Physics background / debris\n') + # sel_fam = [fam for fam in LHC_families if ((re.match('tc[lt][0-9dp].*', fam)) or (fam in ['tcryo', 'tcxrp'])) and (fam in fams_in_dict)] + # printed_families += sel_fam + # _print_values(sel_fam, self._family_dict, file, spacing=' - &', mapping=True) + + # # Other families + # if set(printed_families) != set(fams_in_dict): + # file.write(' # Other families\n') + # _print_values(set(fams_in_dict) - set(printed_families), self._family_dict, file, spacing=' - &', mapping=True) + # else: + # file.write(' # Families\n') + # _print_values(self._family_dict.keys(), self._family_dict, file, spacing=' - &', mapping=True) + + # # Emittance section + # ex = self.nemitt_x + # ey = self.nemitt_y + # file.write(f'\nemittance:\n x: {ex}\n y: {ey}\n') + + # # Collimators section + # file.write('\ncollimators:\n') + # b1_colls, b2_colls, bx_colls = [], [], [] + # for coll in self.to_pandas().index: + # if coll == 'tclia.4r2' or coll == 'tclia.4l8': # TODO: hardcoded!!! + # b1_colls.append(coll) + # b2_colls.append(coll) + # elif coll[-2:] == 'b1': + # b1_colls.append(coll) + # elif coll[-2:] == 'b2': + # b2_colls.append(coll) + # else: + # bx_colls.append(coll) + + # # Handle special cases for collimators + # if (('tclia.4r2' in b1_colls) or ('tclia.4l8' in b1_colls)) and (len(b1_colls) <= 2): + # b1_colls = [] + # if (('tclia.4r2' in b2_colls) or ('tclia.4l8' in b2_colls)) and (len(b2_colls) <= 2): + # b2_colls = [] + + # # Print collimators for each beam + # if len(b1_colls) > 0: + # _print_colls(b1_colls, self, 'b1', file) + # if len(b2_colls) > 0: + # _print_colls(b2_colls, self, 'b2', file) + # if len(bx_colls) > 0: + # _print_colls(bx_colls, self, 'bx', file) + # print('WARNING -- some collimators could not be assigned to b1 or b2. Tracking might not work with those collimators. Please manually change the output file if necessary.') # ==================================== @@ -539,27 +541,14 @@ def _check_installed(self, line, name, collimator_class): + f"(or xtrack.Drift)!\nPlease check the name, or correct the " + f"element.") - def _create_collimator(self, line, collimator_class, name, **kwargs): - assert issubclass(collimator_class, BaseCollimator) - self._check_installed(line, name, collimator_class) + def _create_collimator(self, cls, line, name, **kwargs): + self._check_installed(line, name, cls) if kwargs.pop('verbose', False): - print(f"Installing {name:20} as {collimator_class.__name__}") - el = collimator_class(gap=self[name]['gap'], angle=self[name]['angle'], - length=self[name]['length'], side=self[name]['side'], - _tracking=False, **kwargs) - el.emittance = [self.nemitt_x, self.nemitt_y] - self._elements[name] = el - - def _create_crystal(self, line, crystal_class, name, **kwargs): - assert issubclass(crystal_class, BaseCrystal) - self._check_installed(line, name, crystal_class) - if kwargs.pop('verbose', False): - print(f"Installing {name:20} as {crystal_class.__name__}") - el = crystal_class(gap=self[name]['gap'], angle=self[name]['angle'], - length=self[name]['length'], side=self[name]['side'], - bending_radius=self[name]['bending_radius'], - width=self[name]['width'], height=self[name]['height'], - _tracking=False, **kwargs) + print(f"Installing {name:20} as {cls.__name__}") + prop_dict = {kk: vv for kk, vv in self[name].items() \ + if kk in cls._xofields or kk in cls._store_in_to_dict} + prop_dict.update(kwargs) + el = cls(**prop_dict) el.emittance = [self.nemitt_x, self.nemitt_y] self._elements[name] = el @@ -567,9 +556,9 @@ def install_black_absorbers(self, line, *, names=None, families=None, verbose=Fa names = self._get_names_from_line(line, names, families) for name in names: if self[name]['bending_radius'] is None: - self._create_collimator(line, BlackAbsorber, name, verbose=verbose) + self._create_collimator(BlackAbsorber, line, name, verbose=verbose) else: - self._create_crystal(line, BlackCrystal, name, verbose=verbose) + self._create_collimator(BlackCrystal, line, name, verbose=verbose) elements = [self._elements[name] for name in names] line.collimators.install(names, elements, need_apertures=need_apertures) @@ -578,12 +567,11 @@ def install_everest_collimators(self, line, *, names=None, families=None, verbos for name in names: mat = SixTrack_to_xcoll(self[name]['material']) if self[name]['bending_radius'] is None: - self._create_collimator(line, EverestCollimator, name, material=mat[0], + self._create_collimator(EverestCollimator, line, name, material=mat[0], verbose=verbose) else: - self._create_crystal(line, EverestCrystal, name, material=mat[1], - lattice=self[name]['crystal'], verbose=verbose, - miscut=self[name]['miscut']) + self._create_collimator(EverestCrystal, line, name, material=mat[1], + verbose=verbose) elements = [self._elements[name] for name in names] line.collimators.install(names, elements, need_apertures=need_apertures) From 16ff2e26cf900f26f53a35cfd6351a7234eabbf6 Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Fri, 8 Nov 2024 16:29:11 +0100 Subject: [PATCH 4/7] Typo in tilt --- tests/data/colldb_lhc_run3.yaml | 2 +- tests/data/colldb_lhc_run3_b1.json | 2 +- tests/data/colldb_lhc_run3_b1.yaml | 2 +- tests/data/colldb_lhc_run3_b1_no_families.yaml | 2 +- tests/data/colldb_lhc_run3_b1_no_merge.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/data/colldb_lhc_run3.yaml b/tests/data/colldb_lhc_run3.yaml index 82753ca2..d73f51f9 100644 --- a/tests/data/colldb_lhc_run3.yaml +++ b/tests/data/colldb_lhc_run3.yaml @@ -66,7 +66,7 @@ collimators: tcdqa.b4r6.b1: { <<: *TCDQ } tcsp.a4r6.b1: { <<: *TCSP } tcp.d6l7.b1: { <<: *TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } + tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e-6] } tcp.b6l7.b1: { <<: *TCP7, angle: 127.5 } tcsg.a6l7.b1: { <<: *TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { <<: *CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1.json b/tests/data/colldb_lhc_run3_b1.json index d00a420f..e85d90fd 100644 --- a/tests/data/colldb_lhc_run3_b1.json +++ b/tests/data/colldb_lhc_run3_b1.json @@ -253,7 +253,7 @@ "family": "TCP7", "angle": 0, "material": "MoGR", - "tilt": [-250e-6, 250e6] + "tilt": [-250e-6, 250e-6] }, "tcp.b6l7.b1": { "family": "TCP7", diff --git a/tests/data/colldb_lhc_run3_b1.yaml b/tests/data/colldb_lhc_run3_b1.yaml index 0dc36d9e..723c2843 100644 --- a/tests/data/colldb_lhc_run3_b1.yaml +++ b/tests/data/colldb_lhc_run3_b1.yaml @@ -62,7 +62,7 @@ Collimators: tcdqa.b4r6.b1: { <<: *TCDQ } tcsp.a4r6.b1: { <<: *TCSP } tcp.d6l7.b1: { <<: *TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } + tcp.c6l7.b1: { <<: *TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e-6] } tcp.b6l7.b1: { <<: *TCP7, angle: 127.5 } tcsg.a6l7.b1: { <<: *TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { <<: *CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1_no_families.yaml b/tests/data/colldb_lhc_run3_b1_no_families.yaml index b30f61b0..5f22537f 100644 --- a/tests/data/colldb_lhc_run3_b1_no_families.yaml +++ b/tests/data/colldb_lhc_run3_b1_no_families.yaml @@ -30,7 +30,7 @@ tcdqa.c4r6.b1: { gap: 7.3, stage: tertiary, material: C, length: 3, a tcdqa.b4r6.b1: { gap: 7.3, stage: tertiary, material: C, length: 3, angle: 0, parking: 0.025, side: left } tcsp.a4r6.b1: { gap: 7.3, stage: SECONDARY, material: C, Length: 1, angle: 0, parking: 0.025 } TCP.D6l7.B1: { gap: 5, stage: primary, material: MoGR, length: 0.6, angle: 90, parking: 0.025 } -tcp.c6l7.b1: { gap: 5, stage: primary, MATeRIAL: MoGR, length: 0.6, angle: 0, parking: 0.025, tilt: [-250e-6, 250e6] } +tcp.c6l7.b1: { gap: 5, stage: primary, MATeRIAL: MoGR, length: 0.6, angle: 0, parking: 0.025, tilt: [-250e-6, 250e-6] } tcp.b6l7.b1: { gap: 5, stage: primary, material: C, length: 0.6, angle: 127.5, parking: 0.025 } tcsg.a6l7.b1: { gap: 6.5, stage: secondary, material: C, length: 1, angle: 141.1, parking: 0.025 } tcpcv.a6l7.b1: { gap: null, stage: special, material: Si, length: 0.004, angle: 90, parking: 0.025, side: left, crystal: strip, Bending_radius: 85.10, Width: 5.0e-3, height: 30.0e-3 } diff --git a/tests/data/colldb_lhc_run3_b1_no_merge.yaml b/tests/data/colldb_lhc_run3_b1_no_merge.yaml index 3532ddbf..5d3a0551 100644 --- a/tests/data/colldb_lhc_run3_b1_no_merge.yaml +++ b/tests/data/colldb_lhc_run3_b1_no_merge.yaml @@ -62,7 +62,7 @@ Collimators: tcdqa.b4r6.b1: { family: TCDQ } tcsp.a4r6.b1: { family: TCSP } tcp.d6l7.b1: { family: TCP7, angle: 90, material: MoGR } - tcp.c6l7.b1: { family: TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e6] } + tcp.c6l7.b1: { family: TCP7, angle: 0, material: MoGR, tilt: [-250e-6, 250e-6] } tcp.b6l7.b1: { family: TCP7, angle: 127.5 } tcsg.a6l7.b1: { family: TCSG7, angle: 141.1 } tcpcv.a6l7.b1: { family: CRY7, angle: 90, bending_radius: 85.10, width: 5.0e-3, height: 30.0e-3 } From 130796025a2f3fdc5710ba1d6792f32cd7926822 Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Fri, 8 Nov 2024 16:30:52 +0100 Subject: [PATCH 5/7] Limit tilts to [-90,90] degrees, and change jaw nested list logic: now it is [[LU,LD], [RU,RD]]. --- tests/data/all_tests.list | 8 ++++++-- tests/test_elements.py | 8 ++++---- tests/test_impacts.py | 4 ++-- xcoll/beam_elements/base.py | 24 +++++++++++------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tests/data/all_tests.list b/tests/data/all_tests.list index 05a440c6..a913cb6f 100644 --- a/tests/data/all_tests.list +++ b/tests/data/all_tests.list @@ -1,11 +1,15 @@ tests/test_adt.py::test_blow_up[B1H-ContextCpu] tests/test_adt.py::test_blow_up[B1H-ContextCpu:auto] +tests/test_adt.py::test_blow_up[B1H-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B1V-ContextCpu] tests/test_adt.py::test_blow_up[B1V-ContextCpu:auto] +tests/test_adt.py::test_blow_up[B1V-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B2H-ContextCpu] tests/test_adt.py::test_blow_up[B2H-ContextCpu:auto] +tests/test_adt.py::test_blow_up[B2H-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B2V-ContextCpu] tests/test_adt.py::test_blow_up[B2V-ContextCpu:auto] +tests/test_adt.py::test_blow_up[B2V-ContextPyopencl:0.0] tests/test_black_absorber.py::test_with_parallel_beam[ContextCpu] tests/test_black_absorber.py::test_with_parallel_beam[ContextCpu:auto] tests/test_black_absorber.py::test_with_generic_beam[ContextCpu-H] @@ -52,8 +56,6 @@ tests/test_colldb.py::test_loading_no_merge tests/test_colldb.py::test_loading_crystals tests/test_colldb.py::test_loading_SixTrack tests/test_colldb.py::test_loading_SixTrack_crystals -tests/test_colldb.py::test_dumping -tests/test_colldb.py::test_dumping_from_Sixtrack tests/test_elements.py::test_black_absorber[ContextCpu] tests/test_elements.py::test_black_absorber[ContextCpu:auto] tests/test_elements.py::test_black_crystal[ContextCpu] @@ -131,8 +133,10 @@ tests/test_lossmap.py::test_run_lossmap[B2H_crystals-ContextCpu] tests/test_lossmap.py::test_run_lossmap[B2H_crystals-ContextCpu:auto] tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextCpu] tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextCpu:auto] +tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextPyopencl:0.0] tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextCpu] tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextCpu:auto] +tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextPyopencl:0.0] tests/test_transfer_line.py::test_transfer_line[ContextCpu] tests/test_transfer_line.py::test_transfer_line[ContextCpu:auto] tests/test_version.py::test_version diff --git a/tests/test_elements.py b/tests/test_elements.py index 777617eb..17110aa8 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -96,10 +96,10 @@ {'field': 'angle', 'val': 40, 'expected': {'_sin_zL': np.sin(40*np.pi/180), '_cos_zL': np.cos(40*np.pi/180), '_sin_zR': np.sin(40*np.pi/180), '_cos_zR': np.cos(40*np.pi/180)}}, {'field': 'angle', 'val': [40], 'expected': {'_sin_zL': np.sin(40*np.pi/180), '_cos_zL': np.cos(40*np.pi/180), '_sin_zR': np.sin(40*np.pi/180), '_cos_zR': np.cos(40*np.pi/180)}}, {'field': 'angle', 'val': [40, 47], 'expected': {'_sin_zL': np.sin(40*np.pi/180), '_cos_zL': np.cos(40*np.pi/180), '_sin_zR': np.sin(47*np.pi/180), '_cos_zR': np.cos(47*np.pi/180)}}, - {'field': 'jaw', 'val': 0.015, 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.015, 'jaw_LD': 0.01488, 'jaw_RD': -0.015, 'jaw_L': 0.015, 'jaw_R': -0.015, 'jaw': [[0.01512, -0.015], [0.01488, -0.015]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, # Existing tilt from base_fields - {'field': 'jaw', 'val': [0.015], 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.015, 'jaw_LD': 0.01488, 'jaw_RD': -0.015, 'jaw_L': 0.015, 'jaw_R': -0.015, 'jaw': [[0.01512, -0.015], [0.01488, -0.015]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, - {'field': 'jaw', 'val': [0.015, -0.014], 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.014, 'jaw_LD': 0.01488, 'jaw_RD': -0.014, 'jaw_L': 0.015, 'jaw_R': -0.014, 'jaw': [[0.01512, -0.014], [0.01488, -0.014]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, - {'field': 'jaw', 'val': [[0.015, -0.014],[0.0152, -0.0143]], 'expected': {'jaw_LU': 0.015, 'jaw_RU': -0.014, 'jaw_LD': 0.0152, 'jaw_RD': -0.0143, 'jaw_L': 0.0151, 'jaw_R': -0.01415, 'jaw': [[0.015, -0.014], [0.0152, -0.0143]], 'tilt_L': 0.0001538462, 'tilt_R': -0.0002307692}}, + {'field': 'jaw', 'val': 0.015, 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.015, 'jaw_LD': 0.01488, 'jaw_RD': -0.015, 'jaw_L': 0.015, 'jaw_R': -0.015, 'jaw': [[0.01512, 0.01488], [-0.015, -0.015]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, # Existing tilt from base_fields + {'field': 'jaw', 'val': [0.015], 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.015, 'jaw_LD': 0.01488, 'jaw_RD': -0.015, 'jaw_L': 0.015, 'jaw_R': -0.015, 'jaw': [[0.01512, 0.01488], [-0.015, -0.015]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, + {'field': 'jaw', 'val': [0.015, -0.014], 'expected': {'jaw_LU': 0.01512, 'jaw_RU': -0.014, 'jaw_LD': 0.01488, 'jaw_RD': -0.014, 'jaw_L': 0.015, 'jaw_R': -0.014, 'jaw': [[0.01512, 0.01488], [-0.014, -0.014]], 'tilt_L': -0.0001692308, 'tilt_R': 0}}, + {'field': 'jaw', 'val': [[0.015, 0.0152], [-0.014, -0.0143]], 'expected': {'jaw_LU': 0.015, 'jaw_RU': -0.014, 'jaw_LD': 0.0152, 'jaw_RD': -0.0143, 'jaw_L': 0.0151, 'jaw_R': -0.01415, 'jaw': [[0.015, 0.0152], [-0.014, -0.0143]], 'tilt_L': 0.0001538462, 'tilt_R': -0.0002307692}}, {'field': 'tilt', 'val': 5.2e-3, 'expected': {'_sin_yL': np.sin(5.2e-3), '_cos_yL': np.cos(5.2e-3), '_sin_yR': np.sin(5.2e-3), '_cos_yR': np.cos(5.2e-3), '_tan_yL': np.tan(5.2e-3), '_tan_yR': np.tan(5.2e-3), 'jaw_LU': 0.01172001523251274, 'jaw_RU': -0.01752998476748726, 'jaw_LD': 0.018479984767487263, 'jaw_RD': -0.010770015232512739, 'jaw_L': 0.0151, 'jaw_R': -0.01415}}, {'field': 'tilt', 'val': [5.2e-3], 'expected': {'_sin_yL': np.sin(5.2e-3), '_cos_yL': np.cos(5.2e-3), '_sin_yR': np.sin(5.2e-3), '_cos_yR': np.cos(5.2e-3), '_tan_yL': np.tan(5.2e-3), '_tan_yR': np.tan(5.2e-3), 'jaw_LU': 0.01172001523251274, 'jaw_RU': -0.01752998476748726, 'jaw_LD': 0.018479984767487263, 'jaw_RD': -0.010770015232512739, 'jaw_L': 0.0151, 'jaw_R': -0.01415}}, {'field': 'tilt', 'val': [5.2e-3, 3.7e-3], 'expected': {'_sin_yL': np.sin(5.2e-3), '_cos_yL': np.cos(5.2e-3), '_sin_yR': np.sin(3.7e-3), '_cos_yR': np.cos(3.7e-3), '_tan_yL': np.tan(5.2e-3), '_tan_yR': np.tan(3.7e-3), 'jaw_LU': 0.01172001523251274, 'jaw_RU': -0.01655499451259542, 'jaw_LD': 0.018479984767487263, 'jaw_RD': -0.011745005487404576, 'jaw_L': 0.0151, 'jaw_R': -0.01415}}, diff --git a/tests/test_impacts.py b/tests/test_impacts.py index 26d8da49..b422bb17 100644 --- a/tests/test_impacts.py +++ b/tests/test_impacts.py @@ -28,8 +28,8 @@ [2, 'H']], ids=["B1H", "B2V", "B1V", "B2H"]) def test_impacts_from_line(beam, plane, test_context): line = xt.Line.from_json(path / f'sequence_lhc_run3_b{beam}.json') - coll_manager = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=beam) - coll_manager.install_everest_collimators(verbose=True, line=line) + colldb = xc.CollimatorDatabase.from_yaml(path / 'colldb_lhc_run3.yaml', beam=beam) + colldb.install_everest_collimators(verbose=True, line=line) df_with_coll = line.check_aperture() assert not np.any(df_with_coll.has_aperture_problem) diff --git a/xcoll/beam_elements/base.py b/xcoll/beam_elements/base.py index 749531ed..634ad3b0 100644 --- a/xcoll/beam_elements/base.py +++ b/xcoll/beam_elements/base.py @@ -200,10 +200,7 @@ def __init__(self, **kwargs): # We do not allow any combination of jaw_ and gap_ attributes # (except when jaw=..., gap=None or jaw=None, gap=... is used, as this is how the colldb installs it) - if 'jaw' in kwargs and kwargs['jaw'] is None: - kwargs.pop('jaw') - if 'gap' in kwargs and kwargs['gap'] is None: - kwargs.pop('gap') + kwargs = {kk: vv for kk, vv in kwargs.items() if not vv is None} # Set jaw if 'jaw' in kwargs: @@ -340,7 +337,7 @@ def jaw(self): or (self.tilt_L == 0 and self.tilt_R == 0): return [self.jaw_L, self.jaw_R] else: - return [[self.jaw_LU, self.jaw_RU], [self.jaw_LD, self.jaw_RD]] + return [[self.jaw_LU, self.jaw_LD], [self.jaw_RU, self.jaw_RD]] @jaw.setter # Keeps the tilts unless all 4 corners are specified def jaw(self, val): @@ -359,8 +356,8 @@ def jaw(self, val): if hasattr(val[0], '__iter__'): if hasattr(val[1], '__iter__') and len(val[0]) == 2 and len(val[1]) == 2: self.jaw_LU = val[0][0] - self.jaw_RU = val[0][1] - self.jaw_LD = val[1][0] + self.jaw_LD = val[0][1] + self.jaw_RU = val[1][0] self.jaw_RD = val[1][1] return else: @@ -563,6 +560,8 @@ def tilt_L(self, val): print("Warning: Setting a tilt does not preserve the hierarchy, as there " + "will always be one corner that tightens (the tilt is applied at " + "the centre of the jaw).") + if val > np.pi/2 or val < -np.pi/2: + raise ValueError("Tilts larger than 90 degrees are not supported.") self._sin_yL = np.sin(val) self._cos_yL = np.cos(val) self._tan_yL = np.tan(val) @@ -584,6 +583,8 @@ def tilt_R(self, val): print("Warning: Setting a tilt does not preserve the hierarchy, as there " + "will always be one corner that tightens (the tilt is applied at " + "the centre of the jaw).") + if val > np.pi/2 or val < -np.pi/2: + raise ValueError("Tilts larger than 90 degrees are not supported.") self._sin_yR = np.sin(val) self._cos_yR = np.cos(val) self._tan_yR = np.tan(val) @@ -972,8 +973,6 @@ def _verify_consistency(self): assert self._jaws_parallel == False assert np.isclose(self._sin_zDiff, self._cos_zL*self._sin_zR - self._sin_zL*self._cos_zR) assert np.isclose(self._cos_zDiff, self._cos_zL*self._cos_zR + self._sin_zL*self._sin_zR) - if self.side == 'both' and abs(self.tilt_L - self.tilt_R) >= 90.: - raise ValueError("Tilts of both jaws differ more than 90 degrees!") if self.side != 'right': ang = abs(np.arccos(self._cos_yL)) ang = np.pi - ang if ang > np.pi/2 else ang @@ -1067,10 +1066,7 @@ def __init__(self, **kwargs): # We do not allow any combination of jaw_ and gap_ attributes # (except when jaw=..., gap=None or jaw=None, gap=... is used, as this is how the colldb installs it) - if 'jaw' in kwargs and kwargs['jaw'] is None: - kwargs.pop('jaw') - if 'gap' in kwargs and kwargs['gap'] is None: - kwargs.pop('gap') + kwargs = {kk: vv for kk, vv in kwargs.items() if not vv is None} # Set jaw @@ -1229,6 +1225,8 @@ def tilt(self, val): if val > min(0, -self.bending_angle/2): print("Warning: Setting a positive tilt does not preserve the hierarchy, as the " + "crystal tightens towards the beam.") + if val > np.pi/2 or val < -np.pi/2: + raise ValueError("Tilts larger than 90 degrees are not supported.") self._sin_y = np.sin(val) self._cos_y = np.cos(val) self._tan_y = np.tan(val) From d1c1c9ad9c006a57d4c48f62fd685ac5aeb1f0b7 Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Fri, 8 Nov 2024 19:02:45 +0100 Subject: [PATCH 6/7] Updated test --- tests/data/all_tests.list | 6 ------ tests/data/assert_listing.py | 2 +- tests/test_initial_distribution.py | 8 ++++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/data/all_tests.list b/tests/data/all_tests.list index a913cb6f..58942cd5 100644 --- a/tests/data/all_tests.list +++ b/tests/data/all_tests.list @@ -1,15 +1,11 @@ tests/test_adt.py::test_blow_up[B1H-ContextCpu] tests/test_adt.py::test_blow_up[B1H-ContextCpu:auto] -tests/test_adt.py::test_blow_up[B1H-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B1V-ContextCpu] tests/test_adt.py::test_blow_up[B1V-ContextCpu:auto] -tests/test_adt.py::test_blow_up[B1V-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B2H-ContextCpu] tests/test_adt.py::test_blow_up[B2H-ContextCpu:auto] -tests/test_adt.py::test_blow_up[B2H-ContextPyopencl:0.0] tests/test_adt.py::test_blow_up[B2V-ContextCpu] tests/test_adt.py::test_blow_up[B2V-ContextCpu:auto] -tests/test_adt.py::test_blow_up[B2V-ContextPyopencl:0.0] tests/test_black_absorber.py::test_with_parallel_beam[ContextCpu] tests/test_black_absorber.py::test_with_parallel_beam[ContextCpu:auto] tests/test_black_absorber.py::test_with_generic_beam[ContextCpu-H] @@ -133,10 +129,8 @@ tests/test_lossmap.py::test_run_lossmap[B2H_crystals-ContextCpu] tests/test_lossmap.py::test_run_lossmap[B2H_crystals-ContextCpu:auto] tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextCpu] tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextCpu:auto] -tests/test_rf_sweep.py::test_rf_sweep[DP pos-ContextPyopencl:0.0] tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextCpu] tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextCpu:auto] -tests/test_rf_sweep.py::test_rf_sweep[DP neg-ContextPyopencl:0.0] tests/test_transfer_line.py::test_transfer_line[ContextCpu] tests/test_transfer_line.py::test_transfer_line[ContextCpu:auto] tests/test_version.py::test_version diff --git a/tests/data/assert_listing.py b/tests/data/assert_listing.py index cb26cc6a..47ad0010 100755 --- a/tests/data/assert_listing.py +++ b/tests/data/assert_listing.py @@ -36,4 +36,4 @@ def pytest_collection_modifyitems(self, session, config, items): sys.exit("Please run data/store_all_tests.py as there are some new " + "tests that are not logged yet:\n" + '\n'.join(only_current)) if len(only_expected) > 0: - sys.exit("The following tests were expected but not found:\n" + '\n'.join(only_expected)) + sys.exit("The following tests were expected but not found:\n" + '\n'.join(only_expected) + "Please run data/store_all_tests.py") diff --git a/tests/test_initial_distribution.py b/tests/test_initial_distribution.py index 5432eeac..bf1e9a16 100644 --- a/tests/test_initial_distribution.py +++ b/tests/test_initial_distribution.py @@ -70,7 +70,7 @@ def test_create_initial_distribution(beam, npart,impact_parameter, pencil_spread with flaky_assertions(): # Pencil: left jaw - pos_jawL_conv = coll_conv.jaw_L + pos_jawL_conv = coll_conv.jaw_LU pos_partL_conv = part_conv.x[mask_conv_L].min() pencil_spread_convL = part_conv.x[mask_conv_L].max() - pos_partL_conv assert np.isclose(pencil_spread_convL, pencil_spread, atol=atol_spread) @@ -78,7 +78,7 @@ def test_create_initial_distribution(beam, npart,impact_parameter, pencil_spread assert pos_partL_conv - impact_parameter - pos_jawL_conv > 0 # Pencil: right jaw - pos_jawR_conv = coll_conv.jaw_R + pos_jawR_conv = coll_conv.jaw_RU pos_partR_conv = part_conv.x[mask_conv_R].max() pencil_spread_convR = pos_partR_conv - part_conv.x[mask_conv_R].min() assert np.isclose(pencil_spread_convR, pencil_spread, atol=atol_spread) @@ -117,7 +117,7 @@ def test_create_initial_distribution(beam, npart,impact_parameter, pencil_spread with flaky_assertions(): # Pencil: left jaw - pos_jawL_div = coll_div.jaw_L + pos_jawL_div = coll_div.jaw_LD pos_partL_div = part_div.y[mask_div_L].min() pencil_spread_divL = part_div.y[mask_div_L].max() - pos_partL_div assert np.isclose(pencil_spread_divL, pencil_spread, atol=atol_spread) @@ -125,7 +125,7 @@ def test_create_initial_distribution(beam, npart,impact_parameter, pencil_spread assert pos_partL_div - impact_parameter - pos_jawL_div > 0 # Pencil: right jaw - pos_jawR_div = coll_div.jaw_R + pos_jawR_div = coll_div.jaw_RD pos_partR_div = part_div.y[mask_div_R].max() pencil_spread_divR = pos_partR_div - part_div.y[mask_div_R].min() assert np.isclose(pencil_spread_divR, pencil_spread, atol=atol_spread) From 3d6ebe13e4e2fe33e969f9a8196ccfda3b22233a Mon Sep 17 00:00:00 2001 From: Frederik Van der Veken Date: Fri, 8 Nov 2024 19:06:20 +0100 Subject: [PATCH 7/7] Updated version number to v0.5.10. --- pyproject.toml | 4 ++-- tests/test_version.py | 2 +- xcoll/general.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9ec6895a..a78776df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "xcoll" -version = "0.5.10rc0" +version = "0.5.10" description = "Xsuite collimation package" homepage = "https://github.com/xsuite/xcoll" repository = "https://github.com/xsuite/xcoll" @@ -26,7 +26,7 @@ ruamel-yaml = { version = "^0.17.31", optional = true } numpy = ">=1.0" pandas = ">=1.4" xobjects = ">=0.4.5" -xdeps = ">=0.7.3" +xdeps = ">=0.7.4" xpart = ">=0.19.1" xtrack = ">=0.69.7" diff --git a/tests/test_version.py b/tests/test_version.py index 29a3fe4b..5bf4e1aa 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -6,4 +6,4 @@ from xcoll import __version__ def test_version(): - assert __version__ == '0.5.10rc0' + assert __version__ == '0.5.10' diff --git a/xcoll/general.py b/xcoll/general.py index 9d009650..2e9458ee 100644 --- a/xcoll/general.py +++ b/xcoll/general.py @@ -12,5 +12,5 @@ # ====================== # Do not change # ====================== -__version__ = '0.5.10rc0' +__version__ = '0.5.10' # ======================