-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtoffoli.py
More file actions
44 lines (36 loc) · 734 Bytes
/
toffoli.py
File metadata and controls
44 lines (36 loc) · 734 Bytes
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
from qiskit import QuantumCircuit, execute, Aer
from matplotlib import pyplot as plt
import numpy as np
np.set_printoptions(precision=3, suppress=True)
def csqrtx (qc, s, t):
qc.t(s) # Phase kickback
qc.h(t)
qc.t(t)
qc.cx(s,t)
qc.tdg(t)
qc.cx(s,t)
qc.h(t)
def csqrtxdg (qc, s, t):
qc.tdg(s) # Phase kickback
qc.h(t)
qc.tdg(t)
qc.cx(s,t)
qc.t(t)
qc.cx(s,t)
qc.h(t)
backend = Aer.get_backend("unitary_simulator")
qc = QuantumCircuit(3)
csqrtx(qc,2,0)
qc.barrier()
qc.cx(2,1)
qc.barrier()
csqrtxdg(qc,1,0)
qc.barrier()
qc.cx(2,1)
qc.barrier()
csqrtx(qc,1,0)
qc.barrier()
qc.draw(output='mpl')
unitary = execute(qc, backend).result().get_unitary()
print(unitary)
plt.show()