The quantum circuit simulator that use GPU to accerate the simulation speed.
MIT License
The quantum circuit simulator written in python that aims to use GPU/parrallel computation to accerate the simulation speed. I wish we could support the fastest qubit simulation to support the future quantum algorithm/architecture design and analysis!
Every function should obey the type checking rules Blog of Type Checking for Python
py -m mypy filetobecheck.py
The qubit index is counted from left to right. For example, when we are using an integer 0b1101 to denote a 4 qubit state, the first qubit is 1, the second qubit is 1, and the third qubit is zero. It should be pointout that
Every important function should pass at least one unittest. This is a unittest example for DJ algorithm
import random
sys.path.append('..')
import Algorithm
from Parameter import maximumqubit
import unittest
def generate_random_balance(qubit_num: int) -> np.ndarray:
n = (1 << (qubit_num - 1))
uf = [0] * n
pos = 0
for i in range(0, n):
dice = 0
while dice < 5:
dice = random.randint(0, 5)
if dice > 4:
uf.insert(pos, 1)
pos = (pos + 1) % len(uf)
return uf
class TestDJ(unittest.TestCase):
def test_constant(self):
for i in range(2, maximumqubit + 1):
inputsize = i - 1
n = (1 << (inputsize))
dice = random.randint(0, 1)
uf = [dice] * n
djalg = Algorithm.DuetchJosa(i)
djalg.set_input(uf)
djalg.construct_circuit()
djalg.compute_result()
self.assertEqual(djalg.is_balance(), False)
def test_balance(self):
for i in range(2, maximumqubit + 1):
uf = generate_random_balance(i-1)
djalg = Algorithm.DuetchJosa(i)
djalg.set_input(uf)
djalg.construct_circuit()
djalg.compute_result()
self.assertEqual(djalg.is_balance(), True)
def main():
unittest.main()
'''
Example:
alg = Algorithm.DuetchJosa(4)
uf = [1, 1, 1, 1, 1, 1, 1, 1]
alg.set_input(uf)
alg.construct_circuit()
alg.compute_result()
alg.circuit.state.show_state_dirac()
'''
if __name__ == "__main__":
main()
Here is an example code of creating a QuantumCircuit class and add some gates to it.
import Circuit
import Gate
circuit = Circuit.NumpyCircuit(2)
circuit.add_gate(Gate.CNOT(), [1, 0])
circuit.add_gate(Gate.Hadamard(), [1])
Here is another example code of creating a QuantumCircuit class, add some gates to it, do the computation and measurement.
import Circuit
circuit = Circuit.NumpyCircuit(4)
circuit.add_gate(Gate.Hadamard(), 0)
circuit.add_gate(Gate.Hadamard(), 1)
circuit.add_gate(Gate.Hadamard(), 2)
circuit.add_gate(Gate.Hadamard(), 3)
circuit.compute()
circuit.measureAll("0011")
import Algorithm
alg = Algorithm.DuetchJosa(4)
# uf is a list that define the function f(x)=uf[x], in this case, f(x) is a constant
uf = [1, 1, 1, 1, 1, 1, 1, 1]
alg.set_input(uf)
alg.construct_circuit()
alg.compute_result()
if(alg.balance):
print("Balance")
else:
print("Constant")
alg.circuit.state.show_state_dirac()
import Algorithm
alg = Algorithm.BVAlgorithm(9)
# Initialize a random a and b, such that the input function is f(x)=ax+b
a=0b10101001
b=1
alg.set_input([a,b])
alg.construct_circuit()
alg.compute_result()
print(f"The result is a={alg.solution}")
alg.circuit.state.show_state_dirac()
gvalg = Algorithm.Grover(3)
# Here, db_uf represent a database. Only the third value is 1
db_uf = [0,0,1,0,0,0,0,0]
gvalg.set_input(db_uf)
gvalg.construct_circuit()
gvalg.compute_result()
result = gvalg.solution
print(f"The key {x} has value one")
qubit_num=6
inputsize = 6 // 2
n = (1 << (inputsize))
# We set s=0b101=5
s = 0b101
# uf represent the function f(x)=uf[x]
uf = [7, 5, 0, 6, 5, 7, 6, 0]
simonalg = Algorithm.Simon(qubit_num)
simonalg.set_input(uf)
simonalg.construct_circuit()
simonalg.compute_result()
print(f"The solution is {simonalg.solution}")
Here is a qasm 2.0 code example
OPENQASM 2.0;
include "qelib1.inc";
qreg q[8];
creg c[8];
h q[0];
h q[1];
h q[2];
h q[3];
h q[4];
h q[5];
h q[6];
h q[7];
We can load and simulate the above qasm 2.0 by calling the load_qasm method of quantum circuit
import Circuit
simulator = Circuit.NumpyCircuit(8)
simulator.load_qasm(qasm_string)
simulator.compute()
print(simulator.state_vector())
Given a physical qubit model driven by pulse, automatically generate all pulse sequence
I'm currently a Master student in UCLA studying quantum computation MQST webpage. I'm especially interested in quantum architecure and quantum algorithm and I'm looking for a PHD position in this year. My email address is [email protected]