Skip to content

Parse multiply shortcuts that look like multigroup ZAIDs - #1046

Open
SpaceOceanCorp wants to merge 1 commit into
idaholab:developfrom
SpaceOceanCorp:multiply-zaid-ambiguity
Open

SpaceOceanCorp wants to merge 1 commit into
idaholab:developfrom
SpaceOceanCorp:multiply-zaid-ambiguity

Conversation

@SpaceOceanCorp

@SpaceOceanCorp SpaceOceanCorp commented Nov 4, 2026 •

Copy link
Copy Markdown

Pull Request Checklist for MontePy

Description

vol 2 1000.00m raised a ParsingError, because 1000.00m has the shape of a ZAID with a multigroup library and the lexer returned ZAID. The lexer can't decide this alone, since 1001.50m is a valid ZAID on a material, so the decision moves to the parser:

  • The ZAID token no longer matches a two digit library with the m suffix. These now lex as NUM_MULTIPLY, so all multiply shortcuts lex the same way.
  • zaid_phrase also accepts NUM_MULTIPLY, and reports a syntax error unless it has the shape of a multigroup ZAID. So m1 1001.50m 1.0 still works, and m1 1.5m 1.0 and vol 1.5m 2 are still errors.
  • file_atom accepts NUM_MULTIPLY, because it accepted ZAID. Without this read file=1001.50m would stop working. As a side effect read file=1.5m now parses too.

This also fixes the intermittent failure of test_multiply_fortran_floats on the example 0000.00m. That test is unchanged.

One existing behavior I left alone: vol 1000.00m 2 parses as an isotope fraction, as it did before, because DataParser doesn't check which card a ZAID is on.

The new tests cover multiplies shaped like ZAIDs, multigroup ZAIDs on materials including mixed libraries, the two error cases, and file names. The multiply tests and read file=1.5m fail on develop; the others pin behavior that has to stay the same.

Fixes #1045


General Checklist

  • I have performed a self-review of my own code.
  • The code follows the standards outlined in the development documentation.
  • I have formatted my code with black version 25 or 26.
  • I have added tests that prove my fix is effective or that my feature works (if applicable).

LLM Disclosure

  1. Are you?

    • A human user
    • A large language model (LLM), including ones acting on behalf of a human
  2. Were any large language models (LLM or "AI") used in to generate any of this code?

  • Yes
    • Model(s) used: Claude Opus 5.5
    • Harness used: Claude Code
    • Reasoning effort: low
  • No

Documentation Checklist

  • I have documented all added classes and methods.
  • I have added type hints to all functions as needed.
  • I have marked all changes with the .. versionchanged:: or .. versionadded:: directives.

N/A, no public API changes.

Infrastructure Changes

  • For infrastructure updates, I have updated the developer's guide.

N/A, no infrastructure changes.

Significant features or Behavior changes

  • For significant new features, I have added a section to the getting started guide.

N/A, bug fix.


First-Time Contributor Checklist

  • If this is your first contribution, add yourself to pyproject.toml if you wish to do so.

Additional Notes for Reviewers

Ensure that:

  • This PR fully addresses and resolves the referenced issue(s).
  • The submitted code is consistent with the merge checklist outlined here.
  • The PR covers all relevant aspects according to the development guidelines.
  • 100% coverage of the patch is achieved, or justification for a variance is given.

📚 Documentation preview 📚: https://montepy--1046.org.readthedocs.build/en/1046/

A multiply such as 1000.00m has the shape of a multigroup ZAID, so the
lexer made it a ZAID and the parser rejected it. The lexer can't tell
which one it is: 1001.50m is a valid ZAID on a material.

Lex these as NUM_MULTIPLY, and let zaid_phrase accept a NUM_MULTIPLY
that has the shape of a multigroup ZAID. File names accept NUM_MULTIPLY
too, since they accepted ZAID.
@MicahGale
MicahGale changed the base branch from develop to patch_dev November 5, 2026 05:17
@MicahGale
MicahGale changed the base branch from patch_dev to develop November 5, 2026 14:28
@MicahGale MicahGale self-assigned this Nov 5, 2026
@MicahGale
MicahGale self-requested a review November 5, 2026 17:02
@MicahGale MicahGale added bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error". parsers are hard Examples of where MCNP syntax is complicated and should be simplified. labels Nov 5, 2026

@MicahGale MicahGale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. I just have one suggestion to make the test a little cleaner.

Comment on lines +86 to +87
if hasattr(p, "NUM_MULTIPLY") and not self._MULTIGROUP_ZAID.fullmatch(p[0]):
self.error(p._slice[0])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it is theoretically possible to use a multiply shortcut inside of a material definition, it is a very contrived scenario that requires no use of libraries in the ZAIDs, and requires multiplications to go from ZAID to fraction and back repeatedly. I think only I would come up with something so contrived, so we can exclude this edge case.

def test_multigroup_zaid_in_material(text, libraries):
material = montepy.Material(Input([text], BlockType.DATA))
assert [str(nuclide.library) for nuclide, _ in material] == libraries
assert material.format_for_mcnp_input((6, 3, 0)) == [text]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use mcnp_str to test here as it's cleaner.

@MicahGale MicahGale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little more coverage is needed.

@_("ZAID", "ZAID padding")
@_("ZAID", "ZAID padding", "NUM_MULTIPLY", "NUM_MULTIPLY padding")
def zaid_phrase(self, p):
if hasattr(p, "NUM_MULTIPLY") and not self._MULTIGROUP_ZAID.fullmatch(p[0]):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two lines that were added here which were not covered: https://coveralls.io/jobs/190904452. Please investigate and see if it feasible to get 100% patch coverage.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugs A deviation from expected behavior that does not reach the level of being reportable as an "Error". parsers are hard Examples of where MCNP syntax is complicated and should be simplified.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiply shortcuts shaped like a multigroup ZAID raise ParsingError

2 participants