forked from quantumlib/Cirq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplace_on_bristlecone.py
88 lines (78 loc) · 5.94 KB
/
place_on_bristlecone.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
77
78
79
80
81
82
83
84
85
86
87
88
# pylint: disable=line-too-long
"""Create a circuit, optimize it, and map it onto a Bristlecone chip.
===EXAMPLE_OUTPUT===
Length 10 line on Bristlecone:
(5, 0)━━(5, 1)
┃
(6, 1)━━(6, 2)
┃
(7, 2)━━(7, 3)
┃
(8, 3)━━(8, 4)
┃
(9, 4)━━(9, 5)
Initial circuit:
0: ───×───────M('all')───
│ │
1: ───×───×───M──────────
│ │
2: ───×───×───M──────────
│ │
3: ───×───×───M──────────
│ │
4: ───×───×───M──────────
│ │
5: ───×───×───M──────────
│ │
6: ───×───×───M──────────
│ │
7: ───×───×───M──────────
│ │
8: ───×───×───M──────────
│ │
9: ───×───────M──────────
Xmon circuit:
(5, 0): ───Y^-0.5───@───Y^0.5───@───────Y^-0.5───@──────────────────────────────────────────────────────────────────M('all')───
│ │ │ │
(5, 1): ───X^-0.5───@───X^0.5───@───────X^-0.5───@────────X^0.5───────────@───X^-0.5───@────────X^0.5───@───────────M──────────
│ │ │ │
(6, 1): ───Y^-0.5───────@───────Y^0.5───@────────Y^-0.5───@───────Y^0.5───@───Y^-0.5───@────────Y^0.5───@───────────M──────────
│ │ │ │
(6, 2): ───X^-0.5───────@───────X^0.5───@────────X^-0.5───@───────X^0.5───────@────────X^-0.5───@───────X^0.5───@───M──────────
│ │ │ │
(7, 2): ───Y^-0.5───@───Y^0.5───@───────Y^-0.5───@────────Y^0.5───────────────@────────Y^-0.5───@───────Y^0.5───@───M──────────
│ │ │ │
(7, 3): ───X^-0.5───@───X^0.5───@───────X^-0.5───@────────X^0.5───────────@───X^-0.5───@────────X^0.5───@───────────M──────────
│ │ │ │
(8, 3): ───Y^-0.5───────@───────Y^0.5───@────────Y^-0.5───@───────Y^0.5───@───Y^-0.5───@────────Y^0.5───@───────────M──────────
│ │ │ │
(8, 4): ───X^-0.5───────@───────X^0.5───@────────X^-0.5───@───────X^0.5───────@────────X^-0.5───@───────X^0.5───@───M──────────
│ │ │ │
(9, 4): ───Y^-0.5───@───Y^0.5───@───────Y^-0.5───@────────Y^0.5───────────────@────────Y^-0.5───@───────Y^0.5───@───M──────────
│ │ │ │
(9, 5): ───X^-0.5───@───X^0.5───@───────X^-0.5───@──────────────────────────────────────────────────────────────────M──────────
"""
import cirq
import cirq_google
def main():
print("Length 10 line on Bristlecone:")
line = cirq_google.line_on_device(cirq_google.Bristlecone, length=10)
print(line)
print("Initial circuit:")
n = 10
depth = 2
circuit = cirq.Circuit(
cirq.SWAP(cirq.LineQubit(j), cirq.LineQubit(j + 1))
for i in range(depth)
for j in range(i % 2, n - 1, 2)
)
circuit.append(cirq.measure(*cirq.LineQubit.range(n), key='all'))
print(circuit)
print()
print("Xmon circuit:")
translated = cirq_google.optimized_for_xmon(
circuit=circuit, new_device=cirq_google.Bristlecone, qubit_map=lambda q: line[q.x]
)
print(translated)
if __name__ == '__main__':
main()