Skip to content

[WIP] Seeded RNG - #309

Open
drobnyjt wants to merge 15 commits into
devfrom
rng_seeded
Open

[WIP] Seeded RNG#309
drobnyjt wants to merge 15 commits into
devfrom
rng_seeded

Conversation

@drobnyjt

@drobnyjt drobnyjt commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your contribution to rustBCA!

Before submitting this PR, please make sure you have:

  • Opened an issue
  • Referenced the relevant issue number(s) below
  • Provided a description of the changes below
  • Ensured all tests pass and added any necessary tests for new code

Fixes #308, #306, #305, #310

Description

This PR adds a seeded RNG (ChaCha8) to make RustBCA deterministic; as a first pass, the seed will be hardcoded - before merge, I'd like to have it be an optional input parameter.

This also rolls in the powf -> powi optimizations (there's a minor performance cost to determinism that is basically completely counteracted by these optimizations) and the Biersack-Varelas stopping power correction factor change.

I've also updated the README doctests to take advantage of the new determinism.

Remaining tasks:

  • add ability to specify seed
  • investigate feasibility of environment variable seed for python functions
  • update docs once code updates finished to include implementation details

Tests

Cargo test passes; using CI to make sure nothing's broken.

@drobnyjt

drobnyjt commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author
image

Test using libRustBCA; need to compare all example outputs as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This line in the github action lets you manually hit a "run workflow" button in the UI

@drobnyjt
drobnyjt changed the base branch from main to dev July 28, 2026 02:15
drobnyjt added 3 commits July 28, 2026 00:01
…NG values; fixed simple_bca PRNG so that it gets a new rng with each particle.
…ers switched to thread-level seeds from prngs.
@drobnyjt

Copy link
Copy Markdown
Collaborator Author
Switched to branch 'rng_seeded'
M       examples/make_input_file_and_run.py
Your branch is up to date with 'origin/rng_seeded'.
...
Processing 1000000 ions...
Initializing with 6 threads...
[00:03:11][########################################][00:00:00] 100%
Finished!
H on B-TiB2-Ti
R_N, R_E: 0.405277, 0.14430882622055832
Y: 0.07703 [at./ion]

H on B (default settings)
Y: 0.0769 [at./ion]
R_N, R_E: (0.3553, 0.13995051092991748)
Switched to branch 'dev'
...
Processing 1000000 ions...
Initializing with 6 threads...
[00:03:15][########################################][00:00:00] 100%
Finished!
H on B-TiB2-Ti
R_N, R_E: 0.405419, 0.14406380591577478
Y: 0.076484 [at./ion]

H on B (default settings)
Y: 0.0757 [at./ion]
R_N, R_E: (0.3523, 0.13869173319541878)
comparison

Comparing the rng_seeded branch to dev with make_input_file_and_run.py (modified)

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.

[feature] Seeded RNG

1 participant