Efficient simulation of quantum computing circuits.
Project description
QuaSim: Qua(ntum Simulation made) Sim(ple)
QuaSim is a Python library for simulating quantum circuits. It was created partly as a learning project, partly out of necessity. For my master thesis, I required a quantum circuit simulator that was easy to set up, had low overhead, and was comparatively faster than Qiskit on the amount of qubits that my experiments required.
qubit_num\simulator | qiskit 0.45.1 | quasim 0.1.0 | quasim 0.2.0 |
---|---|---|---|
3 | 15.06s | 3.15s | 2.71s |
4 | 15.20s | 4.43s | 3.83s |
5 | 15.06s | 5.03s | 3.76s |
6 | 14.16s | 7.76s | 4.69s |
7 | 14.36s | 13.60s | 6.32s |
8 | 15.28s | 30.61s | 8.75s |
Table 1: Execution time on 1000 randomly generated circuits with 40 gates each.
Aside from a low degree of overhead and dependencies (numpy only), QuaSim's speed gain comes down to the way it detects and handles entanglement, since entanglement is the reason why quantum circuits experience exponential resource growth when simulated on classical computers.
Unless a qubit has been entangled with other qubits through the use of a controlled gate, QuaSim stores and evolves its state independently from all other qubits. Once two qubits become entangled, they form a joined qubit group, which is then stored and evolved independently from the remaining qubits in the system. Joined states are only used when they cannot be avoided. At each time step, a completely unentangled circuit would only need to keep track of N qubit states, instead of $2^N$ state combinations and, hence, would only require gate matrices of dimension $2\times2$ instead of $2^N\times2^N$.
For a more foundational introduction to the mathematics and intuition of quantum circuit simulation, I recommend Aws Albarghouthi's great article "A Quantum Circuit Simulator in 27 Lines of Python".
Installation
Use the package manager pip to install quasim.
pip install quasim
Usage
from quasim import QuaSim, Circuit
from quasim.gates import H, CX, X
circuit = Circuit(2)
circuit.apply(H(target_qubit=0))
circuit.apply(CX(control_qubit=0, target_qubit=1))
simulator = QuaSim()
simulator.evaluate_circuit(circuit)
print(circuit.state)
print(circuit.probabilities)
print(circuit.probability_dict)
Benchmarking
The benchmarking folder contains code that compares the performance of QuaSim to Qiskit, a popular framework in the context of quantum computing. It compares both approaches in terms of execution time and simulation results. Before executing any of the scripts, make sure you have all the required requirements installed as specified in benchmark/requirements.txt.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Project details
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 quasim-1.0.0.tar.gz
.
File metadata
- Download URL: quasim-1.0.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db9b27e22a0e6a253fcc51f090bc3c8cfcc0f14c8a61b6cea07d0b2fa9c7e2a3 |
|
MD5 | 832444c06f0446541e19f061110f731f |
|
BLAKE2b-256 | b117f5ddacca7d01d3e01d31016b4dd96671b98bffae2c94f319154a859aa494 |
File details
Details for the file quasim-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: quasim-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23d522737a10d8f42b00ef34a31fa1319d05bef9a14870385921452a2c4dff1f |
|
MD5 | 3b1cc7257a805d5aa7aa4a8bc1b99d7d |
|
BLAKE2b-256 | c72756d3ea6a1b31d8fa62053e86b67efe8eeedc74965ef7909bf2c8c76075ba |