Skip to content

Improve add rmode0 aux function#485

Open
dodu94 wants to merge 4 commits intodevelopingfrom
improve-add_rmode0-aux-function
Open

Improve add rmode0 aux function#485
dodu94 wants to merge 4 commits intodevelopingfrom
improve-add_rmode0-aux-function

Conversation

@dodu94
Copy link
Member

@dodu94 dodu94 commented Mar 4, 2026

The add_rmode0 function is key to deploy JADE on clusters where D1SUNED is installed. There were a bunch of edge cases that were not covered by the logic of the functions. These are covered now. To be reviewed after #484

Summary by CodeRabbit

  • Dependencies

    • Updated core dependency version for improved compatibility.
  • Bug Fixes

    • Improved handling of trailing empty lines in MCNP input files.
    • Ensured proper newline formatting during directive injection.
  • Tests

    • Enhanced test coverage for RMODE functionality with new test cases and input fixtures.
  • Chores

    • Updated CI/CD workflows for Python 3.11 support.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2026

Walkthrough

This PR updates CI/CD configuration to support Python 3.11 with legacy OpenMC installation, bumps the f4enix dependency to version 0.19.0, refactors an import path for consistency, enhances RMODE 0 handling logic with improved file formatting, and adds comprehensive test coverage with three new MCNP input test files and a corresponding test function.

Changes

Cohort / File(s) Summary
CI/CD Configuration
.github/workflows/pytest.yml
Adds legacy OpenMC installation for Linux with Python 3.11; updates main OpenMC install condition to exclude both Python 3.10 and 3.11; changes Codecov upload target from Python 3.11 to 3.12 to ensure single run.
Dependency Management
pyproject.toml
Bumps f4enix dependency from >=0.18.0 to >=0.19.0.
Core Logic
src/jade/helper/aux_functions.py, src/jade/run/input.py
Enhances add_rmode0 to strip trailing empty lines from MCNP files and ensure proper newline before RMODE 0 directive; updates Nuclide import path from f4enix.input.irradiation to f4enix.core.irradiation.
Test Data and Coverage
tests/helper/res/rmode/sphere_more_spaces.i, tests/helper/res/rmode/sphere_no_spaces.i, tests/helper/res/rmode/sphere_rmode.i, tests/helper/test_auxiliary_func.py
Introduces three new MCNP input test files with varied formatting and tally configurations; adds test_add_rmode0 test function to verify RMODE card injection and validate input parsing against f4enix.Input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops through workflows and test files with glee,
Python 3.11 now gets legacy parity,
RMODE cards dance, dependencies align,
Our tests now shine with spheres that refine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve add rmode0 aux function' accurately reflects the primary change: enhancing the add_rmode0 function with edge case handling as described in the PR objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch improve-add_rmode0-aux-function

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/jade/helper/aux_functions.py (1)

109-109: ⚠️ Potential issue | 🔴 Critical

Prevent empty-file crash and robustly detect existing RMODE cards.

At Line 127, lines[-1] can crash on empty/all-blank files. Also, Line 123 uses a strict match pattern that can miss indented or multi-space RMODE 0 lines and append duplicates.

🔧 Proposed fix
-def add_rmode0(path: PathLike) -> None:
+def add_rmode0(path: PathLike) -> None:
@@
-    pattern = re.compile(r"rmode 0", re.IGNORECASE)
+    pattern = re.compile(r"^\s*rmode\s+0(?:\s|$)", re.IGNORECASE)
@@
-                        for line in lines:
-                            if pattern.match(line):
+                        for line in lines:
+                            if pattern.match(line):
                                 found = True
                             f.write(line)
                         if not found:
-                            if not lines[-1].endswith("\n"):
+                            if lines and not lines[-1].endswith("\n"):
                                 f.write("\n")
                             f.write("RMODE 0\n")

