This repository simulates quantum circuits, compiles circuits written in Python into OpenQASM, and visualizes the resulting tensor product. This repo can be used to understand the basics of quantum operations.
The implementation is based off of Qiskit and the OpenQASM paper.
First, download this repository and then install the environment using either using Anaconda or Docker.
conda create --name quantum_circuits python=3.7
conda activate quantum_circuits
pip install requirements.txt
To build:
docker build -t quantum_circuits .
To run:
docker run -it quantum_circuits bash
For quick usage:
from circuit import Circuit
# build circuit
circ = Circuit(3,5)
circ.X(2)
circ.H()
circ.barrier()
# get the current state of the qubits
circ.get_state()
# execute the circuit 800 times
circ.execute(num_instances=800)
# compile the circuit to OpenQASM
circ.compile()
# perform measurement
circ.measure(0, 1)
More examples are located here.
Gates that are currently avaliable are:
H
: Hadamard gateID, X, Y, Z
: Pauli gatesRX, RY, RZ
: Rotation gates across (x, y, or z)-axis of the Bloch SphereU3, U2, U1
: Universal gatesS, SDG
: S gate and its transposeT, TDG
: T gate and its transposeCX
: controlled not gateCCX
: Toffoli gate
To run all the test cases:
python tests.py
- Circuit gates are implemented niavely (i.e, the operation at a certain time step is created by taking the tensor product of all gates at that time step.) As a result, this implementation is not memory efficient for large numbers of qubits.
CX, CCX
gates only work if the control and target qubits are next to each other.