Skip to content

Commit 575f7b7

Browse files
authored
Fix import failing if SSE module is missing but polyfill is not (#763)
1 parent da4594c commit 575f7b7

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

glue/python/src/stim/__init__.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77

88
import stim._detect_machine_architecture as _tmp
99

10+
1011
_tmp = _tmp._UNSTABLE_detect_march()
11-
# NOTE: avx2 disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
12-
# if _tmp == 'avx2':
13-
# from stim._stim_avx2 import *
14-
# from stim._stim_avx2 import _UNSTABLE_raw_format_data, __version__
15-
if _tmp == 'avx2' or _tmp == 'sse2':
16-
from stim._stim_sse2 import *
17-
from stim._stim_sse2 import _UNSTABLE_raw_format_data, __version__
18-
else:
19-
from stim._stim_polyfill import *
12+
try:
13+
# NOTE: avx2 disabled until https://github.com/quantumlib/Stim/issues/432 is fixed
14+
# if _tmp == 'avx2':
15+
# from stim._stim_avx2 import _UNSTABLE_raw_format_data, __version__
16+
# from stim._stim_avx2 import *
17+
if _tmp == 'avx2' or _tmp == 'sse2':
18+
from stim._stim_sse2 import _UNSTABLE_raw_format_data, __version__
19+
from stim._stim_sse2 import *
20+
else:
21+
from stim._stim_polyfill import _UNSTABLE_raw_format_data, __version__
22+
from stim._stim_polyfill import *
23+
except ModuleNotFoundError:
2024
from stim._stim_polyfill import _UNSTABLE_raw_format_data, __version__
25+
from stim._stim_polyfill import *
26+
2127
del _tmp
2228

2329

@@ -26,10 +32,12 @@ def _pytest_pycharm_pybind_repr_bug_workaround(cls):
2632
cls.__repr__ = lambda e: f(e)
2733
cls.__repr__.__doc__ = f.__doc__
2834
_pytest_pycharm_pybind_repr_bug_workaround(Circuit)
35+
_pytest_pycharm_pybind_repr_bug_workaround(CircuitErrorLocation)
2936
_pytest_pycharm_pybind_repr_bug_workaround(CircuitErrorLocationStackFrame)
3037
_pytest_pycharm_pybind_repr_bug_workaround(CircuitInstruction)
3138
_pytest_pycharm_pybind_repr_bug_workaround(CircuitRepeatBlock)
3239
_pytest_pycharm_pybind_repr_bug_workaround(CircuitTargetsInsideInstruction)
40+
_pytest_pycharm_pybind_repr_bug_workaround(CompiledDemSampler)
3341
_pytest_pycharm_pybind_repr_bug_workaround(CompiledDetectorSampler)
3442
_pytest_pycharm_pybind_repr_bug_workaround(CompiledMeasurementSampler)
3543
_pytest_pycharm_pybind_repr_bug_workaround(CompiledMeasurementsToDetectionEventsConverter)
@@ -39,10 +47,15 @@ def _pytest_pycharm_pybind_repr_bug_workaround(cls):
3947
_pytest_pycharm_pybind_repr_bug_workaround(DemTargetWithCoords)
4048
_pytest_pycharm_pybind_repr_bug_workaround(DetectorErrorModel)
4149
_pytest_pycharm_pybind_repr_bug_workaround(ExplainedError)
50+
_pytest_pycharm_pybind_repr_bug_workaround(FlipSimulator)
4251
_pytest_pycharm_pybind_repr_bug_workaround(FlippedMeasurement)
52+
_pytest_pycharm_pybind_repr_bug_workaround(Flow)
53+
_pytest_pycharm_pybind_repr_bug_workaround(GateData)
4354
_pytest_pycharm_pybind_repr_bug_workaround(GateTarget)
4455
_pytest_pycharm_pybind_repr_bug_workaround(GateTargetWithCoords)
4556
_pytest_pycharm_pybind_repr_bug_workaround(PauliString)
57+
_pytest_pycharm_pybind_repr_bug_workaround(PauliStringIterator)
4658
_pytest_pycharm_pybind_repr_bug_workaround(Tableau)
59+
_pytest_pycharm_pybind_repr_bug_workaround(TableauIterator)
4760
_pytest_pycharm_pybind_repr_bug_workaround(TableauSimulator)
4861
del _pytest_pycharm_pybind_repr_bug_workaround

0 commit comments

Comments
 (0)