-
Notifications
You must be signed in to change notification settings - Fork 18
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
Differences in cpymad table.twiss
and madx table(twiss, X, X)
when running use
#93
Comments
Hi, I remember facing something similar and since then I never use the What do you think using below a not so minimal example from cpymad.madx import Madx
mqk, mql, length = 1.0, 0.1, 5.3
madx = Madx()
madx.beam(particle='proton', pc=1000)
madx.command.sequence.clone('S1', l='{:10.6e}'.format(length))
madx.elements.marker.clone('s1start', at=0)
madx.command.endsequence()
madx.command.quadrupole.clone('QF', l=mql, k1=mqk)
madx.command.quadrupole.clone('QD', l=mql, k1=-mqk)
madx.command.rbend.clone('dip', l=0.1, angle=10e-3)
madx.command.seqedit(sequence='S1')
madx.command.install(element='QF1', class_='QF', at='{:10.6e}'.format(mql/2))
madx.command.install(element='B1', class_='dip', at=mql+0.1/2)
madx.command.install(element='QD1', class_='QD', at='{:10.6e}'.format(length/2-mql/2))
madx.command.endedit()
madx.use(sequence='s1')
madx.twiss()
print(madx.table.twiss.row_names())
print(madx.table.twiss.name)
print(madx.sequence['s1'].twiss_table.row_names())
madx.options(debug=True)
madx.use(sequence='s1')
print(madx.table.twiss.row_names())
print(madx.table.twiss.name)
print(madx.sequence['s1'].twiss_table.row_names()) |
Hey, thank you for your answer. But, workarounds aside, this still looks like a bug as at the same state of the madx-instance |
Hi, interesting. I've reproduced using a smaller example (since I don't have or want to install afs here). from cpymad.madx import Madx
madx = Madx()
madx.input("""
beam;
mqf.k1 = 0.3037241107;
mqd.k1 = -0.3037241107;
fodo: sequence, l=10, refer=entry;
mqf: quadrupole, at=0, l=1, k1:=mqf.k1;
dff: drift, at=1, l=4;
mqd: quadrupole, at=5, l=1, k1:=mqd.k1;
dfd: drift, at=6, l=4;
endsequence;
use, sequence=fodo;
twiss, sequence=fodo, x=0.1;
""")
before = madx.table.twiss.dframe()
madx.use(sequence="fodo")
after = madx.table.twiss.dframe()
print("row names before:", before.index.tolist())
print("row names after: ", after.index.tolist())
print("name column before:", before.name.tolist())
print("name column after: ", after.name.tolist())
print("x column before:", before.x.tolist())
print("x column after: ", after.x.tolist())
madx.input("from_table = table(twiss, mqf, x);")
print(madx.globals['from_table']) From this we can see that the table values are still correct, just the row names get messed up by the I believe the reason for that is that the table row names are assigned as raw pointers to the current node's name when adding a row, see void
augment_count(const char* table) /* increase table occ. by 1, fill missing */
{
...
if (t->node_nm != NULL)
{
t->node_nm->p[t->curr] = current_node->name;
t->node_nm->curr = t->curr;
}
...
} Now, after calling The reason that MAD-X's The approach MAD-X is taking (i.e. trying to find the element name in arbitrary string columns) is not a good idea IMO, and not even applicable here (since we have to decide on one column to be used for the dataframe's index). Hence, this is probably something to be added to "known issues" that it is unsafe to use tables after A possible workaround would be: twiss_table = madx.table.twiss
twiss_df = pd.DataFrame(
twiss_table.copy(),
index=np.char.partition(twiss_table.name, ":")[:, 0]) We could integrate using this workaround by adding an |
Thank you very much for looking that deep into it (and for providing your take on the smallest example), @coldfix . I like your workaround idea, if the data is still in place? It didn't sound too promising, if the nodes are rebuild. Can we trust any data in the |
Hi, |
As far as I see, the data in the tables are not touched by |
Thank you so much! |
API changes: - ``Table.selected_rows()`` now actually returns the *indices* of the selected elements as documented, rather than returning a boolean mask. - ``Madx.eval()`` does no automatic syntax checking anymore. This is a minor performance improvement and is more consistent with ``Madx.input()`` which doesn't check the syntax either. Expressions can still be checked manually using ``cpymad.util.check_expression`` New features: - (#90) Add comparison operators for ArrayAttribute (see #89) - (#94) Add keyword argument ``Table.dframe(index=..)`` to allow specifying a column or sequence as the DataFrame index rather than using the default (``row_names()``). This is essential when accessing a table after having executed a ``USE`` statement (see #93). - (#97) Add basic support for unexpanded nested sequences by returning them as elements of type ``Sequence`` from ``Sequence.elements`` (see #76) - Add keyword argument ``Madx(prompt=...)`` as a shortcut for the most common ``CommandLog`` use case - (#99) Add method ``Table.column()`` to retrieve specified rows in a specific column. - (#99) Add ``rows`` and/or ``columns`` arguments to several ``Table`` methods to allow querying only specific columns or rows from the MAD-X process - (#99) Add method ``Table.selection()`` that returns a new ``Table`` object which exposes only those rows/columns marked by a previous ``SELECT`` statement (see #98) - Fix ``Madx.eval()`` to handle function calls, e.g.: ``sin(...)`` or ``table(...)`` Bug fixes: - (#95) Fix ``KeyError`` when accessing tables after ``CLEAR`` (see #57) - (#99) Fix requesting a subset of table rows using using a *numpy array* of indices - Fix expression syntax checker to not reject function calls anymore. Rewrite the checker to use a LL(1) parser generator. Documentation: - Add links to external documentation using intersphinx - Use automodapi to create module and class summary pages - Use type hints from function annotations in documentation - Mark more objects for inclusion in the documentation - Add "Edit on GitHub" link to directly edit documentation - Add many function annotations - Generate class inheritance diagrams using graphviz - Document problem with ``Table.row_names()`` after ``USE`` (#93) Tests/CI: - Move python 3.5 deprecation warning to package level - Create GitHub releases for tags automatically (required for zenodo DOIs) - Setup sequence definitions individually and explicitly in each test - Add module for regression tests for all future bugfixes - Put transfer map tests in their own module - Port tests from unittest to pytest for simplicity - Mark flaky tests for expected failure on macOS and windows
I see differences when getting values from
table.twiss.dframe().loc[X, X]
vs runningtable(twiss, X, X)
in madx (e.g. viainput()
) if there is ause
in between the lasttwiss
and getting the values.These differences can be quite substantial, but I have not managed to create a minimum working example with large differences.
Here is one that shows the problem, but the differences are not as big as I can see in some of my scripts:
Output:
upon commenting out the
madx.use()
or doing anothermadx.twiss()
afterwards :The text was updated successfully, but these errors were encountered: