Skip to content

Fix the optional rng_key default in InitFn - #988

Draft
sapunyangkut wants to merge 1 commit into
blackjax-devs:mainfrom
sapunyangkut:codex/fix-hmc-init-protocol-default
Draft

Fix the optional rng_key default in InitFn#988
sapunyangkut wants to merge 1 commit into
blackjax-devs:mainfrom
sapunyangkut:codex/fix-hmc-init-protocol-default

Conversation

@sapunyangkut

Copy link
Copy Markdown

Description

SamplingAlgorithm.init is typed by the InitFn protocol. The protocol allowed rng_key to be None, but it omitted the = None default, so Pyright treated the argument as required even though the concrete HMC initializer accepts init(position).

This adds the missing default to the protocol and a regression test that compares the protocol signature with the concrete HMC initializer. It does not change runtime algorithm behavior.

Related issues / discussions

Closes #782

Validation

  • Pyright 1.1.411: 0 errors on the issue reproducer, with both init(position) and init(position, rng_key) calls.
  • uv run pytest -q tests/test_api_protocols.py tests/mcmc/test_multinomial_hmc.py: 93 passed.
  • uv run pre-commit run --all-files: all applicable hooks passed.
  • Full Windows CI-equivalent run: 1542 passed, 1 skipped, and 4 unrelated baseline failures. All four failures reproduced identically on the same upstream commit without the production fix; two call the unavailable os.geteuid API on Windows, and two are unrelated numerical assertions. The same upstream commit's Ubuntu Tests workflow is successful.

Checklist

General

  • The branch is rebased on the latest main
  • Commit messages are clear and descriptive
  • pre-commit run --all-files passes (black, isort, flake8, mypy)
  • Tests cover the changes

Code quality

  • Public functions have NumPy-style docstrings (no new public function; the existing protocol docstring is unchanged)
  • Naming follows existing conventions
  • All new code is JIT-compatible (the production change is type-only)

New sampler / algorithm

Not applicable; this is a typing contract fix.

AI assistance disclosure

This contribution was prepared and validated with OpenAI Codex automation. The automation reproduced the static typing error and runtime signature mismatch on the current upstream commit, produced the two-file patch, and ran the checks listed above.

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.

HMC Type hint issue

1 participant