Skip to content

fix: add fallback to polyfill when SIMD extensions are missing - #31

Open
moefqy wants to merge 1 commit into
Deltakit:mainfrom
moefqy:fix-macos-sse2-fallback
Open

fix: add fallback to polyfill when SIMD extensions are missing#31
moefqy wants to merge 1 commit into
Deltakit:mainfrom
moefqy:fix-macos-sse2-fallback

Conversation

@moefqy

@moefqy moefqy commented Aug 2, 2026

Copy link
Copy Markdown

Problem

On macOS (specifically x86_64 / Rosetta environments), CPU architecture detection in deltakit_stim returns sse2 (or avx2), causing deltakit_stim/__init__.py to attempt:

if _tmp == 'avx2' or _tmp == 'sse2':
    from deltakit_stim._stim_sse2 import *

However, in the pre-built macOS wheel distribution on PyPI (deltakit_stim-0.2.0-cp311-cp311-macosx_15_0_x86_64.whl), _stim_sse2.so was omitted during the build, shipping only _stim_polyfill.so.

Because there is no exception handler around the import, installing and running deltakit on macOS raises an unhandled crash:

ModuleNotFoundError: No module named 'deltakit_stim._stim_sse2'

Solution

  • Wraps the dynamic architecture import in a try...except (ImportError, ModuleNotFoundError) block.
  • If _stim_sse2 is present, it will load for fast SIMD execution.
  • If _stim_sse2 is missing from the installed package, it gracefully falls back to _stim_polyfill instead of crashing.

Verification

Tested on macOS 15 (Sequoia, Python 3.11.4):

  • Confirmed import deltakit and import deltakit_stim now load cleanly without errors.
  • Verified basic quantum circuit creation and sampling runs with 100% accuracy.

@CLAassistant

CLAassistant commented Aug 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rolandriver

Copy link
Copy Markdown
Collaborator

Thank you @moefqy for this really. I've assigned reviewers to this PR and we will come back to you soon.

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.

3 participants