Skip to content

Conversation

@adamdempsey90
Copy link
Collaborator

PR Summary

This overhauls the entire parameter input machinery to rely on my input deck library Rummy. For examples of the new syntax, see the various input files in examples/ and the Rummy repository.

Rummy breaks an input deck down into suits (the <parthenon/...> nodes) and cards (the parameters themselves). The values of the cards are passed into a byte-code compiler that I wrote. The compiler supports strings, bools, and number variables and various operations on those variables. The syntax for the card values is similar to python. The three big things this adds is support for global variables, referencing other parameters defined in the input deck and full infix expressions. For example,

nb = 16,16, 1  # can also do [16,16,1]
Lx = 1.0
<parthenon/meshblock>
nx1 = nb[0]
nx2 = nb[1]
nx3 = nb[2]

<parthenon/mesh>
nx1 = parthenon.meshblock.nx1 * 10
x1min = -Lx/2.
x1max =  Lx/2.
ix1_bc = "periodic"
ox1_bc = ix1_bc

nx2 = parthenon.meshblock.nx2 * 10
x2min = -pi
x2max = pi
ix2_bc = ix1_bc
ox2_bc = ix1_bc

nx3 = nb[2]

print("Inner X1 BC is " + parthenon.mesh.ix1_bc)
print("X2 Extent:")
print(x2max - x2min)

Operators that are defined are +, - ,*, /, ** (power), // (integer division), %, >, <, >=, <=, !, !=. You can add strings with +. Almost all of the <cmath> functions are supported. Vector params are supported and there is some limited support for slice operations. The compiled parts will spit out errors telling you what you did wrong.

The syntax for variable reference is like classes. The / in a node is replaced with a . . At this time, there is no inheritance.

To support the new syntax I've changed a bit how the input arguments are handled. Now you can do things like this,

./app -i input1.par -i input2.par 'parthenon.mesh.ix1_bc = "outflow"'

We accept multiple -i input files now. These are stuffed into a vector and compiled in order. The modifications are compiled after the input files and should now be wrapped in single quotes (if there are strings, otherwise double quotes is fine).

Restarts are mostly the same, but I have added a -R option to read old restart files that use the old syntax.

Another nice feature this adds is the ability for the host code to pre-populate parameters that can be used in the input files. For example, you could add all of the physical constants before the input decks are compiled.

Lastly, there is a simple print function that can print the value of any parameter or expression from the input file.

I anticipate the utility of this to grow with time as I work more on my compiler. Right now, branches and loops are supported in the compiler but not Rummy, and functions and classes are supported in neither, but I plan to work on those as time permits. The idea is to work towards a fully compiled and interpreted input file.

This is still WIP but appears to work for all the parthenon examples and various artemis tests, so I'm putting it up now for feedback. Things left to do include:

  • Fix the unit tests
  • Verify various downstream code usage
  • Decide on support for legacy format. Compile time or runtime?

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

@Yurlungur
Copy link
Collaborator

This is very cool and I'm excited to look through it

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.

3 participants