Skip to content

fix: draw random trajectory noise from a private generator - #64

Merged
sypsyp97 merged 5 commits into
sypsyp97:mainfrom
cslht11:fix/random-trajectory-local-rng
Nov 2, 2026
Merged

sypsyp97 merged 5 commits into
sypsyp97:mainfrom
cslht11:fix/random-trajectory-local-rng

Conversation

@cslht11

@cslht11 cslht11 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

random_trajectory_3d called torch.manual_seed(seed), which seeds the
process-wide generator: every random draw in the calling script after that call
silently restarted from the trajectory's seed.

Draw from a private torch.Generator on the target device instead. It replays
the same stream the process-wide one produced, so seeded trajectories stay
bit-identical (checked against 2.5.0 on an RTX 4090: max abs diff 0.0). int()
keeps the seed forms torch.manual_seed accepted, which a fresh generator
rejects.

Tests: three cases in tests/test_geometry_input_validation.py - the global
generator is untouched, the seed is reproducible, and a seeded trajectory still
replays the previous stream. 188/188 in that file.

cslht11 and others added 5 commits November 1, 2026 05:22
random_trajectory_3d seeded the process-wide generator, so every later
random draw in the calling script silently restarted from that seed. Draw
from a private generator instead.

A generator on the target device replays the stream the process-wide one
produced, so seeded trajectories stay bit-identical on CPU, MPS and CUDA
(checked against 2.5.0 on an RTX 4090: max abs diff 0.0). int() keeps the
seed forms torch.manual_seed accepted, which a fresh Generator would
otherwise reject.
@sypsyp97

sypsyp97 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks! I pushed two small follow-ups: the noise now follows the trajectory tensors' dtype and device (angle tensors can override the device and dtype arguments), and a missing per-device generator now raises instead of silently switching to a CPU stream with different values. The tests compare against a local copy of the previous algorithm, so they do not need git history.

@sypsyp97
sypsyp97 merged commit a2bcbd8 into sypsyp97:main Nov 2, 2026
11 checks passed
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.

2 participants