Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dev
__pycache__
.idea
Binary file not shown.
10 changes: 10 additions & 0 deletions Brown_Quantum_Initiative/circuits/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .cnot_only_circuits import (
create_deep_cnot_circuit,
create_deep_cnot_circuit_with_mapping,
)
from .qft import (
append_qft_circuit_with_mapping,
append_inverse_qft_circuit_with_mapping,
append_qft_circuit,
append_inverse_qft_circuit,
)
23 changes: 23 additions & 0 deletions Brown_Quantum_Initiative/circuits/cnot_only_circuits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from braket.circuits import Circuit

QUBITS = 11


def create_deep_cnot_circuit(cnot_depth):
circuit = Circuit()
for i in range(0, QUBITS - 1, 2):
circuit.cnot(i, i + 1)
circuit.i(QUBITS - 1)
for _ in range(cnot_depth - 1):
circuit.cnot(0, 1)
return circuit


def create_deep_cnot_circuit_with_mapping(cnot_depth, mapping):
circuit = Circuit()
for i in range(0, QUBITS - 1, 2):
circuit.cnot(mapping[i], mapping[i + 1])
circuit.i(mapping[QUBITS - 1])
for _ in range(cnot_depth - 1):
circuit.cnot(mapping[0], mapping[1])
return circuit
74 changes: 74 additions & 0 deletions Brown_Quantum_Initiative/circuits/qft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import numpy as np
from braket.circuits import Circuit


def append_qft_circuit(circuit, qubits):
# Apply the QFT transformation
for j in range(qubits):
# Apply the Hadamard gate to the j-th qubit
circuit.h(j)
# Apply the controlled phase rotations
for k in range(j + 1, qubits):
# The angle for the controlled rotation
angle = 2 * np.pi / (2 ** (k - j + 1))
circuit.cphaseshift(k, j, angle)

# Reverse the order of the qubits
for qubit in range(qubits // 2):
circuit.swap(qubit, qubits - qubit - 1)

return circuit


def append_qft_circuit_with_mapping(circuit, qubits, mapping):
# Apply the QFT transformation
for j in range(qubits):
# Apply the Hadamard gate to the j-th qubit
circuit.h(mapping[j])
# Apply the controlled phase rotations
for k in range(j + 1, qubits):
# The angle for the controlled rotation
angle = 2 * np.pi / (2 ** (k - j + 1))
circuit.cphaseshift(mapping[k], mapping[j], angle)

# Reverse the order of the qubits
for qubit in range(qubits // 2):
circuit.swap(mapping[qubit], mapping[qubits - qubit - 1])

return circuit


def append_inverse_qft_circuit(circuit: Circuit, qubits):
# Reverse the order of the qubits first
for qubit in range(qubits // 2):
circuit.swap(qubit, qubits - qubit - 1)

# Apply the inverse QFT transformation
for j in range(qubits - 1, -1, -1):
# Apply the controlled phase rotations in reverse order
for k in range(qubits - 1, j, -1):
# The angle for the controlled rotation, with a negative sign for the inverse
angle = -2 * np.pi / (2 ** (k - j + 1))
circuit.cphaseshift(k, j, angle)
# Apply the Hadamard gate to the j-th qubit
circuit.h(j)

return circuit


def append_inverse_qft_circuit_with_mapping(circuit: Circuit, qubits, mapping: list):
# Reverse the order of the qubits first
for qubit in range(qubits // 2):
circuit.swap(mapping[qubit], mapping[qubits - qubit - 1])

# Apply the inverse QFT transformation
for j in range(qubits - 1, -1, -1):
# Apply the controlled phase rotations in reverse order
for k in range(qubits - 1, j, -1):
# The angle for the controlled rotation, with a negative sign for the inverse
angle = -2 * np.pi / (2 ** (k - j + 1))
circuit.cphaseshift(mapping[k], mapping[j], angle)
# Apply the Hadamard gate to the j-th qubit
circuit.h(mapping[j])

return circuit
66 changes: 66 additions & 0 deletions Brown_Quantum_Initiative/deep_cnot_circuit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from mapping import gather_stats, create_logical_to_physical_mapping
from noise_model import noise_model
from braket.circuits import Circuit, Observable, Gate
from braket.devices import LocalSimulator
from circuits import (
create_deep_cnot_circuit,
create_deep_cnot_circuit_with_mapping,
append_qft_circuit_with_mapping,
append_inverse_qft_circuit,
append_inverse_qft_circuit_with_mapping,
append_qft_circuit,
)
from edge_coloring import color_edges_of_complete_graph
import numpy as np
import matplotlib.pyplot as plt

QUBITS = 11


if __name__ == "__main__":
device = LocalSimulator("braket_dm")
run_shots = 1000
nm = noise_model()
cnot_depth_range = np.arange(10, 20, 4)

deep_cnot_success_rate = []
deep_cnot_remapped_success_rate = []

for cnot_depth in cnot_depth_range:
deep_cnot_circuit = create_deep_cnot_circuit(cnot_depth=cnot_depth)
deep_cnot_circuit = nm.apply(deep_cnot_circuit)
result = (
device.run(deep_cnot_circuit, shots=run_shots).result().measurement_counts
)
deep_cnot_success_rate.append(result["00000000000"] / run_shots)

stats = gather_stats(nm, device, shots=1000)
logical_to_physical_mapping = create_logical_to_physical_mapping(
circuit=deep_cnot_circuit, stats=stats
)
deep_cnot_circuit_with_remapping = create_deep_cnot_circuit_with_mapping(
cnot_depth=cnot_depth, mapping=logical_to_physical_mapping
)
deep_cnot_circuit_with_remapping = nm.apply(deep_cnot_circuit_with_remapping)
result = (
device.run(deep_cnot_circuit_with_remapping, shots=run_shots)
.result()
.measurement_counts
)
deep_cnot_remapped_success_rate.append(result["00000000000"] / run_shots)

fig, ax = plt.subplots(figsize=(8, 5), dpi=96)
plt.plot(cnot_depth_range, deep_cnot_success_rate, label="without remapping")
plt.plot(cnot_depth_range, deep_cnot_remapped_success_rate, label="with remapping")

plt.xlabel("number of CNOT gates")
plt.ylabel("success rate")
plt.title(f"Deep CNOT circuit success rate")
ax.legend(
loc="upper right",
fancybox=True,
shadow=True,
ncol=2,
)

plt.show()
48 changes: 48 additions & 0 deletions Brown_Quantum_Initiative/deep_qft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from mapping import gather_stats, create_logical_to_physical_mapping
from noise_model import noise_model
from braket.circuits import Circuit
from braket.devices import LocalSimulator
from circuits import (
append_qft_circuit_with_mapping,
append_inverse_qft_circuit,
append_inverse_qft_circuit_with_mapping,
append_qft_circuit,
)

QUBITS = 11

if __name__ == "__main__":
device = LocalSimulator("braket_dm")
run_shots = 10000
qft_depth = 2
nm = noise_model()

qft_circuit = Circuit()
for _ in range(qft_depth):
qft_circuit = append_qft_circuit(qubits=QUBITS, circuit=qft_circuit)
qft_circuit = append_inverse_qft_circuit(qubits=QUBITS, circuit=qft_circuit)
qft_circuit = nm.apply(qft_circuit)
result = device.run(qft_circuit, shots=run_shots).result().measurement_counts
print(result)

qft_circuit_remapped = Circuit()
stats = gather_stats(nm, device, shots=1000)
logical_to_physical_mapping = create_logical_to_physical_mapping(
circuit=qft_circuit, stats=stats
)
for _ in range(qft_depth):
qft_circuit_remapped = append_qft_circuit_with_mapping(
qubits=QUBITS,
circuit=qft_circuit_remapped,
mapping=logical_to_physical_mapping,
)
qft_circuit_remapped = append_inverse_qft_circuit_with_mapping(
qubits=QUBITS,
circuit=qft_circuit_remapped,
mapping=logical_to_physical_mapping,
)
qft_circuit_remapped = nm.apply(qft_circuit_remapped)
result = (
device.run(qft_circuit_remapped, shots=run_shots).result().measurement_counts
)
print(result)
19 changes: 19 additions & 0 deletions Brown_Quantum_Initiative/edge_coloring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def color_edges_of_complete_graph(n):
# Determine the number of colors needed (chromatic index)
num_colors = n if n % 2 == 1 else n - 1

# Initialize the colors for each edge
# edge_colors = {}
colors_to_edges = dict()
for color in range(n):
colors_to_edges[color] = []

# Assign colors to edges
for i in range(n):
for j in range(i + 1, n):
# For each edge (i, j), assign a color based on a greedy approach
# We use the modulo operator to cycle through colors
color = (i + j) % num_colors
colors_to_edges[color].append((i, j))

return colors_to_edges
Loading