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