-
Notifications
You must be signed in to change notification settings - Fork 4
MAD-NG Features and Compatibility Modes #135
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 all commits
Commits
Show all changes
435 commits
Select commit
Hold shift + click to select a range
3c5c2c3
update that part of the readme with compatibility too
fsoubelet 1c19e6e
update that part of the readme with compatibility too
fsoubelet 318fdb8
ignore type checking import blocks for coverage
fsoubelet 3458ed1
and also these statements
fsoubelet 3389afe
its a start
fsoubelet 3f28a2e
add some to changelog
fsoubelet b704abf
more info
fsoubelet a30d03c
add this too
fsoubelet f845033
rephrase
fsoubelet 784cf43
phrasing again
fsoubelet f0d1825
rephrasing and table format
fsoubelet 3ec774a
MADNG only and admonition about complex representation
fsoubelet 44d01de
should be almost complete
fsoubelet f723f62
flaky in object mode
fsoubelet c4d0e95
small iterations left maybe but let's call this a day
fsoubelet af2bea5
also exported
fsoubelet 47ad9e3
details
fsoubelet 09f29f8
some rewording
JoschD 732a2a0
forgotten save
JoschD 652778b
more to dooooooo
fsoubelet 780db46
and more
fsoubelet 587a4a6
better installation instructions
fsoubelet 1cd1ca9
replace deprecated sphinx-rtd-theme option 'display_version' (since 3.0)
fsoubelet 6366ccf
formatting
fsoubelet f42982e
formatting
fsoubelet cc6011c
expand a tad on validation, add mini section (link) to quickstart
fsoubelet dc4898d
better explained like this
fsoubelet e94a069
simpler, faster version of the headers_dict check (waiting for the ex…
fsoubelet 0aad6ef
test for writing of pd dataframe
fsoubelet bc575c6
and that is done
fsoubelet a3a917d
specifics and writing without headers
fsoubelet 93baf2f
and specify # is for comment lines
fsoubelet 93a363e
no need for todo file anymore
fsoubelet a3d6af9
formatting again
fsoubelet e2de680
list all accepted forms in changelog
fsoubelet 58c1f13
indicate alternate accepted forms here
fsoubelet 694e091
not using this file either
fsoubelet d075dd2
add admonition about unsupported exotic MAD-NG features
fsoubelet a0cfb73
compatibility typo
fsoubelet 783b1c1
more typo
fsoubelet 0f2a0fa
out of scope, not necessarily true
fsoubelet 0cdcd03
actually MAD-NG compliant file
fsoubelet 1ff4c89
actually MAD-NG compliant file
fsoubelet 87cb821
actually MAD-NG compliant file
fsoubelet d090c66
fix example tfs, specify integer type identifier is only MAD-X since …
fsoubelet d22e036
correct info about the length in type identifier
fsoubelet 98581e3
explain much more for the next devs
fsoubelet 04c6f95
convert integer headers to float in MADNG mode - NEEDS TESTING
fsoubelet 51d0c2c
test for headers conversion in MADNG mode
fsoubelet 1fe1c73
it can be i or I according to Laurent
fsoubelet e25d53c
change some is to Is in test files
fsoubelet ab3a152
update compressed versions
fsoubelet d6506c7
include info about i and I
fsoubelet 6357b7d
default compression extra for pandas, add pymadng in test deps
fsoubelet 5c8899e
correct info since Laurent makes the change to MAD-NG for %XXs
fsoubelet 43f844c
more pythonic
fsoubelet fc741f8
more sense
fsoubelet 662aec5
extra check in MADX mode for a TYPE headers
fsoubelet 3d31eb1
phrasing
fsoubelet f5acf3e
specify here that we add a TYPE in MADX mode if not present
fsoubelet c15c39a
todo
fsoubelet 29b5139
remove tfs doc info about %d and MADNG as it will be handled next rel…
fsoubelet 2e25e70
TEMPORARY - Accept %i for integer identifier when reading, with TODO
fsoubelet baa5c4b
we don't have to convert int headers to float anymore as MADNG will a…
fsoubelet eec2834
which means this test goes away too
fsoubelet 15adca2
some info here
fsoubelet 6dea357
add todo to be replaced when we have info on the next released MAD-NG…
fsoubelet e6a1e7b
with next MADNG release this is both MADX and MADNG
fsoubelet bf4d153
some todo and tentative %i addition
fsoubelet 84e8d71
some todo
fsoubelet 8876bc7
todo
fsoubelet e1d2665
do it now - move these warning tests to validation as that's what is …
fsoubelet b815e28
and reformat
fsoubelet 2f7fcec
skeleton for pymadng test
fsoubelet fc5794e
its a nope on the %i for integers
fsoubelet eaf534a
it's the default anyway
fsoubelet 354f003
willing to demonstrate uv
fsoubelet 45f3086
last test
fsoubelet 991a4c3
with updates there
fsoubelet 3f21006
back to master
fsoubelet e19af1f
Implement review suggestion
fsoubelet 7bc9444
revert this too
fsoubelet 0dfd26c
suggestions
fsoubelet ac5e3b3
suggestions
fsoubelet 5425911
point to the doc page for TFS
fsoubelet d52e483
adding 91 ref
fsoubelet ee9b97e
suggestions
fsoubelet 841a857
suggestions
fsoubelet a4d5860
suggestions
fsoubelet 6274b77
suggestions
fsoubelet 8bdea97
suggestions
fsoubelet 51f621a
suggestions, check string dtype here
fsoubelet 56c3962
should be an or here
fsoubelet e519646
suggestions
fsoubelet c83a34c
suggestions
fsoubelet ecc4dfb
use _parse_complex, add comments
fsoubelet ef7c09c
suggestions
fsoubelet 1dcc9b2
suggestions
fsoubelet e46e495
suggestions
fsoubelet 95d1935
suggestions
fsoubelet e4dafae
fix duplicate
fsoubelet b70b6cb
adapt docstring for validate
fsoubelet b2d8fec
skip validation on None only
fsoubelet c2c6a54
these should then be None
fsoubelet 0f28ceb
suggestions
fsoubelet 7c59cd2
suggestions
fsoubelet 38c7a8f
SUPPORTED_EXTENSIONS constant
fsoubelet ce93229
should handle Path?
fsoubelet bce772b
only cast the Paths
fsoubelet 3cec9df
add validation trigger tests from reader and writer
fsoubelet 07a83b0
do not expand path form when converting
fsoubelet 1def6b1
rename formatter class
fsoubelet 67e2880
membership test should be not in
fsoubelet f90b9e5
unused imports
fsoubelet 4b4e80d
more explicit, above comment
fsoubelet ca138b3
be a bit more explicit here too
fsoubelet 89ffc9a
boop
fsoubelet 164185f
another comment gone
fsoubelet e44e7d2
backticks for my boii
fsoubelet 9726187
include tables in that admonition too
fsoubelet 54071e7
clearer names here
fsoubelet dac0508
more explicit here too
fsoubelet 21f7819
add raise info to docstring
fsoubelet a7f9506
more docstring info
fsoubelet e550017
some more comments
fsoubelet 549ffad
propagate the function namechange here too
fsoubelet 716bc5a
comment again
fsoubelet b52b7ac
accept nil as a NaN value
fsoubelet 416d5a8
add some nil here
fsoubelet 9652f17
comment about the nils
fsoubelet 7cda8c9
more comment
fsoubelet ca501a5
should be only nans here
fsoubelet c8924a4
we can now handle NaN and nil in the headers too, so reader is ok
fsoubelet bb3b132
add tests for reading nil in headers and in data
fsoubelet be7675e
add test file with nils
fsoubelet 931fef1
also check headers values for unphysical ones
fsoubelet 0c3adc7
and a test for it
fsoubelet 58a2795
properly return %n for nan/nil dtypes
fsoubelet bd2a8e8
more info
fsoubelet 401a60b
only nils in here
fsoubelet fa377bb
have NoneType in here for %n
fsoubelet 84297a0
infer from NoneType to return None
fsoubelet 4316702
fix behaviour in tests - headers cast to None, data to NaN
fsoubelet 05b84c0
should work on 3.9 too
fsoubelet 6d18ee5
also no need for NoneType here
fsoubelet 45bb12b
docstring fix
fsoubelet e7ea2f9
nil is NoneType
fsoubelet 7a9cc9e
admonition here about nullable behaviour in tfspandas
fsoubelet 93bb4c7
this should be an empty line
fsoubelet e4b2629
correct info here
fsoubelet ec065d8
nil tests comments correction, check all columns with nils
fsoubelet bd1303a
correct this
fsoubelet 2239466
simple nan in headers validation
fsoubelet a7aac7f
more info about the NaN in numeric columns
fsoubelet e2da112
more comment
fsoubelet 7d5d019
intercept None values actually for %n and nil
fsoubelet 8e8bd58
special handling of nullables, can write %n nil just fine in headers …
fsoubelet c406a54
info
fsoubelet 28a2f60
writes None in columns as nil properly but formatting is messed up
fsoubelet b366443
None making its way into a non-numeric column will be written out as …
fsoubelet a0a34ee
this commented out path goes away
fsoubelet 3ad13c4
fix TITLE in this test file
fsoubelet a0aae19
add nullable support of nils in changelog
fsoubelet 378b14a
one more comment
fsoubelet fd9789d
as note
fsoubelet 82d66d8
this was just not true I handle it fine
fsoubelet 99f0914
properly read empty strings and cast nils in string columns to None
fsoubelet adc8b8e
be super specific here
fsoubelet 2c7edae
also test for nil in string column
fsoubelet da6db00
test writing with None (to nil) in headers
fsoubelet 5e8bcea
that was a duplicate
fsoubelet e44191b
add test for pathlib.Path in headers handled properly and written as …
fsoubelet dda2277
comments
fsoubelet 61fde0f
disallow None in headers for MAD-X mode
fsoubelet 3102427
comments
fsoubelet 21bf806
and add a test for this
fsoubelet a1b4aba
some more info in CHANGELOG
fsoubelet c2f211a
some linting
fsoubelet 5bc250d
better than concatenation, better than try return
fsoubelet c238b3d
match on raised error, use fixture
fsoubelet ddc79c4
unecessary elifs with returns in ifs
fsoubelet 45f8ef7
add todo so I can switch branches
fsoubelet 2aa1dcf
merge master back into madng
fsoubelet 3d27744
remove unused
fsoubelet aa85414
use the testing helper from our own module now
fsoubelet 1cfbb21
min pymadng version is 0.5.0 for our tests
fsoubelet 85cddfc
specify minimum MADNG version for compatibility
fsoubelet 5481cd5
no cern network tests here
fsoubelet 2c3d2db
test for madng reading our files
fsoubelet 0cb944e
we skip this test on Windows as pymadng and MADNG are not available t…
fsoubelet 569876b
require pymadng version with exposed protected_send
fsoubelet 815d3d2
drop python 3.9, resolve the dependency constraints on numpy 2 and py…
fsoubelet acef0d9
can import and use NoneType since we drop python3.9
fsoubelet 414b107
can import and use NoneType since we drop python3.9
fsoubelet 21d4ab5
update the changelog with relevant version numbers
fsoubelet ca76aae
don't need this todo file, was just for me
fsoubelet bca4e06
don't need this todo file, was just for me
fsoubelet 92abaef
NAME example is a string
fsoubelet a262f1c
no need for protected_send anymore
fsoubelet 9ec21c0
less verbose
fsoubelet ab75b1a
more explicit on behaviour regarding headers_dict, the df headers, or…
fsoubelet a2aaf51
add comment about why we use pandas.read_csv in _read_metadata too
fsoubelet d87611c
test content of table written then read by MAD-NG
fsoubelet e5a944e
testing josch idea
fsoubelet 3604f54
slightly cleaner version
fsoubelet dec0f24
fully replace old _read_metadata
fsoubelet 8020533
explicit rename of helper
fsoubelet cc4b97a
no need to recv as we communicate later
fsoubelet 7184132
finalize docstrings for new helpers
fsoubelet 3aa112c
do not use anymore this unexpected sep
fsoubelet d2a5baf
some final linting
fsoubelet ca58fe5
some small pytest config to get coverage info
fsoubelet 91f7d48
change affiliation because why not
fsoubelet cb0929a
we should test writing with NO HEADERS for all validation modes
fsoubelet da2acb8
dummy guards checking headers exist before manipulating them
fsoubelet 95b82ac
with a helper function and a bit more checks
fsoubelet 035f497
check they're here, error if not in MADX mode
fsoubelet f1921c7
this only checks in no validation and MADNG validation modes
fsoubelet 7cd5ece
add a check for expected failure in MAD-X mode for this case
fsoubelet 005cc8c
document edge case about no headers in MADX compatibility mode
fsoubelet eec3566
and document the step in the docstring of validation function
fsoubelet 54e0620
where did that come from
fsoubelet ee0cb7f
add this to the changelog
fsoubelet c9de62b
not needed with new behaviour
fsoubelet ac63358
cast to TfsDataFrame in any case and make sure there are headers
fsoubelet 05ed77c
and check for this in validation
fsoubelet 2f776e5
dq
fsoubelet ff7caaa
docpage for validation off by default
fsoubelet cabddb5
also in the changelog
fsoubelet 8bbcbac
still mention it is default in validation function itself
fsoubelet 8be5b73
validation is OFF by default when writing
fsoubelet be6f123
adapt writer tests to explicitely ask for validation when it was impl…
fsoubelet 776ae4b
NoneType also here
fsoubelet 58e02e8
just comments
fsoubelet 210ca74
remove this comment block
fsoubelet 351d0e5
spaces and consistency
fsoubelet a05b82a
no emojis
fsoubelet 21cfb50
showcase headers are here
fsoubelet 03152f8
correct function names in documentation examples
fsoubelet eea534b
fix the rounding issues in headers
fsoubelet e7763e0
this is not used anymore
fsoubelet 5ca050a
comments
fsoubelet 01ce775
add a None (becomes nil) in the _tfs_dataframe_madng fixture
fsoubelet 82b1e72
clearer name for helper function
fsoubelet 63df6cf
examples reworked for new behaviour
fsoubelet 36abd0a
update docstring on the validate argument
fsoubelet f9d39b6
backwards compatible check
fsoubelet d56e9e2
test for pd.DataFrame + headers provided to writing
fsoubelet ade7a2f
more accurate test names
fsoubelet fc12167
parametrize validation modes, check that providing dataframe with emp…
fsoubelet 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
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,101 @@ | ||
MAD-X and MAD-NG Compatibility | ||
============================== | ||
|
||
As `tfs-pandas` allows one to write `TfsDataFrames` as files in the **TFS** format, which are typically output by simulations codes, compatibility of these files with said codes is crucial. | ||
Specifically, `tfs-pandas` aims to ensure the files it writes to disk are accepted as input for `MAD-X <https://madx.web.cern.ch/>`_ and `MAD-NG <https://madx.web.cern.ch/releases/madng/html/>`_. | ||
|
||
However, as ``MAD-NG`` is the successor to ``MAD-X``, it includes new features regarding the **TFS** format, and files including these features will not be accepted by ``MAD-X``. | ||
To circumvent this issue, `tfs-pandas` offers functionality - named validation - to ensure compatibility with either code. | ||
|
||
TfsDataFrame Validation | ||
----------------------- | ||
|
||
It is possible to perform automatic validation of a `TfsDataFrame` both when reading and writing, or to validate them at any time using the `tfs.frame.validate` function. | ||
Validation enforces the rules described in the :ref:`caveats section <tfs-pandas caveats>`, both to guarantee the integrity of the dataframe and compatibility of written files with simulation codes. | ||
|
||
.. admonition:: When Does Validation Happen? | ||
|
||
Validation is **optional**, and is by default turned off at both read-time and write-time. | ||
|
||
Validation is done by providing a `TfsDataFrame` and a compatibility mode to `tfs.frame.validate` (see the :ref:`API reference <modules/index:frame>`). | ||
It goes as: | ||
|
||
.. code-block:: python | ||
|
||
import tfs | ||
from tfs.frame import validate | ||
|
||
df = tfs.read("path/to/file.tfs") | ||
|
||
# To validate with MAD-X compatibility | ||
validate(df, compatibility="mad-x") # or use "madx" | ||
|
||
# To validate with MAD-NG compatibility | ||
validate(df, compatibility="mad-ng") # or use "madng" | ||
|
||
In case of compatibility issue, an exception is raised which will point to the specific incompatible element. | ||
All exceptions inherit from the `TfsFormatError`, which one can `except` as a catch-all for this package. | ||
|
||
.. _common rules: | ||
|
||
Common Validation Rules | ||
----------------------- | ||
|
||
In either compatibility mode, some common rules are enforced. | ||
These rules are listed and described in the :ref:`API reference <modules/index:frame>` for the `tfs.frame.validate` function. | ||
|
||
When validating a `TfsDataFrame`, the behavior in case one of these rules is violated depends on the value of the `non_unique_behavior` parameter. | ||
These rules are *always* checked against when validating a `TfsDataFrame`. | ||
Additional checks can be performed by setting the `compatibility` parameter, as described in the :ref:`MAD-NG <madng mode>` and :ref:`MAD-X <madx mode>` below. | ||
|
||
.. _madng mode: | ||
|
||
MAD-NG Compatibility | ||
-------------------- | ||
|
||
.. admonition:: Supported Versions | ||
|
||
The compatibility with ``MAD-NG`` is guaranteed starting with version `1.0.0`. | ||
See below for details and caveats. | ||
|
||
Since ``MAD-NG`` implements and accepts more features into its **TFS** files, its compatibility mode is naturally less restrictive. | ||
Namely, the following are accepted by ``MAD-NG`` and ``MAD-NG`` only: | ||
|
||
- Boolean dtype for header parameters and table columns. | ||
- Complex dtype for header parameters and table columns. | ||
- Nullable dtype for header parameters and table columns (value `nil`). | ||
|
||
.. admonition:: Complex Number Representation | ||
|
||
In Python, the imaginary part of a complex number is represented by the letter ``j``, as in `1.4 + 2.6j`. | ||
When writing complex values to file, `tfs-pandas` will instead use the ``MAD-NG`` (read `Lua`) representation, and uses the letter ``i``, as in `1.4 + 2.6i`, so that ``MAD-NG`` can properly read such a file. | ||
Both of these representations will be correctly read by `tfs-pandas` (including when ``MAD-NG`` uses ``I`` for special complex numbers). | ||
|
||
.. admonition:: Handling of Nullable Types | ||
|
||
``MAD-NG`` uses the nullable `nil`, which is accepted by `tfs-pandas` with the following caveats: | ||
|
||
- When reading from file, `nil` values in the headers are converted to `None` while those in the dataframe are cast to `NaN`, except in string-dtyped columns where they are converted to `None`. | ||
- When writing to file, `None` values anywhere are written as `nil`, and `NaN` values in the dataframe are written as `NaN` (remember that setting a `None` in a numeric `pandas.DataFrame` column automatically casts it as `NaN`). | ||
|
||
.. attention:: | ||
|
||
The exotic "features" of ``MAD-NG`` such as the ``Lua`` operator overloading for ranges and tables, and their inclusion in **TFS** files are not supported by `tfs-pandas`. | ||
Should one need to use these features, it is recommended to go through the `pymadng <https://pymadng.readthedocs.io/en/latest/>`_ package to handle them in-memory. | ||
|
||
.. _madx mode: | ||
|
||
MAD-X Compatibility | ||
------------------- | ||
|
||
The ``MAD-X`` compatibility mode is more restrictive, and enforces that none of the features listed in the :ref:`MAD-NG section <madng mode>` appear in the `TfsDataFrame`. | ||
|
||
Additionally, ``MAD-X`` will refuse to read into a table any **TFS** file that does not include a `TYPE` entry in the headers (which should be a string). | ||
As such, when checking for compatibility with ``MAD-X``: | ||
|
||
- If the dataframe has no headers, an error will be raised indicating the dataframe should have headers. | ||
- If the dataframe has headers but no `TYPE` entry is not found, `tfs-pandas` will log a warning and add one with the value `"Added by tfs-pandas for MAD-X compatibility"` | ||
|
||
.. admonition:: Default mode | ||
|
||
The default compatibility mode enforced by the `tfs.frame.validate` function is ``MAD-X``. |
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
Oops, something went wrong.
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.