Skip to content

Fix SPEX ignoring random_state, and log the CPU on Windows runners - #645

Merged
mmschlk merged 3 commits into
mainfrom
claude/upbeat-edison-e9x3bi
Oct 26, 2026
Merged

mmschlk merged 3 commits into
mainfrom
claude/upbeat-edison-e9x3bi

Conversation

@mmschlk

@mmschlk mmschlk commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Motivation and Context

CI went red on main after #641 was merged (run). The merged code had passed every job on the PR, so neither failure was caused by the code that went in. These are two separate problems that a run can hit by chance.

1. Ubuntu, Python 3.15: test_approximate_with_spex[...FSII...] failed (obtained ~0, expected 0.05). This is a real bug, fixed here.

Sparse and SPEX ignored random_state. The sparse_transform library draws its random queries from numpy's global random state (np.random.randint, np.random.choice), and shapiq never seeded it. As a result, SPEX(random_state=42) gave a different result after any other use of np.random. I reproduced the CI failure locally: with random_state=42 fixed, the failing case fails for global seed 242, about once in 400 seeds.

The fix is in src/shapiq/approximator/sparse/base.py. With a random_state, the global state is seeded from the approximator's generator for the transform and then restored, so the caller's global state is untouched. Without a random_state, nothing changes.

2. Windows: the test process crashed with 0xc000001d (illegal instruction). Not fixed, only diagnosed here.

The crash happens at the first TabPFN fit (TestProxyTabPFNExplainer::test_proxyshap_tabpfn_reg, which runs PyTorch). The same crash hit a fork PR on 2026-10-23 under the old CI (run). It also passed on all three runs of #641, so it depends on which runner machine a job lands on. Some Windows runners presumably lack a CPU instruction that compiled code in that path uses. The crash cuts off the stack trace, so the library and the instruction are still unknown.

This PR adds a step to the Windows test job that logs:

  • the CPU model,
  • the SIMD extensions numpy finds,
  • the CPU capability torch selects.

The step has continue-on-error, so it never fails the job. The next crash can then be compared with a passing runner before choosing a workaround (e.g. capping torch's CPU dispatch).


Public API Changes

  • No Public API changes
  • Yes, Public API changes (Details below)

random_state on Sparse/SPEX now does what its docstring says. Results with a fixed random_state change, and are now reproducible.


How Has This Been Tested?

  • A new test, test_random_state_makes_approximation_reproducible, checks that the same random_state gives identical estimates under different global seeds and leaves the global state as it was. It fails without the fix and passes with it.
  • test_approximator_base_sparse.py passes (15 tests). Every test_approximate_with_spex case passes for global seed 242 and seeds 0–19.
  • ruff 0.15.5 (check and format) is clean, and ty reports the same diagnostics before and after.
  • actionlint and pre-commit pass on ci.yml. This PR changes ci.yml, so its own run takes the full matrix and runs the new step on Windows.

Checklist

  • The changes have been tested locally.
  • Documentation has been updated (if the public API or usage changes).
  • An entry has been added to CHANGELOG.md (if relevant for users).
  • The code follows the project's style guidelines.
  • I have considered the impact of these changes on the public API.


Generated by Claude Code

sparse_transform draws its random queries from numpy's global random
state, which Sparse and SPEX never seeded, so random_state=42 gave a
different result after every other use of np.random. This made
test_approximate_with_spex fail about once in 400 runs (on main: the
FSII case on Python 3.15).

With a random_state, the global state is now seeded from the
approximator's generator for the transform and restored afterwards.
Without one, nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MhQWPdeTbJyESb8uBYqLAU
On some Windows runners the tests crash with an illegal instruction
(0xc000001d) at the first TabPFN fit, and the crash cuts off the stack
trace. The new step logs the CPU model, the SIMD extensions numpy finds
and the CPU capability torch selects, so a crashing runner can be told
apart from the ones that pass. It never fails the job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MhQWPdeTbJyESb8uBYqLAU
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mmschlk
mmschlk merged commit cff5475 into main Oct 26, 2026
14 checks passed
@mmschlk
mmschlk deleted the claude/upbeat-edison-e9x3bi branch October 26, 2026 09:22
mmschlk pushed a commit to flyingdoubleG/shapiq that referenced this pull request Oct 26, 2026
@mmschlk mmschlk mentioned this pull request Nov 27, 2026
6 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants