-
Notifications
You must be signed in to change notification settings - Fork 0
/
transpile_qc.py
78 lines (68 loc) · 3 KB
/
transpile_qc.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def warn(*args, **kwargs):
pass
import warnings
warnings.warn = warn
import numpy as np
from qiskit import QuantumCircuit
from cirq import Simulator
from qiskit import transpile
from qiskit import circuit
import argparse
from qsyn.set_synthesis import *
from qiskit.extensions import UnitaryGate
from qsyn.state_search import *
from warnings import filterwarnings
# filterwarnings(action='ignore', category=DeprecationWarning, message='`np.int` is a deprecated alias')
# filterwarnings(action='ignore', category=DeprecationWarning, message='`np.bool` is a deprecated alias')
if __name__=="__main__":
basis_gates = ['u3', 'cx']
CT = cirq.ops.ControlledGate(sub_gate = cirq.T)
CS = cirq.ops.ControlledGate(sub_gate = cirq.S)
circuit = cirq.Circuit()
c,b,a =cirq.LineQubit.range(3)
circuit.append(cirq.H(a))
circuit.append(CS(b,a))
circuit.append(CT(c,a))
circuit.append(cirq.H(b))
circuit.append(CS(c,b))
circuit.append(cirq.H(c))
circuit.append(cirq.SWAP(a,c))
spec_QFT = cirq.unitary(circuit)
spec_cluster = [0.5, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, -0.5]
# construct by cirq then get unitary
QFT_2_WO_REV = cirq.ops.QuantumFourierTransformGate(2, without_reverse=True)
QFT_2_WO_REV_INV = cirq.ops.QuantumFourierTransformGate(2, without_reverse=True) ** -1
C_R_2 = cirq.ops.ControlledGate(sub_gate=cirq.ZPowGate(exponent=2 / (2**2)))
C_R_1 = cirq.ops.ControlledGate(sub_gate=cirq.ZPowGate(exponent=2 / (2**1)))
d,c,b,a, = cirq.LineQubit.range(4)
circuit = cirq.Circuit()
circuit.append(QFT_2_WO_REV(c, d))
circuit.append(C_R_1(a, c))
circuit.append(C_R_1(b, d))
circuit.append(C_R_2(b, d))
circuit.append(QFT_2_WO_REV_INV(c, d))
spec_draper_adder = cirq.unitary(circuit)
# for cluster
circuit_to_transpile = QuantumCircuit(4)
circuit_to_transpile.initialize(np.array(spec_cluster), list(range(len(circuit_to_transpile.qubits))))
transpiled_circuit = transpile(circuit_to_transpile, basis_gates=basis_gates, optimization_level=3)
print("==============================")
print("Transpiled Circuit of \'cluster\'")
print("==============================")
print(transpiled_circuit)
# for QFT
circuit_to_transpile = QuantumCircuit(3)
circuit_to_transpile.append(UnitaryGate(spec_QFT), circuit_to_transpile.qubits)
transpiled_circuit = transpile(circuit_to_transpile, basis_gates=basis_gates,optimization_level=3)
print("==============================")
print("Transpiled Circuit of \'QFT\'")
print("==============================")
print(transpiled_circuit)
# for draper
circuit_to_transpile = QuantumCircuit(4)
circuit_to_transpile.append(UnitaryGate(spec_draper_adder), circuit_to_transpile.qubits)
transpiled_circuit = transpile(circuit_to_transpile, basis_gates=basis_gates,optimization_level=3)
print("==============================")
print("Transpiled Circuit of \'draper\'")
print("==============================")
print(transpiled_circuit)