A Qiskit's compiler plugin to reuse qubits using midcircuit measurement
Project description
Qubit Reuse By Reset Plugin
This repository contains an experimental transpiler pass called qubit_reuse
which is executed at the end of the init
stage of transpilation. This pass is based on: Matthew DeCross et al. "Qubit-reuse compilation with mid-circuit measurement and reset" arXiv:2210.0.08039v1
Background
Certain circuits can reduce the number of qubits required to produce results by resetting and re-using existent measured qubits. The order in which certain qubits are chosen is based on their causal cones and the order in which they are measured.
Causal Cones
Let's say we have qubit a x in a DAGCircuit
. We can traverse the DAGCircuit
from the output node of x by checking all its predecessor nodes. When checking every operation node found, if at any point x interacts with other qubits, via a multi-qubit gate, the qubits in that operation are added to a set. From that point we continue evaluating recursively all the predecessor nodes in that multi-qubit interaction and adding all qubits found into the set, until no more predecessor nodes are left.
When the traversal ends, the set will contain all the qubits whose interactions affect qubit x. That is what we call the causal cone of x.
Order of Measurement
Qubits are re-arranged based on the length of their causal cones in ascending order, i.e. the first to be re-arranged are those with smaller causal cones.
Before re-arranging a qubit, we need to check if there are any qubit that have been measured and is available to re-use. If so, we reset it and apply all operations onto its wire. Otherwise, a new qubit is added and the operations are passed on to that wire.
Installation
This package is not available through pypi, but can be installed by cloning this repository:
git clone https://github.com/qiskit-community/qiskit-qubit-reuse
And then installing locally:
pip install ./qiskit-qubit-reuse
If you have the proper authentication keys, you can install it remotely by using:
pip install git+https://github.com/qiskit-community/qiskit-qubit-reuse
Usage
Once installed, Qiskit is able to detect the qubit_reuse
plugin via an entry point. All that needs to be done is to specify the init method in your transpile
call by using init_method="qubit_reuse"
. Use the following example:
from qiskit.circuit.random import random_circuit
from qiskit import transpile
from qiskit.providers.fake_provider import FakeGuadalupeV2
qc = random_circuit(16, 4, measure=True)
transpiled_qc = transpile(qc, backend=FakeGuadalupeV2(), init_method="qubit_reuse")
This entry point provides the option with the least amount of qubits. If you want to specifically use the normal or dual circuit, you can specifcy that by using the qubit_reuse_normal
or the qubit_reuse_dual
endpoints.
Warning: This plugin should only be used with circuits that contain measurements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qiskit-qubit-reuse-0.0.2.tar.gz
.
File metadata
- Download URL: qiskit-qubit-reuse-0.0.2.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a19546cb51881e234c1cf7b57e7d6e81e11e42ca6a81eed6967603c3a6954c03 |
|
MD5 | 69b30f3df7cb11eda8b99ffc7c1c9fd3 |
|
BLAKE2b-256 | 37f3aa061998ef302ee837f27de81659460f6d5b263b60528a95107b04c349ce |
File details
Details for the file qiskit_qubit_reuse-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: qiskit_qubit_reuse-0.0.2-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07cc093154ad99024f1fbd71c9dff68898abf641bcaee38aebcb0071cf6f2305 |
|
MD5 | 638a547d50b72c1e9ef4161b3071dfce |
|
BLAKE2b-256 | bb6cba8fde32e0deb3111e1958b6c855096410bb363ce5d5485f03cc3b247835 |