fix(geant4): fail cleanly on unknown physics lists, count worker kernels#52
Conversation
📝 WalkthroughWalkthroughGeant4Sim now validates unknown physics lists before run-manager construction, reports completed and excess worker kernels, adds a concurrent clean-failure test, and updates reproducibility notes on event ordering, RNG streams, and TBB thread churn. ChangesGeant4 runtime observability
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
6df4050 to
3d85317
Compare
7897e2f to
4c9c9a2
Compare
3d85317 to
27ff670
Compare
4c2fb47 to
48e43fc
Compare
4c9c9a2 to
3417360
Compare
19ae236 to
9feddd2
Compare
3417360 to
2f660ec
Compare
Physics Metrics Comparison1 configuration(s) have differences
Configurations with Differences
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/geant4_module.cpp`:
- Around line 122-124: Update the shutdown summary near the `next_thread_id_`
check to use a dedicated atomic counter for successfully initialized kernels,
rather than allocated worker IDs. Increment that counter only after
`init_worker()` completes successfully, and report its value while preserving
the existing logging condition and message.
- Around line 284-290: Move the physics-list validation using
G4PhysListFactory::IsReferencePhysList before init_master() allocates the leaked
G4MTRunManager or detector_. Preserve the existing unknown-list exception and
only construct/register those resources after validation succeeds; add a
regression test covering a failed initialization followed by retry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ec7f0450-562d-4f8e-b5f8-29981c9f9a63
📒 Files selected for processing (2)
docs/geant4-perf-notes.mdsrc/geant4_module.cpp
2f660ec to
493213c
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/geant4-perf-notes.md`:
- Around line 67-69: Update the per-event RNG follow-up guidance near the
discussion of next_event_id_ so it requires seeding from a stable upstream
input-event identifier, or explicitly preserving input ordering before assigning
event IDs. Do not present arrival-order IDs from next_event_id_.fetch_add(1) as
a reproducibility fix.
In `@scripts/physics_list_failure.sh`:
- Around line 51-52: Make the concurrency test around the phlex invocation
deterministic by adding an observable retry counter or equivalent test hook for
the std::call_once retry path. Update the assertion in
scripts/physics_list_failure.sh to require that the counter records at least one
retry, while preserving the existing command and return-code checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 344318fb-3d94-46d6-8844-05143bdf2210
📒 Files selected for processing (4)
CMakeLists.txtdocs/geant4-perf-notes.mdscripts/physics_list_failure.shsrc/geant4_module.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
- src/geant4_module.cpp
- Validate the physics list with IsReferencePhysList before allocating the detector or the leaked G4MTRunManager: GetReferencePhysList aborts the process via a fatal G4Exception on unknown names. Validating up front (as the export_gdml pre-check already does) turns a bad config into a catchable std::runtime_error, which the sticky-init path then reports cleanly instead of crashing the process. - Count only kernels that finish init_worker successfully in the shutdown summary, via a dedicated atomic, rather than the id allocated on entry. Warn when TBB thread churn builds more kernels than configured slots: each new pool thread that ever runs simulate builds its own kernel, silently costing memory and a fresh RNG stream. - Add a physics_list_failure integration test: an unknown list under concurrent init must exit with the clear error and no "constructed twice" run-manager abort. - Correct the reproducibility mechanism in docs/geant4-perf-notes.md: the dominant effect is event-order nondeterminism against a continuous per-kernel RNG stream, observed even in runs with a single kernel; per-event seeding from the stable cell index (PR #54) is the fix.
493213c to
9e2daa9
Compare
IsReferencePhysListbeforeGetReferencePhysList, which aborts the process via a fatal G4Exception on unknown names. A bad config now turns into a catchablestd::runtime_error, which the sticky-init path on main reports cleanly instead of a core dump.SetNumberOfThreadsin this direct-injection flow (verified empirically), but it should be visible.docs/geant4-perf-notes.md: the dominant effect is event-order nondeterminism against a continuous per-kernel RNG stream, observed even in runs where only a single kernel was built. Per-event seeding from the stable cell index (feat(geant4): seed the RNG per event from the data-cell index #54) is the fix, not the arrival-orderG4Eventid.Rebased onto current
main; the sticky-init and geometry-store-cleanup fixes it now carries make the earlier "clean retry" framing obsolete, so this change keeps only the up-front validation (which complements sticky init), the kernel accounting, and the docs correction.Summary by CodeRabbit
Bug Fixes
Tests
Documentation