@@ -199,7 +199,7 @@ def _run_single(
199
199
200
200
@typechecked
201
201
def run (
202
- circuit : QCircuit ,
202
+ circuit : OneOrMany [ QCircuit ] ,
203
203
device : OneOrMany [AvailableDevice ],
204
204
values : Optional [dict [Expr | str , Complex ]] = None ,
205
205
) -> Union [Result , BatchResult ]:
@@ -220,49 +220,69 @@ def run(
220
220
221
221
Examples:
222
222
>>> c = QCircuit(
223
- ... [H (0), CNOT(0, 1), BasisMeasure([0, 1], shots=1000)],
224
- ... label="Bell pair ",
223
+ ... [X (0), CNOT(0, 1), BasisMeasure([0, 1], shots=1000)],
224
+ ... label="X CNOT circuit ",
225
225
... )
226
226
>>> result = run(c, IBMDevice.AER_SIMULATOR)
227
- >>> print(result) # doctest: +SKIP
228
- Result: IBMDevice, AER_SIMULATOR
229
- Counts: [497 , 0, 0, 503 ]
230
- Probabilities: [0.497 , 0, 0, 0.503 ]
227
+ >>> print(result)
228
+ Result: X CNOT circuit, IBMDevice, AER_SIMULATOR
229
+ Counts: [0 , 0, 0, 1000 ]
230
+ Probabilities: [0, 0, 0, 1 ]
231
231
Samples:
232
- State: 00, Index: 0, Count: 497, Probability: 0.497
233
- State: 11, Index: 3, Count: 503, Probability: 0.503
232
+ State: 11, Index: 3, Count: 1000, Probability: 1.0
234
233
Error: None
235
234
>>> batch_result = run(
236
235
... c,
237
236
... [ATOSDevice.MYQLM_PYLINALG, AWSDevice.BRAKET_LOCAL_SIMULATOR]
238
237
... )
239
- >>> print(batch_result) # doctest: +SKIP
238
+ >>> print(batch_result)
239
+ BatchResult: 2 results
240
+ Result: X CNOT circuit, ATOSDevice, MYQLM_PYLINALG
241
+ Counts: [0, 0, 0, 1000]
242
+ Probabilities: [0, 0, 0, 1]
243
+ Samples:
244
+ State: 11, Index: 3, Count: 1000, Probability: 1.0
245
+ Error: 0.0
246
+ Result: X CNOT circuit, AWSDevice, BRAKET_LOCAL_SIMULATOR
247
+ Counts: [0, 0, 0, 1000]
248
+ Probabilities: [0, 0, 0, 1]
249
+ Samples:
250
+ State: 11, Index: 3, Count: 1000, Probability: 1.0
251
+ Error: None
252
+ >>> c2 = QCircuit(
253
+ ... [X(0), X(1), BasisMeasure([0, 1], shots=1000)],
254
+ ... label="X circuit",
255
+ ... )
256
+ >>> result = run([c,c2], IBMDevice.AER_SIMULATOR)
257
+ >>> print(result)
240
258
BatchResult: 2 results
241
- Result: ATOSDevice, MYQLM_PYLINALG
242
- Counts: [499 , 0, 0, 501 ]
243
- Probabilities: [0.499 , 0, 0, 0.501 ]
259
+ Result: X CNOT circuit, IBMDevice, AER_SIMULATOR
260
+ Counts: [0 , 0, 0, 1000 ]
261
+ Probabilities: [0, 0, 0, 1 ]
244
262
Samples:
245
- State: 00, Index: 0, Count: 499, Probability: 0.499
246
- State: 11, Index: 3, Count: 501, Probability: 0.501
247
- Error: 0.01581926829057682
248
- Result: AWSDevice, BRAKET_LOCAL_SIMULATOR
249
- Counts: [502, 0, 0, 498]
250
- Probabilities: [0.502, 0, 0, 0.498]
263
+ State: 11, Index: 3, Count: 1000, Probability: 1.0
264
+ Error: None
265
+ Result: X circuit, IBMDevice, AER_SIMULATOR
266
+ Counts: [0, 0, 0, 1000]
267
+ Probabilities: [0, 0, 0, 1]
251
268
Samples:
252
- State: 00, Index: 0, Count: 502, Probability: 0.502
253
- State: 11, Index: 3, Count: 498, Probability: 0.498
269
+ State: 11, Index: 3, Count: 1000, Probability: 1.0
254
270
Error: None
255
271
256
272
"""
257
-
258
273
if values is None :
259
274
values = {}
260
275
261
- if isinstance (device , Iterable ):
262
- return BatchResult ([_run_single (circuit , dev , values ) for dev in set (device )])
263
-
264
- return _run_single (circuit , device , values )
265
-
276
+ if isinstance (circuit , Iterable ):
277
+ if isinstance (device , Iterable ):
278
+ return BatchResult ([_run_single (circ , dev , values ) for circ in circuit for dev in device ])
279
+ else :
280
+ return BatchResult ([_run_single (circ , device , values ) for circ in circuit ])
281
+ else :
282
+ if isinstance (device , Iterable ):
283
+ return BatchResult ([_run_single (circuit , dev , values ) for dev in device ])
284
+ else :
285
+ return _run_single (circuit , device , values )
266
286
267
287
@typechecked
268
288
def submit (
0 commit comments