Skip to content

Full State Quantum Circuit Simulation Beyond Memory Limit

License

Notifications You must be signed in to change notification settings

Zhaoyilunnn/qdao

Repository files navigation

Tests qiskit

What is qdao

qdao is a quantum data access optimization framework. It leverages secondary storage to simulate large scale quantum circuits and minimizes the data movement between memory and secondary storage. The memory requirement of full state quantum circuit simulation grows exponentially with the number of qubits. For example, on a typical PC, simulate a circuit with more than 30 qubits can easily result in out-of-memory error. With qdao, the memory occupation of simulation is completely under your control.

Install

git clone https://github.com/Zhaoyilunnn/qdao.git
cd qdao
pip install .

Testing

pytest tests/

Usage

Basic Usage

The following example can be found in the examples/ directory and more examples will be added in the future.

The following code snippet shows the basic usage of qdao. You can configure the num_primary parameter to reduce the memory occupation.

$\text{memory consumption} = 2^{\text{num-primary}} * 16 \text{ Byte}$

from qdao import Engine
from qiskit.circuit.random import random_circuit
from qiskit import transpile
from qiskit_aer import Aer

num_qubits = 12
num_primary = 10
num_local = 8

# Create a qiskit quantum circuit `circ`
circ = random_circuit(num_qubits, 10, measure=False, max_operands=2)
backend = Aer.get_backend("aer_simulator")
circ = transpile(circ, backend=backend)

# `num_primary`: size of a compute unit, i.e., $m$ in QDAO paper
# `num_local`: size of a storage unit, i.e., $t$ in QDAO paper
eng = Engine(circuit=circ, num_primary=num_primary, num_local=num_local)
eng.run()

GPU Simulation

To use GPU for simulation and use host memory to store the entire statevector, try following configurations.

First you need to install qiskit-aer-gpu. Please refer to the official document.

eng = Engine(circuit=circ, num_primary=num_primary, num_local=num_local, sv_location="memory", device="GPU")

Backends

You can specify a backend simulator by using backend option, currently only qiskit and pyquafu are supported.

# First transform qiskit circuit to a quafu circuit
from quafu import QuantumCircuit
quafu_circ = QuantumCircuit(1)

# For qiskit < 1.0
quafu_circ.from_openqasm(circ.qasm())

# For qiskit >= 1.0, `qasm()` api has been deprecated.
from qiskit.qasm2 import dumps
quafu_circ.from_openqasm(dumps(circ))

# Create a new engine using quafu backend
eng = Engine(circuit=quafu_circ, num_primary=num_primary, num_local=num_local, backend="quafu")
eng.run()

Get Simulation Results

We're working on to support measurement in qdao, currently please obtain state vector after simulation as follows.

from qdao.util import retrieve_sv
res = retrieve_sv(num_qubits, num_local=num_local)
print(res)

Citation

If you find our work useful, please kindly cite our paper as below.

@inproceedings{qdao2023,
  title={Full State Quantum Circuit Simulation Beyond Memory Limit},
  author={Zhao, Yilun and Chen, Yu and Li, He and Wang, Ying and Chang, Kaiyan and Wang, Bingmeng and Li, Bing and Han, Yinhe},
  booktitle={2023 IEEE/ACM International Conference on Computer-Aided Design (ICCAD)},
  year={2023},
  organization={IEEE}
}

Development

See the CONTRIBUTING.md.

Features

There are some key features to be supported in the future

  • GPU simulation
  • Noisy simulation

Limitations

When using qiskit backend, setting initial statevector in qiskit incurs significant overhead due To

  1. Qiskit treats state vector as parameters and implements time-coonsuming validation logics, see #14.
  2. There exists additional data copy when submitting circuit with initial state vector to Aer. E.g., if you set 1 GB initial state vector, it actually consumes 2 GB memory during simulation.

Short-Term Solutions

  1. You can use the tagged stable version, which requires qiskit < 1.0 and we did some tricky modifications in qiskit to eliminate the validation overhead.
git checkout stable/0.1
pip install .
  1. You can use quafu backend. Algthough itself is slower than Qiskit, it does not have the problems of qiskit when using QDAO. Indeed, QDAO-PyQuafu is faster than QDAO-Qiskit for large circuit (>=28 Qubits).

  2. Since the additional overhead of qiskit is completely implementation issue, you might want to measure the ideal performance of QDAO-Qiskit. To do so, you could comment this line, which however leads to wrong simulations results.

Long-Term

  • We will implement a customized C++ high-performance backend and integrate it into QDAO. Please stay tuned.

Issues

Please file an issue or contact zyilun8@gmail.com if you encounter any problems.