You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Disambiguate colliding mesh, filter, and tally IDs in get_microxs_and_flux - #4257
openmc.deplete.get_microxs_and_flux writes a model's settings meshes before its tally meshes and silently drops duplicate mesh IDs in mesh_memo during XML export. When a domain mesh passed to get_microxs_and_flux shares an ID (for example mesh_id=1, or any ID reused after openmc.reset_auto_ids()) with a weight-window mesh, another settings mesh, or a mesh on a retained model tally, the tally mesh definition is omitted and the tally silently scores on the wrong mesh (or fails in split-XML mode). Live filter and tally IDs can also collide with the temporary filters and tallies created by get_microxs_and_flux when IDs were reset after building the model.
Who hits this: OpenMC users calling openmc.deplete.get_microxs_and_flux(model, domains=mesh, ...) on a model that already defines a weight-window mesh, another settings mesh, or a retained tally mesh with the same ID, or after openmc.reset_auto_ids() (#3549).
Changes:
Add Settings._iter_meshes() in openmc/settings.py yielding meshes referenced by settings XML (sources, entropy_mesh, temperature_field, ufs_mesh, weight_windows, weight_window_generators, and random_ray['source_region_meshes']).
Add _next_id(cls, occupied_ids) and _disambiguate_mesh_filters(...) in openmc/deplete/microxs.py to copy and assign distinct run-local IDs to colliding domain meshes (and their MeshFilter copies) and reserve live filter and tally IDs before creating temporary energy filters, domain filters, and MicroXS tallies.
Preserve caller-owned meshes, filters, weight windows, and model.tallies, restoring model.tallies in a finally block even if execution raises.
Add unit tests in tests/unit_tests/test_deplete_microxs.py covering weight-window/settings/retained-tally mesh ID collisions, openmc.reset_auto_ids() filter and tally ID collisions, combined and split XML export, and finally restoration.
Scope note: settings.weight_windows_file (HDF5 path-only weight windows without in-memory Settings.weight_windows objects) is out of scope for this PR.
Verified locally: all 47 tests in tests/unit_tests/test_deplete_microxs.py pass (with the new regression tests failing before the patch), combined/split XML and openmc.lib transport outputs match distinct-ID controls bit-for-bit, and 349 non-ENDF unit tests across weightwindows/, test_mesh.py, test_tallies.py, test_model.py, and test_deplete*.py pass with 0 regressions.
This fix and its tests were found, written, and cross-checked with AI agents, including an independent clean-room verification pass from a separate model family before opening this PR.
Harness: Codex CLI (initial diagnosis and patch); Antigravity CLI (ID-unification polish and tests); Claude Code (independent clean-room reproduction and verification)
get_microxs_and_flux now avoids ID conflicts between domain meshes, settings meshes, filters, and tallies. It conditionally includes model tallies in the run and restores the original tally collection after transport and statepoint processing, including when an exception occurs.
Changes: MicroXS mesh and tally handling
Layer / File(s)
Summary
Mesh and filter ID handling openmc/settings.py, openmc/deplete/microxs.py, tests/unit_tests/test_deplete_microxs.py
Settings._iter_meshes yields meshes referenced by configured settings. The microXS path assigns unoccupied filter and tally IDs and copies domain mesh filters when their meshes conflict with settings or retained tally meshes. Tests cover mesh and filter ID conflicts, including after ID resets.
Tally collection and transport lifecycle openmc/deplete/microxs.py, tests/unit_tests/test_deplete_microxs.py
The run tally collection includes model tallies only when requested. A finally block restores the original collection after transport and result processing. Tests check tally ID handling after ID resets.
The change prevents mesh, filter, and tally ID collisions in get_microxs_and_flux and restores the model's tallies after the run, including on failure. No actionable merge-blocking risk was found. The remaining comment is a minor test-fixture consistency suggestion.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: colliding mesh, filter, and tool IDs in get_microxs_and_flux are disambiguated. The changeset adds ID reservation and copying of colliding domain meshes in openmc/depl…
Description check
The description follows the repository template. It has a Description section with a summary, motivation, and a link to issue #3549, and it includes a 'Fixes #3549' line. It has an AI Assistance secti…
Linked Issues check
[#3549] Requirement: when a model has weight windows, get_microxs_and_flux must use the mesh passed through domains, not an existing mesh with the same ID. At the reviewed head, `_disambiguate_mes…
Out of Scope Changes check
The changes in openmc/deplete/microxs.py, openmc/settings.py, and tests/unit_tests/test_deplete_microxs.py serve the ID-collision fix. Settings._iter_meshes() enumerates settings meshes for co…
Full details: Title check
Explanation
The title names the main change: colliding mesh, filter, and tool IDs in get_microxs_and_flux are disambiguated. The changeset adds ID reservation and copying of colliding domain meshes in openmc/deplete/microxs.py, plus a settings mesh iterator, which matches the title. The title is specific and concise.
Full details: Description check
Explanation
The description follows the repository template. It has a Description section with a summary, motivation, and a link to issue #3549, and it includes a 'Fixes #3549' line. It has an AI Assistance section that lists harness, model, and reasoning effort. The checklist is filled in, with some items left unchecked. The description is detailed and covers the scope note, the verification steps, and the tests added.
Full details: Linked Issues check
Explanation
[#3549] Requirement: when a model has weight windows, get_microxs_and_flux must use the mesh passed through domains, not an existing mesh with the same ID. At the reviewed head, _disambiguate_mesh_filters in openmc/deplete/microxs.py checks each domain MeshFilter mesh ID against meshes from Settings._iter_meshes() (which covers weight_windows and weight_window_generators), and against meshes on retained model tallies. On a collision, it copies the domain mesh and its MeshFilter, assigns a fresh run-local mesh ID and filter ID, and uses the copy in the temporary flux and reaction-rate tallies. Caller objects are not changed. Unit tests named in the PR cover weight-window mesh collisions in explicit, automatic, shared, and reset-ID modes, and check the exported XML references. The fix addresses the reported ID-collision mechanism. Residual limit: the PR excludes settings.weight_windows_file (path-only HDF5 weight windows). The issue workaround mentions editing ww.h5. The reproduction in the issue states only that weight windows are applied, so the excluded path does not block this verdict, but it is a known gap for file-based workflows.
Full details: Out of Scope Changes check
Explanation
The changes in openmc/deplete/microxs.py, openmc/settings.py, and tests/unit_tests/test_deplete_microxs.py serve the ID-collision fix. Settings._iter_meshes() enumerates settings meshes for collision checks. _next_id and the filter and tally ID reservation prevent collisions after openmc.reset_auto_ids(). The try/finally block restores model.tallies, which the new temporary tallies require. Moving transport and statepoint processing inside that block supports the same restoration. Two smaller changes are not tied to ID collisions: energy group names are checked with check_value before lookup in GROUP_STRUCTURES, and the energies string path no longer calls EnergyFilter.from_group_structure. These are minor validation and refactoring changes. They do not alter the scope of the linked issue, but a reviewer should confirm that the group-structure lookup gives the same bins as the previous path.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Add the required run_in_tmpdir fixture.
These four tests create XML files but request only tmp_path. Add run_in_tmpdir to each test signature. Keep tmp_path for the explicit export paths. The fixture also isolates the working directory and restores it after failure. (raw.githubusercontent.com)
As per coding guidelines, “Use run_in_tmpdir fixture for tests that create files.”
Also applies to: 281-281, 363-363, 472-472
Source: Coding guidelines
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 81b1ceb8-03a2-4284-b2b4-82f0ea9166d9
Commits
Reviewing files that changed from the base of the PR and between 5d63501 and eb5344e.
Files selected for processing: 3
openmc/deplete/microxs.py
openmc/settings.py
tests/unit_tests/test_deplete_microxs.py
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
openmc.deplete.get_microxs_and_fluxwrites a model's settings meshes before its tally meshes and silently drops duplicate mesh IDs inmesh_memoduring XML export. When a domain mesh passed toget_microxs_and_fluxshares an ID (for examplemesh_id=1, or any ID reused afteropenmc.reset_auto_ids()) with a weight-window mesh, another settings mesh, or a mesh on a retained model tally, the tally mesh definition is omitted and the tally silently scores on the wrong mesh (or fails in split-XML mode). Live filter and tally IDs can also collide with the temporary filters and tallies created byget_microxs_and_fluxwhen IDs were reset after building the model.Who hits this: OpenMC users calling
openmc.deplete.get_microxs_and_flux(model, domains=mesh, ...)on a model that already defines a weight-window mesh, another settings mesh, or a retained tally mesh with the same ID, or afteropenmc.reset_auto_ids()(#3549).Changes:
Settings._iter_meshes()inopenmc/settings.pyyielding meshes referenced by settings XML (sources,entropy_mesh,temperature_field,ufs_mesh,weight_windows,weight_window_generators, andrandom_ray['source_region_meshes'])._next_id(cls, occupied_ids)and_disambiguate_mesh_filters(...)inopenmc/deplete/microxs.pyto copy and assign distinct run-local IDs to colliding domain meshes (and theirMeshFiltercopies) and reserve live filter and tally IDs before creating temporary energy filters, domain filters, andMicroXStallies.model.tallies, restoringmodel.talliesin afinallyblock even if execution raises.tests/unit_tests/test_deplete_microxs.pycovering weight-window/settings/retained-tally mesh ID collisions,openmc.reset_auto_ids()filter and tally ID collisions, combined and split XML export, andfinallyrestoration.Scope note:
settings.weight_windows_file(HDF5 path-only weight windows without in-memorySettings.weight_windowsobjects) is out of scope for this PR.Verified locally: all 47 tests in
tests/unit_tests/test_deplete_microxs.pypass (with the new regression tests failing before the patch), combined/split XML andopenmc.libtransport outputs match distinct-ID controls bit-for-bit, and 349 non-ENDF unit tests acrossweightwindows/,test_mesh.py,test_tallies.py,test_model.py, andtest_deplete*.pypass with 0 regressions.Fixes #3549
AI Assistance
This fix and its tests were found, written, and cross-checked with AI agents, including an independent clean-room verification pass from a separate model family before opening this PR.
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N
Summary by CodeRabbit