Also applies to: 117-119, 123-123, 127-128

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/jade/helper/aux_functions.py` at line 109, The code currently compiles
pattern = re.compile(r"rmode 0", re.IGNORECASE) and uses lines[-1] and re.match
which can crash on empty/all-blank files and miss indented or multi-space "RMODE
0" lines, causing duplicates; update the regex to r"^\s*rmode\s+0\b"
(case-insensitive) and replace re.match with pattern.search, check existence
with any(pattern.search(line) for line in lines) to avoid duplicates, and find
or append to the last non-blank line instead of lines[-1] (handle empty files by
initializing lines to [''] or appending to an empty list safely), ensuring any
appended RMODE line uses consistent newline handling.
🧹 Nitpick comments (2)
tests/helper/test_auxiliary_func.py (1)

58-60: Assert RMODE uniqueness, not only presence.

Current check passes even if duplicate RMODE 0 cards are added. Strengthen this test to assert exactly one RMODE card per file.

✅ Example stronger assertion
-            assert "RMODE" in inp.other_data.keys(), (
-                f"RMODE card not found in the input file {file}"
-            )
+            text = dst.joinpath(file).read_text()
+            rmode_count = sum(
+                1 for line in text.splitlines()
+                if line.strip().upper() == "RMODE 0"
+            )
+            assert rmode_count == 1, f"Expected one RMODE 0 in {file}, found {rmode_count}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/helper/test_auxiliary_func.py` around lines 58 - 60, The test currently
only checks presence of the "RMODE" key via inp.other_data.keys(); change it to
assert there is exactly one RMODE card by validating the count of RMODE entries
(e.g., len(inp.other_data.get("RMODE", [])) == 1) and keep the existing failure
message (referencing file) so the test fails if there are zero or multiple RMODE
cards; update the assertion that currently references inp.other_data and "RMODE"
to check for exact uniqueness rather than mere presence.
.github/workflows/pytest.yml (1)

65-67: Use distinct step names for legacy OpenMC installs.

Both legacy install steps share the same name, which makes job logs harder to read/debug. Consider naming them by Python version.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/pytest.yml around lines 65 - 67, The two legacy install
steps both use the name "Install openmc (legacy)" which makes logs ambiguous;
update the step names to be unique and include the Python version (e.g.,
"Install openmc (legacy, py3.11)") for the step with condition
matrix.python-version == '3.11' and likewise for the other legacy step
(reference the step name "Install openmc (legacy)" in your diff), ensuring each
step name clearly identifies its Python version so job logs are readable and
distinguishable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/jade/helper/aux_functions.py`:
- Line 109: The code currently compiles pattern = re.compile(r"rmode 0",
re.IGNORECASE) and uses lines[-1] and re.match which can crash on
empty/all-blank files and miss indented or multi-space "RMODE 0" lines, causing
duplicates; update the regex to r"^\s*rmode\s+0\b" (case-insensitive) and
replace re.match with pattern.search, check existence with
any(pattern.search(line) for line in lines) to avoid duplicates, and find or
append to the last non-blank line instead of lines[-1] (handle empty files by
initializing lines to [''] or appending to an empty list safely), ensuring any
appended RMODE line uses consistent newline handling.

---

Nitpick comments:
In @.github/workflows/pytest.yml:
- Around line 65-67: The two legacy install steps both use the name "Install
openmc (legacy)" which makes logs ambiguous; update the step names to be unique
and include the Python version (e.g., "Install openmc (legacy, py3.11)") for the
step with condition matrix.python-version == '3.11' and likewise for the other
legacy step (reference the step name "Install openmc (legacy)" in your diff),
ensuring each step name clearly identifies its Python version so job logs are
readable and distinguishable.

In `@tests/helper/test_auxiliary_func.py`:
- Around line 58-60: The test currently only checks presence of the "RMODE" key
via inp.other_data.keys(); change it to assert there is exactly one RMODE card
by validating the count of RMODE entries (e.g., len(inp.other_data.get("RMODE",
[])) == 1) and keep the existing failure message (referencing file) so the test
fails if there are zero or multiple RMODE cards; update the assertion that
currently references inp.other_data and "RMODE" to check for exact uniqueness
rather than mere presence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: adf22449-3b41-4a1d-95d8-d7b6714b26d3

📥 Commits

Reviewing files that changed from the base of the PR and between 2e2b46b and a37aeb0.

📒 Files selected for processing (10)
  • .github/workflows/pytest.yml
  • pyproject.toml
  • src/jade/helper/aux_functions.py
  • src/jade/run/input.py
  • tests/helper/res/__init__.py
  • tests/helper/res/rmode/__init__.py
  • tests/helper/res/rmode/sphere_more_spaces.i
  • tests/helper/res/rmode/sphere_no_spaces.i
  • tests/helper/res/rmode/sphere_rmode.i
  • tests/helper/test_auxiliary_func.py

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/jade/helper/aux_functions.py 95.34% <100.00%> (+0.22%) ⬆️
src/jade/run/input.py 88.01% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dodu94 dodu94 requested a review from alexvalentine94 March 4, 2026 15:25
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