Skip to content

Fix MF33 parsing: duplicate LTY=0 NC sub-subsections and LB 0-4 array split - #48

Open
GuySten wants to merge 2 commits into
paulromano:mainfrom
GuySten:fix-mf33-lty0-lb-split
Open

GuySten wants to merge 2 commits into
paulromano:mainfrom
GuySten:fix-mf33-lty0-lb-split

Conversation

@GuySten

@GuySten GuySten commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

This PR fixes two problems in parse_mf33_subsection (src/endf/mf33.py). The function is also used by parse_mf40, so both bugs affect MF=33 and MF=40.

1. LTY=0 NC-type sub-subsections are appended twice

The LTY == 0 branch appends subsub to subsection['nc_subsections'], and the unconditional append after the if/else adds it a second time. As a result, len(subsection['nc_subsections']) can exceed NC. This PR removes the append inside the branch.

2. LB=0-4 tables are split at the wrong index

ENDF-102 (BNL-224854-2023-INRE), Section 33.2.2.2, gives the record layout for LB=0 to 4:

[MAT,33,MT/ 0.0, 0.0, LT, LB, NT, NP/ {Ek,Fk}{El,Fl}]LIST

The manual defines these quantities:

  • NP is the total number of pairs in the arrays {Ek,Fk}{El,Fl}.
  • NT is the total number of values in the LIST record, so NT = 2*NP.
  • LT is the number of pairs in the second array {El,Fl}. If LT = 0, the table contains only {Ek,Fk}; otherwise {Ek,Fk} has NP - LT pairs.

The {Ek,Fk} table is therefore values[:2*(NP - LT)]. The current code slices at NT - NP, which equals NP values, or only NP/2 pairs. When LT = 0, which always holds for LB=0, 1 and 2, the second half of the Ek-table ends up in El/Fl. When LT > 0, the split is correct only by coincidence, when NP = 2*LT.

Tests

The new file tests/test_mf33.py builds a small MF=33 section by hand. It contains:

  • one LTY=0 and one LTY=1 NC-type sub-subsection
  • three NI-type sub-subsections: LB=1 with LT=0, LB=3 with LT=2 and NP=5, and LB=4 with LT=1 and NP=3

The tests check that each NC sub-subsection appears exactly once, with the right contents, and that every pair lands in the correct E-table. Both tests fail on main and pass with this change. The full suite passes: python -m pytest -ra tests reports 26 passed.

🤖 Generated with Claude Code

GuySten and others added 2 commits November 20, 2026 22:06
* NC-type sub-subsections with LTY=0 were appended to
  'nc_subsections' twice (once inside the LTY=0 branch and again after
  the if/else).
* For NI-type sub-subsections with LB=0-4, the list was split into the
  {Ek,Fk} and {El,Fl} tables at NT - NP = NP values. Per ENDF-102
  Section 33.2.2.2, NP is the total number of pairs, NT = 2*NP, and LT
  is the number of pairs in the second table, so the first table holds
  NP - LT pairs, i.e. 2*(NP - LT) values. With LT=0 (always the case for
  LB=0, 1, 2) half of the Ek-table ended up in the El-table.

Add regression tests built from a hand-written MF=33 section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant