refactor: wire sample_hidden_graph RNG through RNGRoot#35
Merged
Conversation
Change sample_hidden_graph() to accept an RNGRoot instance instead of a bare int seed, aligning it with the cross-component RNG convention established in PR #34. The old int-seed interface is preserved with a deprecation warning for backward compatibility. Closes #9 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR refactors leadforge.structure.sampler.sample_hidden_graph() to take an RNGRoot so the hidden-graph sampler follows the project-wide RNGRoot substream convention for reproducible, cross-component randomness (Issue #9 / PR #34 alignment).
Changes:
- Update
sample_hidden_graph()to acceptRNGRootas the primary input and seed NumPy via a named child stream (hidden_graph). - Preserve the old
seed/intusage paths withDeprecationWarningfor backward compatibility. - Update all in-repo call sites (Generator + script) and test suite callers to pass
RNGRoot(...), and add warning tests.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| leadforge/structure/sampler.py | Changes sample_hidden_graph API to accept RNGRoot, adds deprecation warnings for legacy seed usage. |
| leadforge/api/generator.py | Updates generator to call sample_hidden_graph(RNGRoot(config.seed)). |
| scripts/spike_category_signal.py | Updates script pipeline to call sample_hidden_graph(RNGRoot(config.seed)). |
| tests/structure/test_sampler.py | Updates tests to pass RNGRoot, adds deprecation warning assertions. |
| tests/simulation/test_population.py | Updates population tests to pass RNGRoot(seed) into sampler. |
| tests/simulation/test_engine.py | Updates engine tests to pass RNGRoot(seed) into sampler. |
| tests/render/test_snapshot_windowed.py | Updates snapshot determinism tests to pass RNGRoot(seed). |
| tests/render/test_render.py | Updates render determinism/snapshot tests to pass RNGRoot(seed). |
| .agent-plan.md | Documents the sampler RNG refactor checklist for PR tracking. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address self-review feedback: - Remove unnecessary deprecation warnings — sample_hidden_graph is internal, no external consumers need backward compat - Make rng_root a required RNGRoot parameter (no union type) - Add strict TypeError for non-RNGRoot input - Create RNGRoot once in generator.py rather than inline - Replace deprecation tests with proper type-error tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
pr-agent-context report: This run includes unresolved review comments on PR #35 in repository https://github.com/leadforge-dev/leadforge
For each unresolved review comment, recommend one of: resolve as irrelevant, accept and implement
the recommended solution, open a separate issue and resolve as out-of-scope for this PR, accept and
implement a different solution, or resolve as already treated by the code.
After I reply with my decision per item, implement the accepted actions, resolve the corresponding
PR comments, and push all of these changes in a single commit.
# Copilot Comments
## COPILOT-1
Location: leadforge/structure/sampler.py:53
URL: https://github.com/leadforge-dev/leadforge/pull/35#discussion_r3172327963
Status: outdated
Root author: copilot-pull-request-reviewer
Comment:
The docstring’s `Raises:` section no longer documents input-validation errors, but `sample_hidden_graph()` can raise `TypeError` (missing/invalid `rng_root`) and `ValueError`/`TypeError` from `RNGRoot` construction when using deprecated seed paths. Consider documenting these exceptions so callers know what to expect.
## COPILOT-2
Location: leadforge/structure/sampler.py
URL: https://github.com/leadforge-dev/leadforge/pull/35#discussion_r3172327983
Status: outdated
Root author: copilot-pull-request-reviewer
Comment:
The backward-compat branch will override an explicitly provided RNGRoot if `seed` is also passed (e.g., `sample_hidden_graph(RNGRoot(1), seed=2)`), which is surprising and can lead to silently using the wrong RNG. Consider rejecting ambiguous calls (both `rng_root` and `seed`/int provided) with a `TypeError` rather than picking one branch.
## COPILOT-3
Location: leadforge/structure/sampler.py
URL: https://github.com/leadforge-dev/leadforge/pull/35#discussion_r3172327991
Status: outdated
Root author: copilot-pull-request-reviewer
Comment:
`isinstance(rng_root, int)` will treat `True`/`False` as ints, emit a DeprecationWarning, and then fail inside `RNGRoot(True)` with a `TypeError`. It would be cleaner to special-case `bool` (and generally validate `rng_root` is an `RNGRoot`) so callers get a direct, non-deprecated type error without an unrelated deprecation warning.
## COPILOT-4
Location: leadforge/structure/sampler.py
URL: https://github.com/leadforge-dev/leadforge/pull/35#discussion_r3172327996
Status: outdated
Root author: copilot-pull-request-reviewer
Comment:
If `rng_root` is neither an `int`/`None` nor an `RNGRoot` instance (e.g. a `np.random.Generator`), the function will currently reach `rng_root.child(...)` and raise an `AttributeError`. Consider adding an explicit `isinstance(rng_root, RNGRoot)` check and raising `TypeError` with a clear message to keep the public API predictable.Run metadata: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
sample_hidden_graph()to accept anRNGRootinstance instead of a bareintseed, aligning it with the cross-component RNG convention established in PR refactor: pipeline RNG convention + warnings.warn #34seed: intinterface preserved withDeprecationWarningfor backward compatibilitygenerator.py,spike_category_signal.py) and tests updatedCloses #9
Test plan
pytest -x -q)ruff check .cleanruff format --check .cleantest_same_seed_same_graph)test_deprecated_int_seed_warns,test_deprecated_seed_kwarg_warns🤖 Generated with Claude Code