Skip to content

fix: handle mixed BURN_STEP shapes in results reader (Serpent 2.2.3+)#539

Open
steps-re wants to merge 2 commits into
CORE-GATECH-GROUP:mainfrom
steps-re:fix/resdata-mixed-shape-burn-step
Open

fix: handle mixed BURN_STEP shapes in results reader (Serpent 2.2.3+)#539
steps-re wants to merge 2 commits into
CORE-GATECH-GROUP:mainfrom
steps-re:fix/resdata-mixed-shape-burn-step

Conversation

@steps-re

@steps-re steps-re commented Jul 8, 2026

Copy link
Copy Markdown

Summary

Serpent 2.2.3 changed how BURN_STEP is written in *_res.m files. For burnup steps it emits a 3-element vector, but for decay steps it emits a scalar:

% burnup step
BURN_STEP (idx, [1: 3]) = [ 0 1 0 ];

% decay step — different shape!
BURN_STEP (idx, 1) = 19;

ListOfArrays enforced consistent shapes across all appended rows, so reading any *_res.m file with decay steps crashed with:

ValueError: Shapes do not agree: Current (3,) vs. incoming (1,)

Fix

Modified ListOfArrays.append to:

  1. Emit a UserWarning on the first shape mismatch (once, not on every step)
  2. Switch to ragged (object-dtype) storage instead of raising

Files with consistent shapes (all prior Serpent versions) are completely unaffected — the code path is unchanged for them.

Tests

Three new unit tests added to test_results.py:

  • test_list_of_arrays_consistent_shapes — stacked 2-D array for uniform shapes
  • test_list_of_arrays_ragged_warns_and_stores — single UserWarning + correct object array for mixed shapes
  • test_list_of_arrays_ragged_no_extra_warning — no duplicate warnings after first mismatch

All 7 results tests pass.

Fixes #537

Signed-off-by: Mike German mike@stepsventures.com

steps-re added 2 commits July 8, 2026 09:19
Serpent 2.2.3 with ``set depmtx 1`` writes additional scalar and matrix
declaration lines (e.g. ``flx = 2;``, ``N0 = zeros(n, 1);``) between the
time header and the first N0 isotope entry.  The reader raised a
``SerpentToolsException`` when it hit these unrecognized lines.

Add a loop in ``DepmtxReader._read`` that advances past any lines which do
not match ``NDENS_REGEX`` before starting to parse the N0 block.  The fix
is backward-compatible: files without extra lines are parsed identically.

Add a regression test that prepends ``flx`` and ``N0 = zeros`` lines to
the existing ``depmtx_ref.m`` fixture and verifies the parsed arrays match
the reference reader output exactly.

Fixes CORE-GATECH-GROUP#533

Signed-off-by: Mike German <mike@stepsventures.com>
Serpent 2.2.3 writes BURN_STEP as a 3-element vector for burnup steps
  BURN_STEP (idx, [1: 3]) = [ 0 1 0 ]
but as a scalar for decay steps
  BURN_STEP (idx, 1) = 19

ListOfArrays enforced consistent shapes and raised ValueError when these
were mixed, crashing the results reader on any file that included decay
steps.

Change ListOfArrays to warn (UserWarning) on the first shape mismatch
and switch to ragged (object-dtype) storage rather than raising.
Existing files with consistent shapes are unaffected.

Three unit tests added to verify correct warning emission, correct
object-array output for ragged data, and absence of duplicate warnings
after the first mismatch.

Fixes CORE-GATECH-GROUP#537

Signed-off-by: Mike German <mike@stepsventures.com>
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.

BUG Reading Serpent 2.2.3 res.m file

1 participant