27
27
28
28
29
29
def test_init__start_circuit_unsuccessful (backend : RigettiQCSBackend ):
30
- circuit = make_circuit (2 * backend .configuration ().num_qubits ) # Use too many qubits
30
+ circuit = make_circuit (num_qubits = backend .configuration ().num_qubits + 1 ) # Use too many qubits
31
31
with pytest .raises (Exception ):
32
32
make_job (backend , circuit )
33
33
34
34
35
35
def test_init__before_compile_hook (backend : RigettiQCSBackend , mocker : MockerFixture ):
36
- circuit = make_circuit (backend . configuration (). num_qubits )
36
+ circuit = make_circuit (num_qubits = 2 )
37
37
qc = get_qc (backend .configuration ().backend_name )
38
38
quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
39
39
@@ -72,7 +72,7 @@ def before_compile_hook(qasm: str) -> str:
72
72
73
73
74
74
def test_init__before_execute_hook (backend : RigettiQCSBackend , mocker : MockerFixture ):
75
- circuit = make_circuit (backend . configuration (). num_qubits )
75
+ circuit = make_circuit (num_qubits = 2 )
76
76
qc = get_qc (backend .configuration ().backend_name )
77
77
native_quil_to_executable_spy = mocker .spy (qc .compiler , "native_quil_to_executable" )
78
78
@@ -101,7 +101,7 @@ def before_execute_hook(quil: Program) -> Program:
101
101
102
102
103
103
def test_init__ensure_native_quil__true (backend : RigettiQCSBackend , mocker : MockerFixture ):
104
- circuit = make_circuit (backend . configuration (). num_qubits )
104
+ circuit = make_circuit (num_qubits = 2 )
105
105
qc = get_qc (backend .configuration ().backend_name )
106
106
quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
107
107
@@ -111,7 +111,7 @@ def test_init__ensure_native_quil__true(backend: RigettiQCSBackend, mocker: Mock
111
111
112
112
113
113
def test_init__ensure_native_quil__ignored_if_no_pre_execution_hooks (backend : RigettiQCSBackend , mocker : MockerFixture ):
114
- circuit = make_circuit (backend . configuration (). num_qubits )
114
+ circuit = make_circuit (num_qubits = 2 )
115
115
qc = get_qc (backend .configuration ().backend_name )
116
116
quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
117
117
@@ -121,7 +121,7 @@ def test_init__ensure_native_quil__ignored_if_no_pre_execution_hooks(backend: Ri
121
121
122
122
123
123
def test_init__ensure_native_quil__false (backend : RigettiQCSBackend , mocker : MockerFixture ):
124
- circuit = make_circuit (backend . configuration (). num_qubits )
124
+ circuit = make_circuit (num_qubits = 2 )
125
125
qc = get_qc (backend .configuration ().backend_name )
126
126
quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
127
127
@@ -131,7 +131,7 @@ def test_init__ensure_native_quil__false(backend: RigettiQCSBackend, mocker: Moc
131
131
132
132
133
133
def test_init__ensure_native_quil__missing (backend : RigettiQCSBackend , mocker : MockerFixture ):
134
- circuit = make_circuit (backend . configuration (). num_qubits )
134
+ circuit = make_circuit (num_qubits = 2 )
135
135
qc = get_qc (backend .configuration ().backend_name )
136
136
quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
137
137
@@ -140,14 +140,113 @@ def test_init__ensure_native_quil__missing(backend: RigettiQCSBackend, mocker: M
140
140
assert quil_to_native_quil_spy .call_count == 1 , "compile not performed correct number of times"
141
141
142
142
143
+ def test_init__circuit_with_barrier__all_qubits (backend : RigettiQCSBackend , mocker : MockerFixture ):
144
+ circuit = QuilCircuit (QuantumRegister (2 , "q" ), ClassicalRegister (2 , "ro" ))
145
+ circuit .h (0 )
146
+ circuit .barrier ()
147
+ circuit .h (0 )
148
+ circuit .measure ([0 , 1 ], [0 , 1 ])
149
+ qc = get_qc (backend .configuration ().backend_name )
150
+ quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
151
+
152
+ expected_qasm = "\n " .join (
153
+ [
154
+ "OPENQASM 2.0;" ,
155
+ 'include "qelib1.inc";' ,
156
+ "qreg q[2];" ,
157
+ "creg ro[2];" ,
158
+ "h q[0];" ,
159
+ "#pragma PRESERVE_BLOCK;" ,
160
+ "#pragma END_PRESERVE_BLOCK;" ,
161
+ "h q[0];" ,
162
+ "measure q[0] -> ro[0];" ,
163
+ "measure q[1] -> ro[1];" ,
164
+ ]
165
+ )
166
+
167
+ make_job (backend , circuit , qc )
168
+
169
+ program : Program = quil_to_native_quil_spy .call_args [0 ][0 ]
170
+ qasm = program .out (calibrations = False ).rstrip ()
171
+ assert qasm == expected_qasm
172
+
173
+
174
+ def test_init__circuit_with_barrier__all_qubits_by_qreg (backend : RigettiQCSBackend , mocker : MockerFixture ):
175
+ qreg = QuantumRegister (2 , "q" )
176
+ circuit = QuilCircuit (qreg , ClassicalRegister (2 , "ro" ))
177
+ circuit .h (0 )
178
+ circuit .barrier (qreg )
179
+ circuit .h (0 )
180
+ circuit .measure ([0 , 1 ], [0 , 1 ])
181
+ qc = get_qc (backend .configuration ().backend_name )
182
+ quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
183
+
184
+ expected_qasm = "\n " .join (
185
+ [
186
+ "OPENQASM 2.0;" ,
187
+ 'include "qelib1.inc";' ,
188
+ "qreg q[2];" ,
189
+ "creg ro[2];" ,
190
+ "h q[0];" ,
191
+ "#pragma PRESERVE_BLOCK;" ,
192
+ "#pragma END_PRESERVE_BLOCK;" ,
193
+ "h q[0];" ,
194
+ "measure q[0] -> ro[0];" ,
195
+ "measure q[1] -> ro[1];" ,
196
+ ]
197
+ )
198
+
199
+ make_job (backend , circuit , qc )
200
+
201
+ program : Program = quil_to_native_quil_spy .call_args [0 ][0 ]
202
+ qasm = program .out (calibrations = False ).rstrip ()
203
+ assert qasm == expected_qasm
204
+
205
+
206
+ def test_init__circuit_with_barrier__qubit_subset (backend : RigettiQCSBackend , mocker : MockerFixture ):
207
+ circuit = QuilCircuit (QuantumRegister (2 , "q" ), ClassicalRegister (2 , "ro" ))
208
+ circuit .h (0 )
209
+ circuit .barrier (0 )
210
+ circuit .h (0 )
211
+ circuit .measure ([0 , 1 ], [0 , 1 ])
212
+ qc = get_qc (backend .configuration ().backend_name )
213
+ quil_to_native_quil_spy = mocker .spy (qc .compiler , "quil_to_native_quil" )
214
+
215
+ expected_qasm = "\n " .join (
216
+ [
217
+ "OPENQASM 2.0;" ,
218
+ 'include "qelib1.inc";' ,
219
+ "qreg q[2];" ,
220
+ "creg ro[2];" ,
221
+ "h q[0];" ,
222
+ "h q[0];" ,
223
+ "measure q[0] -> ro[0];" ,
224
+ "measure q[1] -> ro[1];" ,
225
+ ]
226
+ )
227
+
228
+ with pytest .warns (
229
+ UserWarning ,
230
+ match = (
231
+ "barriers not applied to all circuit qubits will be omitted during execution on a RigettiQCSBackend -- "
232
+ "apply barrier to all circuit qubits to preserve barrier effect"
233
+ ),
234
+ ):
235
+ make_job (backend , circuit , qc )
236
+
237
+ program : Program = quil_to_native_quil_spy .call_args [0 ][0 ]
238
+ qasm = program .out (calibrations = False ).rstrip ()
239
+ assert qasm == expected_qasm
240
+
241
+
143
242
def test_result (job : RigettiQCSJob ):
144
243
result = job .result ()
145
244
146
245
assert result .date == job .result ().date , "Result not cached"
147
246
148
247
assert job .status () == JobStatus .DONE
149
248
150
- assert result .backend_name == "2q -qvm"
249
+ assert result .backend_name == "3q -qvm"
151
250
assert result .job_id == job .job_id ()
152
251
assert result .success is True
153
252
@@ -176,16 +275,16 @@ def test_submit(job: RigettiQCSJob):
176
275
177
276
@pytest .fixture
178
277
def backend ():
179
- return RigettiQCSProvider ().get_simulator (num_qubits = 2 )
278
+ return RigettiQCSProvider ().get_simulator (num_qubits = 3 )
180
279
181
280
182
281
@pytest .fixture
183
282
def job (backend ):
184
- circuit = make_circuit (backend . configuration (). num_qubits )
283
+ circuit = make_circuit (num_qubits = 2 )
185
284
return make_job (backend , circuit )
186
285
187
286
188
- def make_circuit (num_qubits ) -> QuilCircuit :
287
+ def make_circuit (* , num_qubits ) -> QuilCircuit :
189
288
circuit = QuilCircuit (QuantumRegister (num_qubits , "q" ), ClassicalRegister (num_qubits , "ro" ))
190
289
circuit .h (0 )
191
290
circuit .measure (range (num_qubits ), range (num_qubits ))
0 commit comments