-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfondq_stack_main.py
59 lines (48 loc) · 1.55 KB
/
fondq_stack_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import random
# Import the Grover implementation
from grover_algorithm import *
# This is for the device
from fondq_device import FondQDevice
# This is for the optimisers
from cnotopt import CNOTOptimizer, ReplaceHadamards
"""
Start mapping and optimisation
"""
qubit_count = 2
# circuit_sample_count = 10
#Set up input and output qubits.
(input_qubits, output_qubit) = set_io_qubits(qubit_count)
#Choose the x' and make an oracle which can recognize it.
x_bits = [random.randint(0, 1) for _ in range(qubit_count)]
print('Secret bit sequence: {}'.format(x_bits))
# Make oracle (black box)
oracle = make_oracle(input_qubits, output_qubit, x_bits)
# Embed the oracle into a quantum circuit implementing Grover's algorithm.
# circuit = make_grover_circuit(input_qubits, output_qubit, oracle)
print('Circuit:')
circuit = cirq.Circuit(
make_grover_circuit(input_qubits, output_qubit, oracle)
,device=FondQDevice(7, 4)
)
print(circuit)
print("\n")
# Make sure that the Hadamards are next to the CNOT
circuit_earliest = cirq.Circuit(circuit.all_operations())
#
print("Optimize the CNOTs\n")
cnotopt = CNOTOptimizer()
cnotopt.optimize_circuit(circuit_earliest)
print(circuit_earliest)
# #
print("Replace Hadamards\n")
hopt = ReplaceHadamards()
hopt.optimize_circuit(circuit_earliest)
print(circuit_earliest)
#
print("Reinsert all the gates\n")
circuit_earliest = cirq.Circuit(circuit_earliest.all_operations())
print(circuit_earliest)
print("\nRemove empty moments")
remempty = cirq.DropEmptyMoments()
remempty.optimize_circuit(circuit_earliest)
print(circuit_earliest)