Skip to content

Fix for Weight Window Scaling Bug#3511

Merged
paulromano merged 6 commits into
openmc-dev:developfrom
jtramm:ww_scale_fix
Jul 29, 2025
Merged

Fix for Weight Window Scaling Bug#3511
paulromano merged 6 commits into
openmc-dev:developfrom
jtramm:ww_scale_fix

Conversation

@jtramm

@jtramm jtramm commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in the weight window scaling logic. Currently, weight windows are scaled up/down in two areas in response to certain conditions being met. In the case of birth weight scaling (PR #3459), this is done to ensure that weight windows are scaled so as to be responsive to the weight window value of where the particle was sampled, such that rouletting/splitting does not happen immediately at birth.

I was noticing some significant bias in tallies in the JET problem when weight windows were enabled vs. just analog MC. This was being caused by the scaling function only scaling the lower and upper weight window bounds, rather than the survival weight as well. In effect, when particles would be in a weight window zone that triggered the rouletting routine, the routine would have a survival weight that would be far below the actual particle weight. This means the particles would always pass the roulette successfully and have their weights cut down to the unscaled survival weight, leading to a significant overall net loss of weight from the simulation.

This fix simply ensures the survival weight also gets scaled, such that rouletting happens in the expected manner.

Below is the data for a specific detector tally in JET (the A1 TLD which is quite close to the tokamak, allowing for it to be possible to get some tallies scores on with just analog MC).

Flux
Experimental 2.98E-09
MCNP - Weight Windows 2.35E-09
OpenMC - Analog 2.82E-09
OpenMC - Weight Windows (current branch) 1.45e-09
OpenMC - Weight Windows (this PR) 2.01E-09

Notably, the difference between the analog and WW cases is still larger than expected. There is a lot of uncertainty with the analog case, however, so it's unclear if this is real bias or just noise. Even if there is another bug in the weight window logic somewhere else still causing bias, the current fix is still necessary.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug in the weight window scaling logic where the survival weight was not being scaled along with the lower and upper weight bounds. This caused particles to always pass roulette checks with significantly reduced weights, leading to substantial bias in tallies (e.g., JET problem showing 1.45e-09 vs expected ~2.8e-09 flux values).

  • Adds scaling of survival_weight in the WeightWindow scale() method
  • Ensures consistent weight window behavior during rouletting/splitting operations
  • Addresses significant tally bias observed in complex geometries like JET tokamak simulations

@pshriwise pshriwise left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tracking this down @jtramm. Just one question about the test updates.


def test_weightwindows(model):
test = HashedPyAPITestHarness('statepoint.2.h5', model)
test = TolerantPyAPITestHarness('statepoint.2.h5', model)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for updating the results! Why the change to the tolerance test harness? The results should still be reproducible right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to reproduce the statepoint hash even for that test on the original develop branch (I tried on both my mac and a linux cluster). Even for serial execution, compilers have a free hand in re-ordering operations that are associative mathematically, but non-associative for floating point, such that the bit-wise reproducibility that statepoint hashing requires seems difficult to achieve in a portable manner. The tolerant test harness still requires the simulation be reproducible, but results are rounded such that everything doesn't need to be bitwise the same.

That said, I'm surprised it is still failing now with the tolerant test. The test passes on both my mac and the linux cluster I'm on (with gcc 11.1, 13.3, and LLVM 20.1.2), so I'm not sure what is causing the failure. Will look into it a bit more, perhaps we need to run with fewer particles or something.

@jtramm

jtramm commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

Update: I converged things a little more for both the analog and new weight window runs in OpenMC, and also looked at the B1 results since they were more well resolved with the higher runtime in the analog case. The results show very close agreement between OpenMC (with and without weight windows) and MCNP (which was converged to +/-5%). Thus, I don't believe there is any remaining bias due to weight windows -- this PR should fix everything.

A1 Tally B1 Tally
OpenMC - Analog 2.16E-09 1.11E-08
OpenMC - Weight Windows (Current develop) 1.45e-09 7.08e-09
OpenMC - Weight Windows (This PR) 2.27E-09 1.09E-08
MCNP - Weight Windows 2.35E-09 1.09E-08

Now I just need to figure out the issue with the testing...

@paulromano paulromano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jtramm Thanks for this important fix! When I update the test result on my machine, it looks like the hash value matches what gets produced on our CI runners so I expect the tests should pass now 🟢 Not sure why your system is producing different values but I wouldn't be surprised if it comes down to some subtle difference between Linux and Mac (part of the reason we still don't have CI configurations on macOS).

@paulromano
paulromano enabled auto-merge (squash) July 29, 2025 07:51
@paulromano
paulromano merged commit 4cce6ee into openmc-dev:develop Jul 29, 2025
14 checks passed
yardasol pushed a commit to yardasol/openmc that referenced this pull request Dec 25, 2025
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 2026
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants