Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/usage/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ The following is a list of the available utilities:
* ``--runtpe``: remove the runtpe files (.r) from MCNP simulation folders. This helps in
reducing the storage memory occupied by the simulation outputs.
* ``--addrmode``: This adds the "RMODE 0" card to all the MCNP input files. This is useful
when running the benchmarks on a cluster with D1SUNED prompt version instead of vanilla MCNP.
when running the benchmarks on a cluster with D1SUNED prompt version instead of vanilla MCNP.
* ``--unfinished``: Print to log the simulations that were not completed correctly or have not been run yet.
9 changes: 9 additions & 0 deletions src/jade/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,12 @@ def add_rmode(self):
"""Add the rmode=0 to the mcnp input files."""
logging.info("Adding RMODE 0 to the MCNP input files")
add_rmode0(self.tree.benchmark_input_templates)

def print_unfinished_runs(self):
"""Print the simulations that were not completed."""
for key, status in self.status.simulations.items():
if len(status.failed_simulations) > 0:
code, lib, bench = key
logging.info(f"Unfinished simulations for {code} {lib} {bench}:")
for sim in status.failed_simulations:
logging.info(f"\t{sim}")
5 changes: 5 additions & 0 deletions src/jade/helper/aux_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@ def add_rmode0(path: PathLike) -> None:
if file.endswith(".i"):
with open(os.path.join(pathroot, file)) as f:
lines = f.readlines()
# Remove trailing empty lines at the end of file
while lines and lines[-1].strip() == "":
lines.pop()
Comment on lines +123 to +125
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Handle empty/blank-only files before accessing lines[-1].

After trimming trailing blanks (Line 124–125), lines can become empty. Line 133 then raises IndexError, so add_rmode0 can crash on valid edge-case inputs.

Proposed fix
                     # Remove trailing empty lines at the end of file
                     while lines and lines[-1].strip() == "":
                         lines.pop()
                     with open(os.path.join(pathroot, file), "w") as f:
                         found = False
                         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: 133-134

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

In `@src/jade/helper/aux_functions.py` around lines 123 - 125, The function
add_rmode0 can crash for empty or blank-only files because after the
trailing-blank trim loop the list lines may be empty but the code later accesses
lines[-1]; update add_rmode0 to check for emptiness after trimming (e.g., if not
lines: return or handle as a special-case) before any access to lines[-1], and
apply the same guard where lines[-1] is used around the referenced lines 133–134
so empty/blank-only inputs are handled safely. Ensure you reference the local
variable lines and the function add_rmode0 when adding the guard.

with open(os.path.join(pathroot, file), "w") as f:
found = False
for line in lines:
if pattern.match(line):
found = True
f.write(line)
if not found:
if not lines[-1].endswith("\n"):
f.write("\n")
f.write("RMODE 0\n")


Expand Down
7 changes: 7 additions & 0 deletions src/jade/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def main():
help="Add the RMODE 0 card to all mcnp benchmarks",
action="store_true",
)
parser.add_argument(
"--unfinished",
help="Print the simulations that were not completed",
action="store_true",
)

args = parser.parse_args()

Expand All @@ -35,6 +40,8 @@ def main():
app.rmv_runtpe()
if args.addrmode:
app.add_rmode()
if args.unfinished:
app.print_unfinished_runs()
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Potential AttributeError when using --unfinished on fresh installation.

If this utility is run on a directory that hasn't been initialized yet, JadeApp.__init__() takes an early-return path (see src/jade/app/app.py lines 43-47) where self.status is never assigned. Calling app.print_unfinished_runs() will then raise an AttributeError when accessing self.status.simulations.

Consider adding a guard to check if the app was fully initialized before calling this method, or handle the case gracefully in print_unfinished_runs().

🛡️ Proposed fix
     if args.unfinished:
