-
Notifications
You must be signed in to change notification settings - Fork 0
Xsuite Conversion to Tbt Objects #23
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
Merged
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4a2a5b0
First attempt at xtrack implementation
jgray-19 269276b
Add xtrack to the toml
jgray-19 d4e6081
Toml again?
jgray-19 f594135
Add setuptools to toml
jgray-19 0e0291e
License update (for xtrack)
jgray-19 f5453ea
More setuptools xsuite stuff
jgray-19 af2aa3a
Add xpart
jgray-19 24d9fde
Fix typo
jgray-19 ed3adb8
Fix floating-point representation in example_line fixture
jgray-19 a9e2965
Add platform check for xtrack kernel compilation in test_convert_xsuite
jgray-19 1804ac0
Enhance MAD-NG and XTRACK modules with improved error handling and ad…
jgray-19 18ca2e9
Refactor variable names for clarity in MAD-NG and enhance documentati…
jgray-19 f4ba3f0
Improve documentation in MAD-NG module with clearer descriptions and …
jgray-19 5f4ad71
Update turn_by_turn/madng.py
jgray-19 1be3165
Update pyproject.toml
jgray-19 1655685
Update turn_by_turn/xtrack.py
jgray-19 0383609
Remove unnecessary TYPE_CHECKING import and adjust type hint for conv…
jgray-19 612f762
Refactor tests and modules to improve consistency and clarity; update…
jgray-19 67b80a7
Update documentation and improve code clarity; disable display_versio…
jgray-19 46c0fc8
Enhance documentation for turn_by_turn; add usage examples for read_t…
jgray-19 f8278de
Remove load_tbt_data import from package namespace
jgray-19 3337d79
Fix ImportError handling for tfs package in write_tbt function
jgray-19 2bd2a14
Enhance docstring for example_line fixture to clarify its purpose and…
jgray-19 337a340
Some ruff formatting
jgray-19 c612290
Refactor documentation in index.rst and io.py for clarity and structu…
jgray-19 aff359a
Reorder import statements in __init__.py for consistency
jgray-19 d6dfba0
minor stuff
JoschD 24cc58d
added API header
JoschD 1d0b150
Improve formatting in test_xtrack.py and xtrack_line.py.
jgray-19 283b751
Refactor particle ID handling in convert_to_tbt for clarity and consi…
jgray-19 49f7d04
Clarify type annotations in convert_to_tbt functions for consistency …
jgray-19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,3 @@ | |
| .. automodule:: turn_by_turn.utils | ||
| :members: | ||
| :noindex: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest | ||
| from turn_by_turn.structures import TbtData, TransverseData | ||
|
|
||
| @pytest.fixture(scope="session") | ||
jgray-19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def example_fake_tbt(): | ||
jgray-19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Returns a TbtData object using simulation data taken from MAD-NG. | ||
| This data is also used for the tests in xtrack, so change the numbers | ||
| at your own risk. | ||
|
|
||
| It is possible to run the MAD-NG in the inputs folder to regenerate the data. | ||
| Also, xtrack produces the same data, so you can use the xtrack test fixture | ||
| `example_line`. | ||
| """ | ||
| names = np.array(["BPM1", "BPM3", "BPM2"]) | ||
| # First BPM | ||
| bpm1_p1_x = np.array([ 1e-3, 0.002414213831,-0.0009999991309]) | ||
| bpm1_p1_y = np.array([-1e-3, 0.0004142133507, 0.001000000149]) | ||
| bpm1_p2_x = np.array([-1e-3,-0.002414213831, 0.0009999991309]) | ||
| bpm1_p2_y = np.array([ 1e-3,-0.0004142133507,-0.001000000149]) | ||
|
|
||
| # Second BPM | ||
| bpm3_p1_x = np.array([ 0.002414213831,-0.0009999991309,-0.002414214191]) | ||
| bpm3_p1_y = np.array([ 0.0004142133507, 0.001000000149,-0.0004142129907]) | ||
| bpm3_p2_x = np.array([-0.002414213831, 0.0009999991309, 0.002414214191]) | ||
| bpm3_p2_y = np.array([-0.0004142133507,-0.001000000149, 0.0004142129907]) | ||
|
|
||
| # Third BPM | ||
| bpm2_p1_x = np.array([-0.0009999999503,-0.0004142138307, 0.0009999998012]) | ||
| bpm2_p1_y = np.array([ 0.00100000029,-0.002414213351,-0.001000001159]) | ||
| bpm2_p2_x = np.array([ 0.0009999999503, 0.0004142138307,-0.0009999998012]) | ||
| bpm2_p2_y = np.array([-0.00100000029, 0.002414213351, 0.001000001159]) | ||
|
|
||
| matrix = [ | ||
| TransverseData( # first particle | ||
| X=pd.DataFrame(index=names, data=[bpm1_p1_x, bpm2_p1_x, bpm3_p1_x]), | ||
| Y=pd.DataFrame(index=names, data=[bpm1_p1_y, bpm2_p1_y, bpm3_p1_y]), | ||
| ), | ||
| TransverseData( # second particle | ||
| X=pd.DataFrame(index=names, data=[bpm1_p2_x, bpm2_p2_x, bpm3_p2_x]), | ||
| Y=pd.DataFrame(index=names, data=[bpm1_p2_y, bpm2_p2_y, bpm3_p2_y]), | ||
| ), | ||
| ] | ||
| return TbtData(matrices=matrix, bunch_ids=[0, 1], nturns=3) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,46 @@ | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import pytest | ||
| from pathlib import Path | ||
|
|
||
| from tests.test_lhc_and_general import INPUTS_DIR, compare_tbt | ||
| from turn_by_turn import madng, read_tbt, write_tbt | ||
| from turn_by_turn.structures import TbtData, TransverseData | ||
| from turn_by_turn.structures import TbtData | ||
|
|
||
|
|
||
| def test_read_ng(_ng_file): | ||
| original = _original_simulation_data() | ||
|
|
||
| def test_read_ng(_ng_file: Path, example_fake_tbt: TbtData): | ||
| # Check directly from the module | ||
| new = madng.read_tbt(_ng_file) | ||
| compare_tbt(original, new, no_binary=True) | ||
| compare_tbt(example_fake_tbt, new, no_binary=True) | ||
|
|
||
| # Check from the main function | ||
| new = read_tbt(_ng_file, datatype="madng") | ||
| compare_tbt(original, new, no_binary=True) | ||
| compare_tbt(example_fake_tbt, new, no_binary=True) | ||
|
|
||
| def test_write_ng(_ng_file, tmp_path): | ||
| original_tbt = _original_simulation_data() | ||
|
|
||
| def test_write_ng(_ng_file: Path, tmp_path: Path, example_fake_tbt: TbtData): | ||
| # Write the data | ||
| from_tbt = tmp_path / "from_tbt.tfs" | ||
| madng.write_tbt(from_tbt, original_tbt) | ||
| madng.write_tbt(from_tbt, example_fake_tbt) | ||
|
|
||
| # Read the written data | ||
| new_tbt = madng.read_tbt(from_tbt) | ||
| compare_tbt(original_tbt, new_tbt, no_binary=True) | ||
| compare_tbt(example_fake_tbt, new_tbt, no_binary=True) | ||
|
|
||
| # Check from the main function | ||
| original_tbt = read_tbt(_ng_file, datatype="madng") | ||
| write_tbt(from_tbt, original_tbt, datatype="madng") | ||
| written_tbt = read_tbt(_ng_file, datatype="madng") | ||
| write_tbt(from_tbt, written_tbt, datatype="madng") | ||
|
|
||
| new_tbt = read_tbt(from_tbt, datatype="madng") | ||
| compare_tbt(original_tbt, new_tbt, no_binary=True) | ||
| assert original_tbt.date == new_tbt.date | ||
| compare_tbt(written_tbt, new_tbt, no_binary=True) | ||
| assert written_tbt.date == new_tbt.date | ||
|
|
||
| def test_error_ng(_error_file): | ||
| def test_error_ng(_error_file: Path): | ||
| with pytest.raises(ValueError): | ||
| read_tbt(_error_file, datatype="madng") | ||
|
|
||
| # ---- Helpers ---- # | ||
| def _original_simulation_data() -> TbtData: | ||
| # Create a TbTData object with the original data | ||
| names = np.array(["BPM1", "BPM3", "BPM2"]) | ||
| bpm1_p1_x = np.array([ 1e-3, 0.002414213831,-0.0009999991309]) | ||
| bpm1_p1_y = np.array([-1e-3, 0.0004142133507, 0.001000000149]) | ||
| bpm1_p2_x = np.array([-1e-3,-0.002414213831, 0.0009999991309]) | ||
| bpm1_p2_y = np.array([ 1e-3,-0.0004142133507,-0.001000000149]) | ||
|
|
||
| bpm2_p1_x = np.array([-0.0009999999503,-0.0004142138307, 0.0009999998012]) | ||
| bpm2_p1_y = np.array([ 0.00100000029,-0.002414213351,-0.001000001159]) | ||
| bpm2_p2_x = np.array([ 0.0009999999503, 0.0004142138307,-0.0009999998012]) | ||
| bpm2_p2_y = np.array([-0.00100000029, 0.002414213351, 0.001000001159]) | ||
|
|
||
| bpm3_p1_x = np.array([ 0.002414213831,-0.0009999991309,-0.002414214191]) | ||
| bpm3_p1_y = np.array([ 0.0004142133507, 0.001000000149,-0.0004142129907]) | ||
| bpm3_p2_x = np.array([-0.002414213831, 0.0009999991309, 0.002414214191]) | ||
| bpm3_p2_y = np.array([-0.0004142133507,-0.001000000149, 0.0004142129907]) | ||
|
|
||
| matrix = [ | ||
| TransverseData( # first particle | ||
| X=pd.DataFrame(index=names, data=[bpm1_p1_x, bpm2_p1_x, bpm3_p1_x]), | ||
| Y=pd.DataFrame(index=names, data=[bpm1_p1_y, bpm2_p1_y, bpm3_p1_y]), | ||
| ), | ||
| TransverseData( # second particle | ||
| X=pd.DataFrame(index=names, data=[bpm1_p2_x, bpm2_p2_x, bpm3_p2_x]), | ||
| Y=pd.DataFrame(index=names, data=[bpm1_p2_y, bpm2_p2_y, bpm3_p2_y]), | ||
| ), | ||
| ] | ||
| return TbtData(matrices=matrix, bunch_ids=[1, 2], nturns=3) | ||
|
|
||
|
|
||
| # ---- Fixtures ---- # | ||
| @pytest.fixture | ||
| def _ng_file(tmp_path): | ||
| def _ng_file(tmp_path: Path) -> Path: | ||
| return INPUTS_DIR / "madng" / "fodo_track.tfs" | ||
|
|
||
| @pytest.fixture | ||
| def _error_file(tmp_path): | ||
| def _error_file(tmp_path: Path) -> Path: | ||
| return INPUTS_DIR / "madng" / "fodo_track_error.tfs" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.