Metadata-Version: 2.1
Name: quasim
Version: 0.2.0
Summary: Efficient simulation of quantum computing circuits.
Author: Christoph Stein
License: The MIT License (MIT)
        Copyright © 2024 Christoph Stein
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/westoun/quasim
Project-URL: Issues, https://github.com/westoun/quasim/issues
Keywords: quantum,quantum computing,quantum computing simulator,simulation,simulator,quantum circuit simulator,quantum circuit
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26.0
Provides-Extra: benchmark
Requires-Dist: qiskit==0.45.1; extra == "benchmark"
Requires-Dist: qiskit-aer==0.13.1; extra == "benchmark"
Requires-Dist: qiskit-terra==0.45.1; extra == "benchmark"
Requires-Dist: scipy==1.13.0; extra == "benchmark"

# QuaSim: Qua(ntum Simulation made) Sim(ple)

[QuaSim](https://github.com/westoun/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](https://www.ibm.com/quantum/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](https://pages.cs.wisc.edu/~aws/)
great article ["A Quantum Circuit Simulator in 27 Lines of Python"](https://barghouthi.github.io/2021/08/05/quantum/).

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install quasim.

```bash
pip install quasim
```

## Usage

```python
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](https://www.ibm.com/quantum/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](https://choosealicense.com/licenses/mit/)