+        if not hasattr(app, 'status'):
+            logging.warning("JADE is not initialized. No simulations to report.")
+        else:
-        app.print_unfinished_runs()
+            app.print_unfinished_runs()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/jade/utilities.py` around lines 43 - 44, The call to
app.print_unfinished_runs() can raise AttributeError because JadeApp.__init__
may return early and never set self.status; update the caller to guard before
invoking the method (e.g., if hasattr(app, "status") and app.status is not None:
app.print_unfinished_runs()) or alternatively update
JadeApp.print_unfinished_runs() to handle a missing or None self.status (check
for getattr(self, "status", None) and return/print a friendly message when
absent); reference JadeApp.__init__, app.print_unfinished_runs, and
self.status.simulations when making the change.



if __name__ == "__main__":
Expand Down
10 changes: 10 additions & 0 deletions tests/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,13 @@ def test_continue_run(self):
app.run_cfg = run_cfg
command = app.continue_run(testing=True)
assert "#!/bin/sh\n\n#SBATCH" in command[0]

def test_print_unfinished_runs(self, caplog):
import logging

# Set caplog to capture INFO level logs
caplog.set_level(logging.INFO)

app = JadeApp(root=DUMMY_ROOT, skip_init=True)
app.print_unfinished_runs()
assert "Dummy_continue2" in caplog.text
Empty file added tests/helper/res/__init__.py
Empty file.
Empty file.
106 changes: 106 additions & 0 deletions tests/helper/res/rmode/sphere_more_spaces.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
MCNP XS LEAK SPHERE TEST INPUT VRT
1 0 -1 IMP:N=1 IMP:P=1
2 1 -0.302 +1 -2 IMP:N=1 IMP:P=1
3 0 +2 IMP:N=0 IMP:P=0

1 S 0 0 0 5
2 S 0 0 0 50
3 S 0 0 0 60
C

C
SDEF POS 0 0 0 PAR=N ERG=d1 $ position, particle type, energy
SI1 H 1e-6 0.1 1 10 14 $ histogram boundaries
SP1 D 0 1 1 1 1 $ probabilities for each bin
C
MODE N P
PHYS:P J 1
c
PRDMP 2J -1 $ Flag to print the mctal
C
FC2 Neutron Flux at the external surface in Vitamin-J 175 energy groups
F2:N 2
E2 1.000E-07 4.140E-07 5.316E-07 6.826E-07 8.764E-07 1.125E-06
1.445E-06 1.855E-06 2.382E-06 3.059E-06 3.928E-06 5.043E-06
6.476E-06 8.315E-06 1.068E-05 1.371E-05 1.760E-05 2.260E-05
2.902E-05 3.727E-05 4.785E-05 6.144E-05 7.889E-05 1.013E-04
1.301E-04 1.670E-04 2.145E-04 2.754E-04 3.536E-04 4.540E-04
5.829E-04 7.485E-04 9.611E-04 1.234E-03 1.585E-03 2.035E-03
2.249E-03 2.485E-03 2.613E-03 2.747E-03 3.035E-03 3.355E-03
3.707E-03 4.307E-03 5.531E-03 7.102E-03 9.119E-03 1.059E-02
1.171E-02 1.503E-02 1.930E-02 2.187E-02 2.358E-02 2.418E-02
2.479E-02 2.606E-02 2.700E-02 2.850E-02 3.183E-02 3.431E-02
4.087E-02 4.631E-02 5.248E-02 5.656E-02 6.738E-02 7.202E-02
7.950E-02 8.250E-02 8.652E-02 9.804E-02 1.111E-01 1.168E-01
1.228E-01 1.291E-01 1.357E-01 1.426E-01 1.500E-01 1.576E-01
1.657E-01 1.742E-01 1.832E-01 1.925E-01 2.024E-01 2.128E-01
2.237E-01 2.352E-01 2.472E-01 2.732E-01 2.872E-01 2.945E-01
2.972E-01 2.985E-01 3.020E-01 3.337E-01 3.688E-01 3.877E-01
4.076E-01 4.505E-01 4.979E-01 5.234E-01 5.502E-01 5.784E-01
6.081E-01 6.393E-01 6.721E-01 7.065E-01 7.427E-01 7.808E-01
8.209E-01 8.629E-01 9.072E-01 9.617E-01 1.003E+00 1.108E+00
1.165E+00 1.225E+00 1.287E+00 1.353E+00 1.423E+00 1.496E+00
1.572E+00 1.653E+00 1.738E+00 1.827E+00 1.921E+00 2.019E+00
2.122E+00 2.231E+00 2.307E+00 2.346E+00 2.365E+00 2.385E+00
2.466E+00 2.592E+00 2.725E+00 2.865E+00 3.012E+00 3.166E+00
3.329E+00 3.679E+00 4.066E+00 4.493E+00 4.724E+00 4.966E+00
5.220E+00 5.488E+00 5.770E+00 6.065E+00 6.376E+00 6.592E+00
6.703E+00 7.047E+00 7.408E+00 7.788E+00 8.187E+00 8.607E+00
9.048E+00 9.512E+00 1.000E+01 1.051E+01 1.105E+01 1.162E+01
1.221E+01 1.252E+01 1.284E+01 1.350E+01 1.384E+01 1.419E+01
1.455E+01 1.492E+01 1.568E+01 1.649E+01 1.690E+01 1.733E+01
1.964E+01
C
FC22 Gamma flux at the external surface
F22:P 2
E22: 1e-2 1e-1 1 5 20
C
FC32 Gamma flux at the external surface [FINE@FISPACT MANUAL 24 Group Structure]
F32:P 2
E32: 0.01 0.02 0.05 0.10 0.20 0.30 0.40 0.60 0.80 1.00 1.22 1.44 1.66 2.00 2.50
3.00 4.00 5.00 6.50 8.00 10.00 12.00 14.00 20.00
C
FC4 Neutron heating with F4+FM multiplier
F4:N 2
FM4 -1 1 1 -4
SD4 1
C
FC44 Gamma heating with F4+FM multiplier
F44:P 2
FM44 -1 1 -5 -6
SD44 1
C
FC6 Neutron heating F6
F6:N 2
SD6 1
C
FC46 Gamma heating F6
F46:P 2
SD46 1
C
FC12 Neutron Flux at the external surface in course energy groups
F12:N 2
E12 1e-6 0.1 1 10 20
C
FC24 T production
F24:N 2
FM24 1 1 205
SD24 1
C
FC14 He ppm production
F14:N 2
FM14 1 1 207
SD14 1
C
FC34 DPA production
F34:N 2
FM34 1 1 444
SD34 1








98 changes: 98 additions & 0 deletions tests/helper/res/rmode/sphere_no_spaces.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
MCNP XS LEAK SPHERE TEST INPUT VRT
1 0 -1 IMP:N=1 IMP:P=1
2 1 -0.302 +1 -2 IMP:N=1 IMP:P=1
3 0 +2 IMP:N=0 IMP:P=0

1 S 0 0 0 5
2 S 0 0 0 50
3 S 0 0 0 60
C

C
SDEF POS 0 0 0 PAR=N ERG=d1 $ position, particle type, energy
SI1 H 1e-6 0.1 1 10 14 $ histogram boundaries
SP1 D 0 1 1 1 1 $ probabilities for each bin
C
MODE N P
PHYS:P J 1
c
PRDMP 2J -1 $ Flag to print the mctal
C
FC2 Neutron Flux at the external surface in Vitamin-J 175 energy groups
F2:N 2
E2 1.000E-07 4.140E-07 5.316E-07 6.826E-07 8.764E-07 1.125E-06
1.445E-06 1.855E-06 2.382E-06 3.059E-06 3.928E-06 5.043E-06
6.476E-06 8.315E-06 1.068E-05 1.371E-05 1.760E-05 2.260E-05
2.902E-05 3.727E-05 4.785E-05 6.144E-05 7.889E-05 1.013E-04
1.301E-04 1.670E-04 2.145E-04 2.754E-04 3.536E-04 4.540E-04
5.829E-04 7.485E-04 9.611E-04 1.234E-03 1.585E-03 2.035E-03
2.249E-03 2.485E-03 2.613E-03 2.747E-03 3.035E-03 3.355E-03
3.707E-03 4.307E-03 5.531E-03 7.102E-03 9.119E-03 1.059E-02
1.171E-02 1.503E-02 1.930E-02 2.187E-02 2.358E-02 2.418E-02
2.479E-02 2.606E-02 2.700E-02 2.850E-02 3.183E-02 3.431E-02
4.087E-02 4.631E-02 5.248E-02 5.656E-02 6.738E-02 7.202E-02
7.950E-02 8.250E-02 8.652E-02 9.804E-02 1.111E-01 1.168E-01
1.228E-01 1.291E-01 1.357E-01 1.426E-01 1.500E-01 1.576E-01
1.657E-01 1.742E-01 1.832E-01 1.925E-01 2.024E-01 2.128E-01
2.237E-01 2.352E-01 2.472E-01 2.732E-01 2.872E-01 2.945E-01
2.972E-01 2.985E-01 3.020E-01 3.337E-01 3.688E-01 3.877E-01
4.076E-01 4.505E-01 4.979E-01 5.234E-01 5.502E-01 5.784E-01
6.081E-01 6.393E-01 6.721E-01 7.065E-01 7.427E-01 7.808E-01
8.209E-01 8.629E-01 9.072E-01 9.617E-01 1.003E+00 1.108E+00
1.165E+00 1.225E+00 1.287E+00 1.353E+00 1.423E+00 1.496E+00
1.572E+00 1.653E+00 1.738E+00 1.827E+00 1.921E+00 2.019E+00
2.122E+00 2.231E+00 2.307E+00 2.346E+00 2.365E+00 2.385E+00
2.466E+00 2.592E+00 2.725E+00 2.865E+00 3.012E+00 3.166E+00
3.329E+00 3.679E+00 4.066E+00 4.493E+00 4.724E+00 4.966E+00
5.220E+00 5.488E+00 5.770E+00 6.065E+00 6.376E+00 6.592E+00
6.703E+00 7.047E+00 7.408E+00 7.788E+00 8.187E+00 8.607E+00
9.048E+00 9.512E+00 1.000E+01 1.051E+01 1.105E+01 1.162E+01
1.221E+01 1.252E+01 1.284E+01 1.350E+01 1.384E+01 1.419E+01
1.455E+01 1.492E+01 1.568E+01 1.649E+01 1.690E+01 1.733E+01
1.964E+01
C
FC22 Gamma flux at the external surface
F22:P 2
E22: 1e-2 1e-1 1 5 20
C
FC32 Gamma flux at the external surface [FINE@FISPACT MANUAL 24 Group Structure]
F32:P 2
E32: 0.01 0.02 0.05 0.10 0.20 0.30 0.40 0.60 0.80 1.00 1.22 1.44 1.66 2.00 2.50
3.00 4.00 5.00 6.50 8.00 10.00 12.00 14.00 20.00
C
FC4 Neutron heating with F4+FM multiplier
F4:N 2
FM4 -1 1 1 -4
SD4 1
C
FC44 Gamma heating with F4+FM multiplier
F44:P 2
FM44 -1 1 -5 -6
SD44 1
C
FC6 Neutron heating F6
F6:N 2
SD6 1
C
FC46 Gamma heating F6
F46:P 2
SD46 1
C
FC12 Neutron Flux at the external surface in course energy groups
F12:N 2
E12 1e-6 0.1 1 10 20
C
FC24 T production
F24:N 2
FM24 1 1 205
SD24 1
C
FC14 He ppm production
F14:N 2
FM14 1 1 207
SD14 1
C
FC34 DPA production
F34:N 2
FM34 1 1 444
SD34 1
99 changes: 99 additions & 0 deletions tests/helper/res/rmode/sphere_rmode.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
MCNP XS LEAK SPHERE TEST INPUT VRT
1 0 -1 IMP:N=1 IMP:P=1
2 1 -0.302 +1 -2 IMP:N=1 IMP:P=1
3 0 +2 IMP:N=0 IMP:P=0

1 S 0 0 0 5
2 S 0 0 0 50
3 S 0 0 0 60
C

C
SDEF POS 0 0 0 PAR=N ERG=d1 $ position, particle type, energy
SI1 H 1e-6 0.1 1 10 14 $ histogram boundaries
SP1 D 0 1 1 1 1 $ probabilities for each bin
C
MODE N P
PHYS:P J 1
c
PRDMP 2J -1 $ Flag to print the mctal
C
FC2 Neutron Flux at the external surface in Vitamin-J 175 energy groups
F2:N 2
E2 1.000E-07 4.140E-07 5.316E-07 6.826E-07 8.764E-07 1.125E-06
1.445E-06 1.855E-06 2.382E-06 3.059E-06 3.928E-06 5.043E-06
6.476E-06 8.315E-06 1.068E-05 1.371E-05 1.760E-05 2.260E-05
2.902E-05 3.727E-05 4.785E-05 6.144E-05 7.889E-05 1.013E-04
1.301E-04 1.670E-04 2.145E-04 2.754E-04 3.536E-04 4.540E-04
5.829E-04 7.485E-04 9.611E-04 1.234E-03 1.585E-03 2.035E-03
2.249E-03 2.485E-03 2.613E-03 2.747E-03 3.035E-03 3.355E-03
3.707E-03 4.307E-03 5.531E-03 7.102E-03 9.119E-03 1.059E-02
1.171E-02 1.503E-02 1.930E-02 2.187E-02 2.358E-02 2.418E-02
2.479E-02 2.606E-02 2.700E-02 2.850E-02 3.183E-02 3.431E-02
4.087E-02 4.631E-02 5.248E-02 5.656E-02 6.738E-02 7.202E-02
7.950E-02 8.250E-02 8.652E-02 9.804E-02 1.111E-01 1.168E-01
1.228E-01 1.291E-01 1.357E-01 1.426E-01 1.500E-01 1.576E-01
1.657E-01 1.742E-01 1.832E-01 1.925E-01 2.024E-01 2.128E-01
2.237E-01 2.352E-01 2.472E-01 2.732E-01 2.872E-01 2.945E-01
2.972E-01 2.985E-01 3.020E-01 3.337E-01 3.688E-01 3.877E-01
4.076E-01 4.505E-01 4.979E-01 5.234E-01 5.502E-01 5.784E-01
6.081E-01 6.393E-01 6.721E-01 7.065E-01 7.427E-01 7.808E-01
8.209E-01 8.629E-01 9.072E-01 9.617E-01 1.003E+00 1.108E+00
1.165E+00 1.225E+00 1.287E+00 1.353E+00 1.423E+00 1.496E+00
1.572E+00 1.653E+00 1.738E+00 1.827E+00 1.921E+00 2.019E+00
2.122E+00 2.231E+00 2.307E+00 2.346E+00 2.365E+00 2.385E+00
2.466E+00 2.592E+00 2.725E+00 2.865E+00 3.012E+00 3.166E+00
3.329E+00 3.679E+00 4.066E+00 4.493E+00 4.724E+00 4.966E+00
5.220E+00 5.488E+00 5.770E+00 6.065E+00 6.376E+00 6.592E+00
6.703E+00 7.047E+00 7.408E+00 7.788E+00 8.187E+00 8.607E+00
9.048E+00 9.512E+00 1.000E+01 1.051E+01 1.105E+01 1.162E+01
1.221E+01 1.252E+01 1.284E+01 1.350E+01 1.384E+01 1.419E+01
1.455E+01 1.492E+01 1.568E+01 1.649E+01 1.690E+01 1.733E+01
1.964E+01
C
FC22 Gamma flux at the external surface
F22:P 2
E22: 1e-2 1e-1 1 5 20
C
FC32 Gamma flux at the external surface [FINE@FISPACT MANUAL 24 Group Structure]
F32:P 2
E32: 0.01 0.02 0.05 0.10 0.20 0.30 0.40 0.60 0.80 1.00 1.22 1.44 1.66 2.00 2.50
3.00 4.00 5.00 6.50 8.00 10.00 12.00 14.00 20.00
C
FC4 Neutron heating with F4+FM multiplier
F4:N 2
FM4 -1 1 1 -4
SD4 1
C
FC44 Gamma heating with F4+FM multiplier
F44:P 2
FM44 -1 1 -5 -6
SD44 1
C
FC6 Neutron heating F6
F6:N 2
SD6 1
C
FC46 Gamma heating F6
F46:P 2
SD46 1
C
FC12 Neutron Flux at the external surface in course energy groups
F12:N 2
E12 1e-6 0.1 1 10 20
C
FC24 T production
F24:N 2
FM24 1 1 205
SD24 1
C
FC14 He ppm production
F14:N 2
FM14 1 1 207
SD14 1
C
FC34 DPA production
F34:N 2
RMODE 0
FM34 1 1 444
SD34 1
Loading
Loading