Skip to main content

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

MIT

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

quasim-0.2.0.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distribution

quasim-0.2.0-py3-none-any.whl (13.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page