-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathhws6.py
More file actions
46 lines (33 loc) · 982 Bytes
/
hws6.py
File metadata and controls
46 lines (33 loc) · 982 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
45
46
# pylint: skip-file
"""Example of a 6-qubit phase function."""
import revkit
from projectq.cengines import MainEngine
from projectq.libs.revkit import PermutationOracle, PhaseOracle
from projectq.meta import Compute, Dagger, Uncompute
from projectq.ops import All, H, Measure, X
# phase function
def f(a, b, c, d, e, f):
"""Phase function."""
return (a and b) ^ (c and d) ^ (e and f)
# permutation
pi = [0, 2, 3, 5, 7, 1, 4, 6]
eng = MainEngine()
qubits = eng.allocate_qureg(6)
x = qubits[::2] # qubits on odd lines
y = qubits[1::2] # qubits on even lines
# circuit
with Compute(eng):
All(H) | qubits
All(X) | [x[0], x[1]]
PermutationOracle(pi) | y
PhaseOracle(f) | qubits
Uncompute(eng)
with Compute(eng):
with Dagger(eng):
PermutationOracle(pi, synth=revkit.dbs) | x
PhaseOracle(f) | qubits
Uncompute(eng)
All(H) | qubits
All(Measure) | qubits
# measurement result
print(f"Shift is {sum(int(q) << i for i, q in enumerate(qubits))}")