Skip to content

Commit ccc371f

Browse files
mtreinishjakelishmangeorgios-tsmergify[bot]
authored
Implement multithreaded stochastic swap in rust (Qiskit#7658)
* Implement multithreaded stochastic swap in rust This commit is a rewrite of the core swap trials functionality in the StochasticSwap transpiler pass. Previously this core routine was written using Cython (see Qiskit#1789) which had great performance, but that implementation was single threaded. The core of the stochastic swap algorithm by it's nature is well suited to be executed in parallel, it attempts a number of random trials and then picks the best result from all the trials and uses that for that layer. These trials can easily be run in parallel as there is no data dependency between the trials (there are shared inputs but read-only). As the algorithm generally scales exponentially the speed up from running the trials in parallel can offset this and improve the scaling of the pass. Running the pass in parallel was previously tried in Qiskit#4781 using Python multiprocessing but the overhead of launching an additional process and serializing the input arrays for each trial was significantly larger than the speed gains. To run the algorithm efficiently in parallel multithreading is needed to leverage shared memory on shared inputs. This commit rewrites the cython routine using rust. This was done for two reasons. The first is that rust's safety guarantees make dealing with and writing parallel code much easier and safer. It's also multiplatform because the rust language supports native threading primatives in language. The second is while writing parallel cython code using open-mp there are limitations with it, mainly on windows. In practice it was also difficult to write and maintain parallel cython code as it has very strict requirements on python and c code interactions. It was much faster and easier to port it to rust and the performance for each iteration (outside of parallelism) is the same (in some cases marginally faster) in rust. The implementation here reuses the data structures that the previous cython implementation introduced (mainly flattening all the terra objects into 1d or 2d numpy arrays for efficient access from C). The speedups from this PR can be significant, calling transpile() on a 400 qubit (with a depth of 10) QV model circuit targetting a 409 heavy hex coupling map goes from ~200 seconds with the single threaded cython to ~60 seconds with this PR locally on a 32 core system, When transpiling a 1000 qubit (also with a depth of 10) QV model circuit targetting a 1081 qubit heavy hex coupling map goes from taking ~6500 seconds to ~720 seconds. The tradeoff with this PR is for local qiskit-terra development a rust compiler needs to be installed. This is made trivial using rustup (https://rustup.rs/), but it is an additional burden and one that we might not want to make. If so we can look at turning this PR into a separate repository/package that qiskit-terra can depend on. The tradeoff here is that we'll be adding friction to the api boundary between the pass and the core swap trials interface. But, it does ease the dependency on development for qiskit-terra. * Sanitize packaging to support future modules This commit fixes how we package the compiled rust module in qiskit-terra. As a single rust project only gives us a single compiled binary output we can't use the same scheme we did previously with cython with a separate dynamic lib file for each module. This shifts us to making the rust code build a `qiskit._accelerate` module and in that we have submodules for everything we need from compiled code. For this PR there is only one submodule, `stochastic_swap`, so for example the parallel swap_trials routine can be imported from `qiskit._accelerate.stochastic_swap.swap_trials`. In the future we can have additional submodules for other pieces of compiled code in qiskit. For example, the likely next candidate is the pauli expectation value cython module, which we'll likely port to rust and also make parallel (for sufficiently large number of qubits). In that case we'd add a new submodule for that functionality. * Adjust random normal distribution to use correct mean This commit corrects the use of the normal distribution to have the mean set to 1.0. Previously we were doing this out of band for each value by adding 1 to the random value which wasn't necessary because we could just generate it with a mean of 1.0. * Remove unecessary extra scope from locked read This commit removes an unecessary extra scope around the locked read for where we store the best solution. The scope was previously there to release the lock after we check if there is a solution or not. However this wasn't actually needed as we can just do the check inline and the lock will release after the condition block. * Remove unecessary explicit type from opt_edges variable * Fix indices typo in NLayout constructor Co-authored-by: Jake Lishman <[email protected]> * Remove explicit lifetime annotation from swap_trials Previously the swap_trials() function had an explicit lifetime annotation `'p` which wasn't necessary because the compiler can determine this on it's own. Normally when dealing with numpy views and a Python object (i.e. a GIL handle) we need a lifetime annotation to tell the rust compiler the numpy view and the python gil handle will have the same lifetime. But since swap_trials doesn't take a gil handle and operates purely in rust we don't need this lifetime and the rust compiler can deal with the lifetime of the numpy views on their own. * Use sum() instead of fold() * Fix lint and add rust style and lint checks to CI This commit fixes the python lint failures and also updates the ci configuration for the lint job to also run rust's style and lint enforcement. * Fix returned layout mapping from NLayout This commit fixes the output list from the `layout_mapping()` method of `NLayout`. Previously, it incorrectly would return the wrong indices it should be a list of virtual -> physical to qubit pairs. This commit corrects this error Co-authored-by: georgios-ts <[email protected]> * Tweak tox configuration to try and reliably build rust extension * Make swap_trials parallelization configurable This commit makes the parallelization of the swap_trials() configurable. This is dones in two ways, first a new argument parallel_threshold is added which takes an optional int which is the number of qubits to switch between a parallel and serial version. The second is that it takes into account the the state of the QISKIT_IN_PARALLEL environment variable. This variable is set to TRUE by parallel_map() when we're running in a multiprocessing context. In those cases also running stochastic swap in parallel will likely just cause too much load as we're potentially oversubscribing work to the number of available CPUs. So, if QISKIT_IN_PARALLEL is set to True we run swap_trials serially. * Revert "Make swap_trials parallelization configurable" This reverts commit 57790c8. That commit attempted to sovle some issues in test running, mainly around multiple parallel dispatch causing exceess load. But in practice it was broken and caused more issues than it fixed. We'll investigate and add control for the parallelization in a future commit separately after all the tests are passing so we have a good baseline. * Add docs to swap_trials() and remove unecessary num_gates arg * Fix race condition leading to non-deterministic behavior Previously, in the case of circuits that had multiple best possible depth == 1 solutions for a layer, there was a race condition in the fast exit path between the threads which could lead to a non-deterministic result even with a fixed seed. The output was always valid, but which result was dependent on which parallel thread with an ideal solution finished last and wrote to the locked best result last. This was causing weird non-deterministic test failures for some tests because of Qiskit#1794 as the exact match result would change between runs. This could be a bigger issue because user expectations are that with a fixed seed set on the transpiler that the output circuit will be deterministically reproducible. To address this is issue this commit trades off some performance to ensure we're always returning a deterministic result in this case. This is accomplished by updating/checking if a depth==1 solution has been found in another trial thread we only act (so either exit early or update the already found depth == 1 solution) if that solution already found has a trial number that is less than this thread's trial number. This does limit the effectiveness of the fast exit, but in practice it should hopefully not effect the speed too much. As part of this commit some tests are updated because the new deterministic behavior is slightly different from the previous results from the cython serial implementation. I manually verified that the new output circuits are still valid (it also looks like the quality of the results in some of those cases improved, but this is strictly anecdotal and shouldn't be taken as a general trend with this PR). * Apply suggestions from code review Co-authored-by: georgios-ts <[email protected]> * Fix compiler errors in previous commit * Revert accidental commit of parallel reduction in compute_cost This was only a for local testing to prove it was a bad idea and was accidently included in the branch. We should not nest the parallel execution like this. * Eliminate short circuit for depth == 1 swap_trial() result This commit eliminates the short circuit fast return in swap_trial() when another trial thread has found an ideal solution. Trying to do this in a parallel context is tricky to make deterministic because in cases of >1 depth == 1 solutions there is an inherent race condition between the threads for writing out their depth == 1 result to the shared location. Different strategies were tried to make this reliably deterministic but there wa still a race condition. Since this was just a performance optimization to avoid doing unnecessary work this commit removes this step. Weighing improved performance against repeatability in the output of the compiler, the reproducible results are more important. After we've adopted a multithreaded stochastic swap we can investigate adding this back as a potential future optimization. * Add missing docstrings * Add section to contributing on installing form source * Make rust python classes pickleable * Add rust compiler install to linux wheel jobs * Try more tox changes to fix docs builds * Revert "Eliminate short circuit for depth == 1 swap_trial() result" This reverts commit c510764. The removal there was premature and we had a fix for the non-determinism in place, ignoring a typo which was preventing it from working. Co-Authored-By: Georgios Tsilimigkounakis <[email protected]> * Fix submodule declaration and module attribute on rust classes * Fix rust lint * Fix docs job definition * Disable multiprocessing parallelism in unit tests This commit disables the multiprocessing based parallelism when running unittest jobs in CI. We historically have defaulted the use of multiprocessing in environments only where the "fork" start method is available because this has the best performance and has no caveats around how it is used by users (you don't need an `if __name__ == "__main__"` guard). However, the use of the "fork" method isn't always 100% reliable (see https://bugs.python.org/issue40379), which we saw on Python 3.9 Qiskit#6188. In unittest CI (and tox) by default we use stestr which spawns (not using fork) parallel workers to run tests in parallel. With this PR this means in unittest we're now running multiple test runner subprocesses, which are executing parallel dispatched code using multiprocessing's fork start method, which is executing multithreaded rust code. This three layers of nesting is fairly reliably hanging as Python's fork doesn't seem to be able to handle this many layers of nested parallelism. There are 2 ways I've been able to fix this, the first is to change the start method used by `parallel_map()` to either "spawn" or "forkserver" either of these does not suffer from random hanging. However, doing this in the unittest context causes significant overhead and slows down test executing significantly. The other is to just disable the multiprocessing which fixes the hanging and doesn't impact runtime performance signifcantly (and might actually help in CI so we're not oversubscribing the limited resources. As I have not been able to reproduce `parallel_map()` hanging in a standalone context with multithreaded stochastic swap this commit opts for just disabling multiprocessing in CI and documenting the known issue in the release notes as this is the simpler solution. It's unlikely that users will nest parallel processes as it typically hurts performance (and parallel_map() actively guards against it), we only did it in testing previously because the tests which relied on it were a small portion of the test suite (roughly 65 tests) and typically did not have a significant impact on the total throughput of the test suite. * Fix typo in azure pipelines config * Remove unecessary extension compilation for image tests * Add test script to explicitly verify parallel dispatch In an earlier commit we disabled the use of parallel dispatch in parallel_map() to avoid a bug in cpython associated with their fork() based subprocess launch. Doing this works around the bug which was reliably triggered by running multiprocessing in parallel subprocesses. It also has the side benefit of providing a ~2x speed up for test suite execution in CI. However, this meant we lost our test coverage in CI for running parallel_map() with actual multiprocessing based parallel dispatch. To ensure we don't inadvertandtly regress this code path moving forward this commit adds a dedicated test script which runs a simple transpilation in parallel and verifies that everything works as expected with the default parallelism settings. * Avoid multi-threading when run in a multiprocessing context This commit adds a switch on running between a single threaded and a multithreaded variant of the swap_trials loop based on whether the QISKIT_IN_PARALLEL flag is set. If QISKIT_IN_PARALLEL is set to TRUE this means the `parallel_map()` function is running in the outer python context and we're running in multiprocessing already. This means we do not want to be running in multiple threads generally as that will lead to potential resource exhaustion by spawn n processes each potentially running with m threads where `n` is `min(num_phys_cpus, num_tasks)` and `m` is num_logical_cpus (although only `min(num_logical_cpus, num_trials)` will be active) which on the typical system there aren't enough cores to leverage both multiprocessing and multithreading. However, in case a user does have such an environment they can set the `QISKIT_FORCE_THREADS` env variable to `TRUE` which will use threading regardless of the status of `QISKIT_IN_PARALLEL`. * Apply suggestions from code review Co-authored-by: Jake Lishman <[email protected]> * Minor fixes from review comments This commits fixes some minor details found during code review. It expands the section on building from source to explain how to build a release optimized binary with editable mode, makes the QISKIT_PARALLEL env variable usage consistent across all jobs, and adds a missing shebang to the `install_rush.sh` script which is used to install rust in the manylinux container environment. * Simplify tox configuration In earlier commits the tox configuration was changed to try and fix the docs CI job by going to great effort to try and enforce that setuptools-rust was installed in all situations, even before it was actually needed. However, the problem with the docs ci job was unrelated to the tox configuration and this reverts the configuration to something that works with more versions of tox and setuptools-rust. * Add missing pieces of cargo configuration Co-authored-by: Jake Lishman <[email protected]> Co-authored-by: georgios-ts <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 44f794a commit ccc371f

28 files changed

+852
-578
lines changed

.cargo/config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.x86_64-apple-darwin]
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]
6+
7+
[target.aarch64-apple-darwin]
8+
rustflags = [
9+
"-C", "link-arg=-undefined",
10+
"-C", "link-arg=dynamic_lookup",
11+
]

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,8 @@ test/ipynb/mpl/circuit/result_test.json
151151
test/ipynb/mpl/graph/*.png
152152
test/ipynb/mpl/graph/*.zip
153153
test/ipynb/mpl/graph/result_test.json
154+
155+
# Added by cargo
156+
157+
/target
158+
Cargo.lock

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unsafe-load-any-extension=no
3333
# A comma-separated list of package or module names from where C extensions may
3434
# be loaded. Extensions are loading into the active Python interpreter and may
3535
# run arbitrary code
36-
extension-pkg-allow-list=retworkx, numpy, tweedledum
36+
extension-pkg-allow-list=retworkx, numpy, tweedledum, qiskit._accelerate
3737

3838

3939
[MESSAGES CONTROL]

CONTRIBUTING.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,32 @@ build all the documentation into `docs/_build/html` and the release notes in
225225
particular will be located at `docs/_build/html/release_notes.html`
226226

227227
## Installing Qiskit Terra from source
228-
Please see the [Installing Qiskit Terra from
229-
Source](https://qiskit.org/documentation/contributing_to_qiskit.html#installing-terra-from-source)
230-
section of the Qiskit documentation.
228+
229+
Qiskit Terra is primarily written in Python but there are some core routines
230+
that are written in the [Rust](https://www.rust-lang.org/) programming
231+
language to improve the runtime performance. For the released versions of
232+
qiskit-terra we publish precompiled binaries on the
233+
[Python Package Index](https://pypi.org/) for all the supported platforms
234+
which only requires a functional Python environment to install. However, when
235+
building and installing from source you will need a rust compiler installed. You can do this very easily
236+
using rustup: https://rustup.rs/ which provides a single tool to install and
237+
configure the latest version of the rust compiler.
238+
[Other installation methods](https://forge.rust-lang.org/infra/other-installation-methods.html)
239+
exist too. For windows users besides rustup you will also need install
240+
the Visual C++ build tools so that rust can link against the system c/c++
241+
libraries. You can see more details on this in the
242+
[rustup documentation](https://rust-lang.github.io/rustup/installation/windows.html).
243+
244+
Once you have a rust compiler installed you can rely on the normal Python
245+
build/install steps to install Qiskit Terra. This means you just run
246+
`pip install .` in your local git clone to build and install Qiskit Terra.
247+
248+
Do note that if you do use develop mode/editable install (via `python setup.py develop` or `pip install -e .`) the Rust extension will be built in debug mode
249+
without any optimizations enabled. This will result in poor runtime performance.
250+
If you'd like to use an editable install with an optimized binary you can
251+
run `python setup.py build_rust --release --inplace` after you install in
252+
editable mode to recompile the rust extensions in release mode.
253+
231254

232255
## Test
233256

Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "qiskit-terra"
3+
version = "0.20.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[lib]
9+
name = "qiskit_accelerate"
10+
crate-type = ["cdylib"]
11+
12+
[dependencies]
13+
rayon = "1.5"
14+
numpy = "0.15.1"
15+
rand = "0.8"
16+
rand_pcg = "0.3"
17+
rand_distr = "0.4.3"
18+
19+
[dependencies.pyo3]
20+
version = "0.15.1"
21+
features = ["extension-module", "hashbrown"]
22+
23+
[dependencies.ndarray]
24+
version = "^0.15.0"
25+
features = ["rayon"]
26+
27+
[dependencies.hashbrown]
28+
version = "0.11.2"
29+
features = ["rayon"]
30+
31+
[profile.release]
32+
lto = 'fat'
33+
codegen-units = 1

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ include test/python/pickles/*.pickle
1515
include test/python/qasm/*.qasm
1616
include test/python/visualization/references/*.png
1717
include test/python/notebooks/*.ipynb
18+
19+
include Cargo.toml
20+
recursive-include src *

azure-pipelines.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ stages:
180180
pip install -U "cplex" "qiskit-aer" "z3-solver" -c constraints.txt
181181
mkdir -p /tmp/terra-tests
182182
cp -r test /tmp/terra-tests/.
183+
cp tools/verify_parallel_map.py /tmp/terra-tests/.
183184
cp .stestr.conf /tmp/terra-tests/.
184185
cp -r .stestr /tmp/terra-tests/. || :
185186
sudo apt-get update
@@ -193,8 +194,11 @@ stages:
193194
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))")
194195
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
195196
stestr run
197+
python ./verify_parallel_map.py
196198
popd
197199
displayName: 'Run tests'
200+
env:
201+
QISKIT_PARALLEL: FALSE
198202
- task: CopyFiles@2
199203
condition: failed()
200204
displayName: 'Copy images'
@@ -239,7 +243,6 @@ stages:
239243
virtualenv image_tests
240244
image_tests/bin/pip install -U -r requirements.txt -c constraints.txt
241245
image_tests/bin/pip install -U -c constraints.txt -e ".[visualization]"
242-
image_tests/bin/python setup.py build_ext --inplace
243246
sudo apt-get update
244247
sudo apt-get install -y graphviz pandoc
245248
image_tests/bin/pip check
@@ -286,6 +289,8 @@ stages:
286289
tools/verify_headers.py qiskit test
287290
python tools/find_optional_imports.py
288291
reno lint
292+
cargo fmt --check
293+
cargo clippy -- -D warnings
289294
displayName: 'Style and lint'
290295
- job: 'Docs'
291296
pool: {vmImage: 'ubuntu-latest'}
@@ -314,7 +319,6 @@ stages:
314319
set -e
315320
python -m pip install --upgrade pip setuptools wheel
316321
pip install -U tox
317-
python setup.py build_ext --inplace
318322
sudo apt-get update
319323
sudo apt-get install -y graphviz
320324
displayName: 'Install dependencies'
@@ -384,7 +388,10 @@ stages:
384388
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))")
385389
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
386390
stestr run
391+
python ./tools/verify_parallel_map.py
387392
displayName: 'Run tests'
393+
env:
394+
QISKIT_PARALLEL: FALSE
388395
- task: CopyFiles@2
389396
condition: failed()
390397
displayName: 'Copy images'
@@ -454,10 +461,12 @@ stages:
454461
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 1024))")
455462
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
456463
stestr run
464+
python ./tools/verify_parallel_map.py
457465
displayName: 'Run tests'
458466
env:
459467
LANG: 'C.UTF-8'
460468
PYTHONIOENCODING: 'utf-8:backslashreplace'
469+
QISKIT_PARALLEL: FALSE
461470
- task: CopyFiles@2
462471
condition: failed()
463472
displayName: 'Copy images'
@@ -538,6 +547,7 @@ stages:
538547
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 1024))")
539548
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
540549
stestr run
550+
python ./tools/verify_parallel_map.py
541551
env:
542552
LANG: 'C.UTF-8'
543553
PYTHONIOENCODING: 'utf-8:backslashreplace'
@@ -630,7 +640,10 @@ stages:
630640
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))")
631641
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
632642
stestr run
643+
python ./tools/verify_parallel_map.py
633644
displayName: 'Run tests'
645+
env:
646+
QISKIT_PARALLEL: FALSE
634647
- task: CopyFiles@2
635648
condition: failed()
636649
displayName: 'Copy images'
@@ -712,6 +725,7 @@ stages:
712725
export PYTHONHASHSEED=$(python -S -c "import random; print(random.randint(1, 4294967295))")
713726
echo "PYTHONHASHSEED=$PYTHONHASHSEED"
714727
stestr run
728+
python ./tools/verify_parallel_map.py
715729
displayName: 'Run tests'
716730
- task: CopyFiles@2
717731
condition: failed()

examples/python/stochastic_swap.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,22 @@
7373
# Build the expected output to verify the pass worked
7474
expected = QuantumCircuit(qr, cr)
7575
expected.cx(qr[1], qr[2])
76+
expected.h(qr[2])
7677
expected.swap(qr[0], qr[1])
78+
expected.h(qr[0])
7779
expected.cx(qr[1], qr[3])
7880
expected.h(qr[3])
79-
expected.h(qr[2])
8081
expected.measure(qr[1], cr[0])
81-
expected.h(qr[0])
8282
expected.swap(qr[1], qr[3])
83-
expected.h(qr[3])
8483
expected.cx(qr[2], qr[1])
84+
expected.h(qr[3])
85+
expected.swap(qr[0], qr[1])
8586
expected.measure(qr[2], cr[2])
86-
expected.swap(qr[1], qr[3])
87-
expected.measure(qr[3], cr[3])
88-
expected.cx(qr[1], qr[0])
89-
expected.measure(qr[1], cr[0])
90-
expected.measure(qr[0], cr[1])
87+
expected.cx(qr[3], qr[1])
88+
expected.measure(qr[0], cr[3])
89+
expected.measure(qr[3], cr[0])
90+
expected.measure(qr[1], cr[1])
9191
expected_dag = circuit_to_dag(expected)
92-
9392
# Run the pass on the dag from the input circuit
9493
pass_ = StochasticSwap(coupling, 20, 999)
9594
after = pass_.run(dag)

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[build-system]
2-
requires = ["Cython>=0.27.1", "setuptools", "wheel"]
2+
requires = ["Cython>=0.27.1", "setuptools", "wheel", "setuptools-rust"]
3+
build-backend = "setuptools.build_meta"
34

45
[tool.black]
56
line-length = 100
@@ -16,3 +17,7 @@ test-command = "python {project}/examples/python/stochastic_swap.py"
1617
# Numpy 1.22 there are no i686 wheels, so we force pip to use older ones without
1718
# restricting any dependencies that Numpy and Scipy might have.
1819
before-test = "pip install --only-binary=numpy,scipy numpy scipy"
20+
21+
[tool.cibuildwheel.linux]
22+
before-all = "yum install -y wget && {package}/tools/install_rust.sh"
23+
environment = 'PATH="$PATH:$HOME/.cargo/bin"'

qiskit/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
import sys
1919
import warnings
2020

21+
import qiskit._accelerate
22+
23+
# Globally define compiled modules. The normal import mechanism will not
24+
# find compiled submodules in _accelerate because it relies on file paths
25+
# manually define them on import so people can directly import
26+
# qiskit._accelerate.* submodules and not have to rely on attribute access
27+
sys.modules["qiskit._accelerate.stochastic_swap"] = qiskit._accelerate.stochastic_swap
28+
29+
2130
# qiskit errors operator
2231
from qiskit.exceptions import QiskitError, MissingOptionalLibraryError
2332

0 commit comments

Comments
 (0)