Skip to content

Commit

Permalink
[improve] 5-star circuits, refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Zen committed May 5, 2023
1 parent 39da064 commit 6014262
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 192 deletions.
70 changes: 69 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,70 @@
from htcircuits import ht_stabilizer
from collections import defaultdict
from src.htcircuits import ht_stabilizer
from src.htcircuits.lc_classes import *
from src.htcircuits.circuit_lookup import circuit_lookup
import matplotlib.pyplot as plt


def stabilizer_circuit_statistics(num_qubits, connectivity):

cost = defaultdict(int)
depth = defaultdict(int)

LCClasses = [LCClass2, LCClass3, LCClass4, LCClass5]
cls = LCClasses[num_qubits - 2]

for id in range(cls.count()):
circuit_info = circuit_lookup(num_qubits, connectivity, id)
cost[circuit_info.cost] += 1
depth[circuit_info.depth] += 1

average_cost = 0
for the_cost, count in cost.items():
average_cost += the_cost*count
average_cost /= cls.count()

average_depth = 0
for the_depth, count in depth.items():
average_depth += the_depth*count
average_depth /= cls.count()

max_cost = max(cost.keys())
max_depth = max(depth.keys())

print(f"Circuit statistics {connectivity}: \n avg 2-qubit count: {average_cost}\n"
f" avg 2-qubit depth: {average_depth}\n max 2-qubit count: {max_cost}\n max 2-qubit depth: {max_depth}")

plt.figure(figsize=(3, 4))
plt.title(f"{num_qubits} qubits {connectivity}")

# plt.plot(cost.keys(), cost.values(), label="cx count")
plt.bar(list(cost.keys()), list(cost.values()), color=(1, 0, 0, .5), label="cx count")
plt.bar(list(depth.keys()), list(depth.values()), color=(0, 1, 0, .5), label="cx depth")

plt.legend()
plt.tight_layout()


print("3 qubits")
stabilizer_circuit_statistics(3, "all")
stabilizer_circuit_statistics(3, "linear")

print("4 qubits")
stabilizer_circuit_statistics(4, "all")
stabilizer_circuit_statistics(4, "linear")
stabilizer_circuit_statistics(4, "star")
stabilizer_circuit_statistics(4, "cycle")

print("5 qubits")
stabilizer_circuit_statistics(5, "all")
stabilizer_circuit_statistics(5, "linear")
stabilizer_circuit_statistics(5, "star")
stabilizer_circuit_statistics(5, "cycle")
stabilizer_circuit_statistics(5, "T")
stabilizer_circuit_statistics(5, "Q")

plt.show()


# 4 Qubits: all > cycle, star > linear
# 5 Qubits: all > star > cycle > Q > T > linear
2 changes: 1 addition & 1 deletion src/htcircuits/circuit_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parse_circuit(self) -> QuantumCircuit:
return qc


def circuit_lookup(num_qubits: int, connectivity: str, id):
def circuit_lookup(num_qubits: int, connectivity: str, id: int):
filename = f"stabilizer{num_qubits}-{connectivity}.txt"

try:
Expand Down
44 changes: 22 additions & 22 deletions src/htcircuits/data/stabilizer5-star.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
65:2:2:h0 cx0,1 cx0,4 h0 h2 h3 h4
33:2:2:h0 cx0,1 cx0,3 h0 h2 h3 h4
17:2:2:h0 cx0,1 cx0,2 h0 h2 h3 h4
528:8:8:h4 h3 h2 h1 h0 cz0,4 swap3,0 cz0,2 swap1,0
288:8:8:h4 h3 h2 h1 h0 cz0,4 swap2,0 cz0,3 swap1,0
192:8:8:h4 h3 h2 h1 h0 cz0,3 swap2,0 cz0,4 swap1,0
528:6:6:h0 h3 cz0,3 h0 h4 cz0,4 h0 s0 h1 cz0,1 cz0,3 s0 h0 h2 cz0,2 h0 s1 cz0,1 s1 h1 h2 h3 h4
288:6:6:h0 h2 cz0,2 s0 h4 cz0,4 h0 h4 cz0,4 s0 h0 h1 cz0,1 s0 h3 cz0,3 h0 h1 cz0,1 h2 s2 h4
192:6:6:h0 s3 h3 cz0,3 h0 s0 h2 cz0,2 h0 s3 cz0,3 h1 cz0,1 h4 cz0,4 h0 h4 s4 cz0,4 h1 s1 h4
136:4:4:h0 cx0,2 cx0,3 h0 h1 h3 h4 cz0,2 cz0,4
260:4:4:h0 cx0,2 cx0,4 h0 h1 h3 h4 cz0,2 cz0,3
514:4:4:h0 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