Repository navigation
Conversation
lockwo
reviewed
Nov 10, 2026
| *, | ||
| slice_info: bool = False, | ||
| ) -> None: | ||
| if n_steps < 1: |
Contributor
There was a problem hiding this comment.
this is fine, don't need all the tests for a simple check (that users should realistically never miss, but because the check is cheap it is fine)
Contributor
Author
|
Trimmed — down to the two cases that pin distinct behavior: n_steps=0 raises at construction, and n_steps=1 still samples. The negative and alternate-porting-fn cases hit the same guard branch, and the 3/1000 cases exercise the same valid path, so they're out. Fix itself untouched. |
This branch has not been deployed
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.
ChainFactor(base, n_steps=0).sample(...)returns an all-zeros array shapedlike the base factor's output spec. No step of the base factor ever ran; the
returned value is the scan's initial carry placeholder, presented to the
caller as a sample from the factor.
Minimal reproduction (identity
DeterministicFactoron a scalar int port,chained over its feedback port, input 5):
n_steps=1→ returns 5n_steps=3→ returns 5n_steps=0→ returns 0 — a value the factor never produced.The placeholder matches the output spec in shape and dtype, so it is
indistinguishable from a legitimate sample by any downstream check. For
0/1-encoded discrete factors the all-zeros value is even a legal
configuration. The trigger is realistic: the in-repo Gibbs example wires a
user sweep-count hyperparameter straight into
n_steps, so a computedcount that hits 0 (e.g. "skip burn-in",
total - warmup) silently yieldsfabricated samples. The fabrication appears on every sample path
(
sample,sample(return_aux=True),sample_with_references) — the auxtraces honestly show 0 steps; only the primary return lies.
Root cause:
AbstractChainFactor._runbuilds the scan's initial "main"carry as zeros of the base output spec; with zero steps,
jax.lax.scanreturns that carry untouched and
samplereturns it as the result.ChainFactor.__init__validates nothing. (Negativen_stepscurrentlyfails at sample time with an inscrutable
MLIRErrorfrom insidejax.random.split, with no mention ofn_steps.)Both circuit classes in the same library already guard the analogous
parameter:
DiscretePCircuitandHybridPCircuitraiseValueErrorforreps < 1("reps must be at least 1"). The chain factor's step count isthe same kind of parameter with no equivalent guard.
Fix
Validate in
AbstractChainFactor.__init__, mirroring the circuits' check:This closes the silent hole (0) at construction on every sample path, and
turns the negative case into a clear construction-time
ValueErrorinstead of a sample-time
MLIRError. Nothing legitimate is rejected: notest, example, or notebook in the repo constructs with
n_steps < 1, andn_steps=1behavior is bit-identical to before.Tests
New
tests/test_f4_chainfactor_check.py(6 tests):n_steps=0andn_steps=-1raiseValueErrorat construction (string and callableporting forms);
n_steps ∈ {1, 3, 1000}on the identity chain return theinput unchanged.
Verified against torx v0.0.3 (2142045): the new tests pass, and the full
suite (
tests/, excluding the hardware-timingtest_performance.py)passes with this fix and an unrelated HybridPCircuit fix applied:
230 passed + 147 subtests, no regressions. Code formatted with the repo's
pre-commit hooks (black / isort / flake8 all pass).