Skip to content

Commit

Permalink
Data for NWQBench
Browse files Browse the repository at this point in the history
Data for NWQBench
  • Loading branch information
Guigetzu1224 committed May 13, 2022
1 parent bf96abe commit a7b829c
Show file tree
Hide file tree
Showing 670 changed files with 5,098,579 additions and 0 deletions.
Binary file added NWQ_Bench/.DS_Store
Binary file not shown.
80 changes: 80 additions & 0 deletions NWQ_Bench/adder/adder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ----------------------------------------------------------------------
# NWQBench: Northwest Quantum Proxy Application Suite
# ----------------------------------------------------------------------
# Ang Li, Samuel Stein, James Ang.
# Pacific Northwest National Laboratory(PNNL), U.S.
# BSD Lincese.
# Created 04/19/2021.
# ----------------------------------------------------------------------

import numpy as np
from qiskit import QuantumCircuit
#from qiskit import execute, Aer
import sys
import os

def majority(qc,a,b,c):
qc.cx(c,b)
qc.cx(c,a)
qc.ccx(a,b,c)

def unmaj(qc,a,b,c):
qc.ccx(a,b,c)
qc.cx(c,a)
qc.cx(a,b)

def adder4(qc,a0,a1,a2,a3,b0,b1,b2,b3,cin,cout):
majority(qc,cin,b0,a0)
majority(qc,a0,b1,a1)
majority(qc,a1,b2,a2)
majority(qc,a2,b3,a3)
qc.cx(a3,cout)
unmaj(qc,a2,b3,a3)
unmaj(qc,a1,b2,a2)
unmaj(qc,a0,b1,a1)
unmaj(qc,cin,b0,a0)


n_bits = int(sys.argv[1])
if n_bits % 4 != 0 or n_bits <= 0:
print ("Number of adder bits should be a multiply of 4.\n")
exit(0)

n_qubits = n_bits * 2 + 2 + int(n_bits/4) - 1
qc = QuantumCircuit(n_qubits, n_qubits)


#===================== Initialization ====================
#we compute a=1110, b=0001, cin=1 => a=0000,b=0001,cout=1

#a[0:n_bits-1]=1110
for i in range(1,n_bits):
qc.x(i)

#b=[n_bits:2*n_bits-1]=0001
qc.x(n_bits)

#cin[2*n_bits] = 1
qc.x(2*n_bits)

#===================== Adder ====================

for i in range(0,n_bits,4):
adder4(qc,i,i+1,i+2,i+3,i+n_bits,i+n_bits+1,i+n_bits+2,i+n_bits+3,n_bits*2+int(i/4),n_bits*2+int(i/4)+1)

qc.measure_all()

if not os.path.isdir("qasm"):
os.mkdir("qasm")
qasm_file = open("qasm/" + "adder_n" + str(n_qubits) + ".qasm","w")
qasm_file.write(qc.qasm())
qasm_file.close()

#simulator = Aer.get_backend('qasm_simulator')
#job = execute(qc,simulator,shots=10)
#result = job.result()
#counts = result.get_counts(qc)
#print (counts)



55 changes: 55 additions & 0 deletions NWQ_Bench/adder/cirq/adder_n10_cirq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import cirq
import numpy as np
from functools import reduce

q = [cirq.NamedQubit('q' + str(i)) for i in range(10)]

circuit = cirq.Circuit(
cirq.X(q[1]),
cirq.X(q[2]),
cirq.X(q[3]),
cirq.X(q[4]),
cirq.X(q[8]),
cirq.CNOT(q[0], q[4]),
cirq.CNOT(q[0], q[8]),
cirq.CCX(q[8], q[4], q[0]),
cirq.CNOT(q[1], q[5]),
cirq.CNOT(q[1], q[0]),
cirq.CCX(q[0], q[5], q[1]),
cirq.CNOT(q[2], q[6]),
cirq.CNOT(q[2], q[1]),
cirq.CCX(q[1], q[6], q[2]),
cirq.CNOT(q[3], q[7]),
cirq.CNOT(q[3], q[2]),
cirq.CCX(q[2], q[7], q[3]),
cirq.CNOT(q[3], q[9]),
cirq.CCX(q[2], q[7], q[3]),
cirq.CNOT(q[3], q[2]),
cirq.CNOT(q[2], q[7]),
cirq.CCX(q[1], q[6], q[2]),
cirq.CNOT(q[2], q[1]),
cirq.CNOT(q[1], q[6]),
cirq.CCX(q[0], q[5], q[1]),
cirq.CNOT(q[1], q[0]),
cirq.CNOT(q[0], q[5]),
cirq.CCX(q[8], q[4], q[0]),
cirq.CNOT(q[0], q[8]),
cirq.CNOT(q[8], q[4]),
cirq.measure(q[0], key='meas0'),
cirq.measure(q[1], key='meas1'),
cirq.measure(q[2], key='meas2'),
cirq.measure(q[3], key='meas3'),
cirq.measure(q[4], key='meas4'),
cirq.measure(q[5], key='meas5'),
cirq.measure(q[6], key='meas6'),
cirq.measure(q[7], key='meas7'),
cirq.measure(q[8], key='meas8'),
cirq.measure(q[9], key='meas9')
)

simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1024)
result_dict = dict(result.multi_measurement_histogram(keys=['meas0', 'meas1', 'meas2', 'meas3', 'meas4', 'meas5', 'meas6', 'meas7', 'meas8', 'meas9']))
keys = list(map(lambda arr: reduce(lambda x, y: str(x) + str(y), arr[::-1]), result_dict.keys()))
counts = dict(zip(keys,[value for value in result_dict.values()]))
print(counts)
93 changes: 93 additions & 0 deletions NWQ_Bench/adder/cirq/adder_n19_cirq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import cirq
import numpy as np
from functools import reduce

q = [cirq.NamedQubit('q' + str(i)) for i in range(19)]

circuit = cirq.Circuit(
cirq.X(q[1]),
cirq.X(q[2]),
cirq.X(q[3]),
cirq.X(q[4]),
cirq.X(q[5]),
cirq.X(q[6]),
cirq.X(q[7]),
cirq.X(q[8]),
cirq.X(q[16]),
cirq.CNOT(q[0], q[8]),
cirq.CNOT(q[0], q[16]),
cirq.CCX(q[16], q[8], q[0]),
cirq.CNOT(q[1], q[9]),
cirq.CNOT(q[1], q[0]),
cirq.CCX(q[0], q[9], q[1]),
cirq.CNOT(q[2], q[10]),
cirq.CNOT(q[2], q[1]),
cirq.CCX(q[1], q[10], q[2]),
cirq.CNOT(q[3], q[11]),
cirq.CNOT(q[3], q[2]),
cirq.CCX(q[2], q[11], q[3]),
cirq.CNOT(q[3], q[17]),
cirq.CCX(q[2], q[11], q[3]),
cirq.CNOT(q[3], q[2]),
cirq.CNOT(q[2], q[11]),
cirq.CCX(q[1], q[10], q[2]),
cirq.CNOT(q[2], q[1]),
cirq.CNOT(q[1], q[10]),
cirq.CCX(q[0], q[9], q[1]),
cirq.CNOT(q[1], q[0]),
cirq.CNOT(q[0], q[9]),
cirq.CCX(q[16], q[8], q[0]),
cirq.CNOT(q[0], q[16]),
cirq.CNOT(q[16], q[8]),
cirq.CNOT(q[4], q[12]),
cirq.CNOT(q[4], q[17]),
cirq.CCX(q[17], q[12], q[4]),
cirq.CNOT(q[5], q[13]),
cirq.CNOT(q[5], q[4]),
cirq.CCX(q[4], q[13], q[5]),
cirq.CNOT(q[6], q[14]),
cirq.CNOT(q[6], q[5]),
cirq.CCX(q[5], q[14], q[6]),
cirq.CNOT(q[7], q[15]),
cirq.CNOT(q[7], q[6]),
cirq.CCX(q[6], q[15], q[7]),
cirq.CNOT(q[7], q[18]),
cirq.CCX(q[6], q[15], q[7]),
cirq.CNOT(q[7], q[6]),
cirq.CNOT(q[6], q[15]),
cirq.CCX(q[5], q[14], q[6]),
cirq.CNOT(q[6], q[5]),
cirq.CNOT(q[5], q[14]),
cirq.CCX(q[4], q[13], q[5]),
cirq.CNOT(q[5], q[4]),
cirq.CNOT(q[4], q[13]),
cirq.CCX(q[17], q[12], q[4]),
cirq.CNOT(q[4], q[17]),
cirq.CNOT(q[17], q[12]),
cirq.measure(q[0], key='meas0'),
cirq.measure(q[1], key='meas1'),
cirq.measure(q[2], key='meas2'),
cirq.measure(q[3], key='meas3'),
cirq.measure(q[4], key='meas4'),
cirq.measure(q[5], key='meas5'),
cirq.measure(q[6], key='meas6'),
cirq.measure(q[7], key='meas7'),
cirq.measure(q[8], key='meas8'),
cirq.measure(q[9], key='meas9'),
cirq.measure(q[10], key='meas10'),
cirq.measure(q[11], key='meas11'),
cirq.measure(q[12], key='meas12'),
cirq.measure(q[13], key='meas13'),
cirq.measure(q[14], key='meas14'),
cirq.measure(q[15], key='meas15'),
cirq.measure(q[16], key='meas16'),
cirq.measure(q[17], key='meas17'),
cirq.measure(q[18], key='meas18')
)

simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1024)
result_dict = dict(result.multi_measurement_histogram(keys=['meas0', 'meas1', 'meas2', 'meas3', 'meas4', 'meas5', 'meas6', 'meas7', 'meas8', 'meas9', 'meas10', 'meas11', 'meas12', 'meas13', 'meas14', 'meas15', 'meas16', 'meas17', 'meas18']))
keys = list(map(lambda arr: reduce(lambda x, y: str(x) + str(y), arr[::-1]), result_dict.keys()))
counts = dict(zip(keys,[value for value in result_dict.values()]))
print(counts)
131 changes: 131 additions & 0 deletions NWQ_Bench/adder/cirq/adder_n28_cirq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import cirq
import numpy as np
from functools import reduce

q = [cirq.NamedQubit('q' + str(i)) for i in range(28)]

circuit = cirq.Circuit(
cirq.X(q[1]),
cirq.X(q[2]),
cirq.X(q[3]),
cirq.X(q[4]),
cirq.X(q[5]),
cirq.X(q[6]),
cirq.X(q[7]),
cirq.X(q[8]),
cirq.X(q[9]),
cirq.X(q[10]),
cirq.X(q[11]),
cirq.X(q[12]),
cirq.X(q[24]),
cirq.CNOT(q[0], q[12]),
cirq.CNOT(q[0], q[24]),
cirq.CCX(q[24], q[12], q[0]),
cirq.CNOT(q[1], q[13]),
cirq.CNOT(q[1], q[0]),
cirq.CCX(q[0], q[13], q[1]),
cirq.CNOT(q[2], q[14]),
cirq.CNOT(q[2], q[1]),
cirq.CCX(q[1], q[14], q[2]),
cirq.CNOT(q[3], q[15]),
cirq.CNOT(q[3], q[2]),
cirq.CCX(q[2], q[15], q[3]),
cirq.CNOT(q[3], q[25]),
cirq.CCX(q[2], q[15], q[3]),
cirq.CNOT(q[3], q[2]),
cirq.CNOT(q[2], q[15]),
cirq.CCX(q[1], q[14], q[2]),
cirq.CNOT(q[2], q[1]),
cirq.CNOT(q[1], q[14]),
cirq.CCX(q[0], q[13], q[1]),
cirq.CNOT(q[1], q[0]),
cirq.CNOT(q[0], q[13]),
cirq.CCX(q[24], q[12], q[0]),
cirq.CNOT(q[0], q[24]),
cirq.CNOT(q[24], q[12]),
cirq.CNOT(q[4], q[16]),
cirq.CNOT(q[4], q[25]),
cirq.CCX(q[25], q[16], q[4]),
cirq.CNOT(q[5], q[17]),
cirq.CNOT(q[5], q[4]),
cirq.CCX(q[4], q[17], q[5]),
cirq.CNOT(q[6], q[18]),
cirq.CNOT(q[6], q[5]),
cirq.CCX(q[5], q[18], q[6]),
cirq.CNOT(q[7], q[19]),
cirq.CNOT(q[7], q[6]),
cirq.CCX(q[6], q[19], q[7]),
cirq.CNOT(q[7], q[26]),
cirq.CCX(q[6], q[19], q[7]),
cirq.CNOT(q[7], q[6]),
cirq.CNOT(q[6], q[19]),
cirq.CCX(q[5], q[18], q[6]),
cirq.CNOT(q[6], q[5]),
cirq.CNOT(q[5], q[18]),
cirq.CCX(q[4], q[17], q[5]),
cirq.CNOT(q[5], q[4]),
cirq.CNOT(q[4], q[17]),
cirq.CCX(q[25], q[16], q[4]),
cirq.CNOT(q[4], q[25]),
cirq.CNOT(q[25], q[16]),
cirq.CNOT(q[8], q[20]),
cirq.CNOT(q[8], q[26]),
cirq.CCX(q[26], q[20], q[8]),
cirq.CNOT(q[9], q[21]),
cirq.CNOT(q[9], q[8]),
cirq.CCX(q[8], q[21], q[9]),
cirq.CNOT(q[10], q[22]),
cirq.CNOT(q[10], q[9]),
cirq.CCX(q[9], q[22], q[10]),
cirq.CNOT(q[11], q[23]),
cirq.CNOT(q[11], q[10]),
cirq.CCX(q[10], q[23], q[11]),
cirq.CNOT(q[11], q[27]),
cirq.CCX(q[10], q[23], q[11]),
cirq.CNOT(q[11], q[10]),
cirq.CNOT(q[10], q[23]),
cirq.CCX(q[9], q[22], q[10]),
cirq.CNOT(q[10], q[9]),
cirq.CNOT(q[9], q[22]),
cirq.CCX(q[8], q[21], q[9]),
cirq.CNOT(q[9], q[8]),
cirq.CNOT(q[8], q[21]),
cirq.CCX(q[26], q[20], q[8]),
cirq.CNOT(q[8], q[26]),
cirq.CNOT(q[26], q[20]),
cirq.measure(q[0], key='meas0'),
cirq.measure(q[1], key='meas1'),
cirq.measure(q[2], key='meas2'),
cirq.measure(q[3], key='meas3'),
cirq.measure(q[4], key='meas4'),
cirq.measure(q[5], key='meas5'),
cirq.measure(q[6], key='meas6'),
cirq.measure(q[7], key='meas7'),
cirq.measure(q[8], key='meas8'),
cirq.measure(q[9], key='meas9'),
cirq.measure(q[10], key='meas10'),
cirq.measure(q[11], key='meas11'),
cirq.measure(q[12], key='meas12'),
cirq.measure(q[13], key='meas13'),
cirq.measure(q[14], key='meas14'),
cirq.measure(q[15], key='meas15'),
cirq.measure(q[16], key='meas16'),
cirq.measure(q[17], key='meas17'),
cirq.measure(q[18], key='meas18'),
cirq.measure(q[19], key='meas19'),
cirq.measure(q[20], key='meas20'),
cirq.measure(q[21], key='meas21'),
cirq.measure(q[22], key='meas22'),
cirq.measure(q[23], key='meas23'),
cirq.measure(q[24], key='meas24'),
cirq.measure(q[25], key='meas25'),
cirq.measure(q[26], key='meas26'),
cirq.measure(q[27], key='meas27')
)

simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1024)
result_dict = dict(result.multi_measurement_histogram(keys=['meas0', 'meas1', 'meas2', 'meas3', 'meas4', 'meas5', 'meas6', 'meas7', 'meas8', 'meas9', 'meas10', 'meas11', 'meas12', 'meas13', 'meas14', 'meas15', 'meas16', 'meas17', 'meas18', 'meas19', 'meas20', 'meas21', 'meas22', 'meas23', 'meas24', 'meas25', 'meas26', 'meas27']))
keys = list(map(lambda arr: reduce(lambda x, y: str(x) + str(y), arr[::-1]), result_dict.keys()))
counts = dict(zip(keys,[value for value in result_dict.values()]))
print(counts)
Loading

0 comments on commit a7b829c

Please sign in to comment.