Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Experimental: First Line Parser #515

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

szymonlopaciuk
Copy link
Collaborator

Description

Build a first iteration of a fast parser for a MAD-X inspired sequence language, currently capable of storing and loading Lines and Multilines. The expressions are kept in place, close to their corresponding elements, as opposed to the way data is structured in json. As an example, here's a "FODO":

cell_l = 1;
knl_f = 1;
knl_d = -1;
angle = 15 * raddeg;
h = angle / cell_l;
k0 = h;

line1: beamline;
    particle_ref, p0c = 7e9, q0 = 1, mass0 = pmass;
    b1: Bend, k0 = k0, h = h, length = cell_l;
    qf1: Multipole, knl = {0, knl_f};
    d12u: Drift, length = cell_l / 2;
    m12: Marker;
    d12d: Drift, length = cell_l / 2;
    qd2: Multipole, knl = {0, knl_d};
endbeamline;

Twiss default, configs, and metadata can be included. The parser is build using Bison+Flex, which compiles the grammar into C files, which interface with the rest of the parser written in Cython. On a standard HL-LHC lattice the read speed is <1.5x the json loading speed, which is somehow a necessary slow down due to the fact that we need to convert the different data layout -- still further speedup opportunities exist.

This has only been tested with Xtrack so far, and an environment flag XTRACK_TEST_XLD=1 can be switched on in order to make a JSON->XLD->JSON round-trip every time a json file is loaded. When run as part of the test suite this can be the first step to ensure we do not break things in the future, even though currently this is experimental.

Checklist

Mandatory:

  • I have added tests to cover my changes
  • ONLY XTRACK tests have been checked for now
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable
  • I have tested also GPU contexts

It can be re-enabled whenever necessary, but as it is it's polluting
the standard output of the test session far beyond of what's reasonable.

Signed-off-by: Szymon Łopaciuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant