@@ -23,7 +23,13 @@ def test_griddevice_metadata():
23
23
qubit_pairs = [(a , b ) for a in qubits for b in qubits if a != b and a .is_adjacent (b )]
24
24
isolated_qubits = [cirq .GridQubit (9 , 9 ), cirq .GridQubit (10 , 10 )]
25
25
gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate , cirq .CZ )
26
- metadata = cirq .GridDeviceMetadata (qubit_pairs , gateset , all_qubits = qubits + isolated_qubits )
26
+ target_gatesets = (cirq .CZTargetGateset (),)
27
+ metadata = cirq .GridDeviceMetadata (
28
+ qubit_pairs ,
29
+ gateset ,
30
+ all_qubits = qubits + isolated_qubits ,
31
+ compilation_target_gatesets = target_gatesets ,
32
+ )
27
33
expected_pairings = frozenset (
28
34
{
29
35
(cirq .GridQubit (0 , 0 ), cirq .GridQubit (0 , 1 )),
@@ -45,6 +51,7 @@ def test_griddevice_metadata():
45
51
assert metadata .nx_graph .nodes () == expected_graph .nodes ()
46
52
assert metadata .gate_durations is None
47
53
assert metadata .isolated_qubits == frozenset (isolated_qubits )
54
+ assert metadata .compilation_target_gatesets == target_gatesets
48
55
49
56
50
57
def test_griddevice_metadata_bad_durations ():
@@ -80,35 +87,58 @@ def test_griddevice_self_loop():
80
87
def test_griddevice_json_load ():
81
88
qubits = cirq .GridQubit .rect (2 , 3 )
82
89
qubit_pairs = [(a , b ) for a in qubits for b in qubits if a != b and a .is_adjacent (b )]
83
- gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate )
90
+ gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate , cirq . CZ )
84
91
duration = {
85
92
cirq .GateFamily (cirq .XPowGate ): cirq .Duration (nanos = 1 ),
86
93
cirq .GateFamily (cirq .YPowGate ): cirq .Duration (picos = 2 ),
87
94
cirq .GateFamily (cirq .ZPowGate ): cirq .Duration (picos = 3 ),
95
+ cirq .GateFamily (cirq .CZ ): cirq .Duration (nanos = 4 ),
88
96
}
89
97
isolated_qubits = [cirq .GridQubit (9 , 9 ), cirq .GridQubit (10 , 10 )]
98
+ target_gatesets = [cirq .CZTargetGateset ()]
90
99
metadata = cirq .GridDeviceMetadata (
91
- qubit_pairs , gateset , gate_durations = duration , all_qubits = qubits + isolated_qubits
100
+ qubit_pairs ,
101
+ gateset ,
102
+ gate_durations = duration ,
103
+ all_qubits = qubits + isolated_qubits ,
104
+ compilation_target_gatesets = target_gatesets ,
92
105
)
93
106
rep_str = cirq .to_json (metadata )
94
107
assert metadata == cirq .read_json (json_text = rep_str )
95
108
96
109
110
+ def test_griddevice_json_load_with_defaults ():
111
+ qubits = cirq .GridQubit .rect (2 , 3 )
112
+ qubit_pairs = [(a , b ) for a in qubits for b in qubits if a != b and a .is_adjacent (b )]
113
+ gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate , cirq .CZ )
114
+
115
+ # Don't set parameters with default values
116
+ metadata = cirq .GridDeviceMetadata (qubit_pairs , gateset )
117
+ rep_str = cirq .to_json (metadata )
118
+
119
+ assert metadata == cirq .read_json (json_text = rep_str )
120
+
121
+
97
122
def test_griddevice_metadata_equality ():
98
123
qubits = cirq .GridQubit .rect (2 , 3 )
99
124
qubit_pairs = [(a , b ) for a in qubits for b in qubits if a != b and a .is_adjacent (b )]
100
- gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate )
125
+ gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate , cirq . CZ , cirq . SQRT_ISWAP )
101
126
duration = {
102
127
cirq .GateFamily (cirq .XPowGate ): cirq .Duration (nanos = 1 ),
103
128
cirq .GateFamily (cirq .YPowGate ): cirq .Duration (picos = 3 ),
104
129
cirq .GateFamily (cirq .ZPowGate ): cirq .Duration (picos = 2 ),
130
+ cirq .GateFamily (cirq .CZ ): cirq .Duration (nanos = 4 ),
131
+ cirq .GateFamily (cirq .SQRT_ISWAP ): cirq .Duration (nanos = 5 ),
105
132
}
106
133
duration2 = {
107
134
cirq .GateFamily (cirq .XPowGate ): cirq .Duration (nanos = 10 ),
108
135
cirq .GateFamily (cirq .YPowGate ): cirq .Duration (picos = 13 ),
109
136
cirq .GateFamily (cirq .ZPowGate ): cirq .Duration (picos = 12 ),
137
+ cirq .GateFamily (cirq .CZ ): cirq .Duration (nanos = 14 ),
138
+ cirq .GateFamily (cirq .SQRT_ISWAP ): cirq .Duration (nanos = 15 ),
110
139
}
111
140
isolated_qubits = [cirq .GridQubit (9 , 9 )]
141
+ target_gatesets = [cirq .CZTargetGateset (), cirq .SqrtIswapTargetGateset ()]
112
142
metadata = cirq .GridDeviceMetadata (qubit_pairs , gateset , gate_durations = duration )
113
143
metadata2 = cirq .GridDeviceMetadata (qubit_pairs [:2 ], gateset , gate_durations = duration )
114
144
metadata3 = cirq .GridDeviceMetadata (qubit_pairs , gateset , gate_durations = None )
@@ -117,28 +147,47 @@ def test_griddevice_metadata_equality():
117
147
metadata6 = cirq .GridDeviceMetadata (
118
148
qubit_pairs , gateset , gate_durations = duration , all_qubits = qubits + isolated_qubits
119
149
)
150
+ metadata7 = cirq .GridDeviceMetadata (
151
+ qubit_pairs , gateset , compilation_target_gatesets = target_gatesets
152
+ )
153
+ metadata8 = cirq .GridDeviceMetadata (
154
+ qubit_pairs , gateset , compilation_target_gatesets = target_gatesets [::- 1 ]
155
+ )
156
+ metadata9 = cirq .GridDeviceMetadata (
157
+ qubit_pairs , gateset , compilation_target_gatesets = tuple (target_gatesets )
158
+ )
159
+ metadata10 = cirq .GridDeviceMetadata (
160
+ qubit_pairs , gateset , compilation_target_gatesets = set (target_gatesets )
161
+ )
120
162
121
163
eq = cirq .testing .EqualsTester ()
122
164
eq .add_equality_group (metadata )
123
165
eq .add_equality_group (metadata2 )
124
166
eq .add_equality_group (metadata3 )
125
167
eq .add_equality_group (metadata4 )
126
168
eq .add_equality_group (metadata6 )
169
+ eq .add_equality_group (metadata7 , metadata8 , metadata9 , metadata10 )
127
170
128
171
assert metadata == metadata5
129
172
130
173
131
174
def test_repr ():
132
175
qubits = cirq .GridQubit .rect (2 , 3 )
133
176
qubit_pairs = [(a , b ) for a in qubits for b in qubits if a != b and a .is_adjacent (b )]
134
- gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate )
177
+ gateset = cirq .Gateset (cirq .XPowGate , cirq .YPowGate , cirq .ZPowGate , cirq . CZ )
135
178
duration = {
136
179
cirq .GateFamily (cirq .XPowGate ): cirq .Duration (nanos = 1 ),
137
180
cirq .GateFamily (cirq .YPowGate ): cirq .Duration (picos = 3 ),
138
181
cirq .GateFamily (cirq .ZPowGate ): cirq .Duration (picos = 2 ),
182
+ cirq .GateFamily (cirq .CZ ): cirq .Duration (nanos = 4 ),
139
183
}
140
184
isolated_qubits = [cirq .GridQubit (9 , 9 )]
185
+ target_gatesets = [cirq .CZTargetGateset ()]
141
186
metadata = cirq .GridDeviceMetadata (
142
- qubit_pairs , gateset , gate_durations = duration , all_qubits = qubits + isolated_qubits
187
+ qubit_pairs ,
188
+ gateset ,
189
+ gate_durations = duration ,
190
+ all_qubits = qubits + isolated_qubits ,
191
+ compilation_target_gatesets = target_gatesets ,
143
192
)
144
193
cirq .testing .assert_equivalent_repr (metadata )
0 commit comments