Skip to content

Beta implementation of Just In time parsing#960

Draft
MicahGale wants to merge 299 commits into
beta_rel_devfrom
jit_parse
Draft

Beta implementation of Just In time parsing#960
MicahGale wants to merge 299 commits into
beta_rel_devfrom
jit_parse

Conversation

@MicahGale

@MicahGale MicahGale commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Checklist for MontePy

Description

This PR adds the ability to do Just-in-time parsing. The quick summary is that at file read time, only the very beginning (3 words max per object) are read and used to store the object in the "proper place" then when more information is needed from that object it is full_parsed, and the data are stored so it may be accessed. Here's an overview of how that was done:

  1. Complete rework of __init__ to a hook based system with _init_blank, _parse_tree, etc. To make the code more DRY.
  2. Added jit_parse args to __init__ and defaulted to jit_parse.
  3. Added full_parse that essentially triggers a re-init
  4. Added the decorators needs_full_cst and needs_full_ast to mark functions that need full abstract/concrete syntax trees. Right now they are identical, but they could be used in the future. When a function that is marked is called it is checked if it is fully parsed, if not a full parse occurs.
  5. Added decorators to pull objects from other places in the problem on the fly to remove the need for update_pointers

For more details read the updated dev docs.

I know this is a ton @tjlaboss. I am thinking of having you review just the architecture, and then calling that good before doing a beta release. For testing I found a way to have all of the integration tests to run with both jit_parse=False and jit_parse=True pretty cleanly with pytest (thanks Claude).

TODO:

  • Get 100% patch coverage.

Fixes #529


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 (Sonnet 4.6), GH Copilot (?)
  • No

Documentation Checklist

  • I have documented all added classes and methods.
  • For infrastructure updates, I have updated the developer's guide.
  • For significant new features, I have added a section to the getting started guide.

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--960.org.readthedocs.build/en/960/

MicahGale and others added 30 commits August 30, 2025 21:24
MicahGale and others added 24 commits June 12, 2026 11:52
`g`, and `f`/`e` formatters treat precision differently.
`g` is used when there is no reverse engineering occurring, otherwise
`f`/`e` are used. Therefore the formatter precision changes meaning.
In rounding it is treated as being the number of digits right of the
decimal. This logic updates it so when `g` is used it now represents the
number of sig figs, so the rounding truncation logic still applies.
Updated default float precision to be basically machine precision.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…-tests

Fixed deprecated test fixtures breaking tests
Bumps [actions/checkout](https://github.com/actions/checkout) from 6.0.2 to 6.0.3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@de0fac2...df4cb1c)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…ns/checkout-6.0.3

Bump actions/checkout from 6.0.2 to 6.0.3
Started testing against python 3.15 dev releases.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…st arg.

cell.py was missing `Annotated` in its imports despite using it directly in the
lattice_type setter annotation under `from __future__ import annotations`, and
had `true` (lowercase) instead of `True`. Also removed the `jit_parse` keyword
argument from test_arbitrary_parse that parse() never accepted.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tjlaboss

Copy link
Copy Markdown
Collaborator

Observation:

JIT significantly reduces memory usage--less memory allocation and more garbage collection

So far JIT somewhat inflates loading time. Without JIT: 31 s. With JIT: 69s, for the benchmark. Reading a large reactor model with depletion on my desktop, loading time increased from 41 to 46 s.

Comment thread montepy/mcnp_problem.py
if len(input.input_lines) > 0:
try:
obj = obj_parser(input)
obj = obj_parser(input, problem=self, jit_parse=jit_parse)

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.

jit_parse doesn't seem to propagate to the objects.

>>> deck0 = montepy.read_input("tests/inputs/test.imcnp", jit_parse=False)
>>> deck0.cells[3]
Cell('3 3 -1\n      1000 1005 -1010\n     imp:n,p=1', number=3, jit_parse=False)
>>> deck1 = montepy.read_input("tests/inputs/test.imcnp", jit_parse=True)
>>> deck1.cells[3]
Cell('3 3 -1\n      1000 1005 -1010\n     imp:n,p=1', number=3, jit_parse=False)

@MicahGale MicahGale Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think somewhere a full parse is getting triggered during the full model reading process.

@MicahGale

Copy link
Copy Markdown
Collaborator Author

So far JIT somewhat inflates loading time. Without JIT: 31 s. With JIT: 69s, for the benchmark. Reading a large reactor model with depletion on my desktop, loading time increased from 41 to 46 s.

I suspect the overhead is due to @args_checked I will dig into this more.

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

Labels

code improvement A feature request that will improve the software and its maintainability, but be invisible to users. feature request An issue that improves the user interface. performance 🐌 Issues related to speed and memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants