@@ -287,22 +287,21 @@ def result_types_tensor_x_y_testing(device: Device, run_kwargs: dict[str, Any]):
287
287
varphi = - 0.543
288
288
obs = Observable .X () @ Observable .Y ()
289
289
obs_targets = [0 , 2 ]
290
+ expected_mean = np .sin (theta ) * np .sin (phi ) * np .sin (varphi )
291
+ expected_var = (
292
+ 8 * np .sin (theta ) ** 2 * np .cos (2 * varphi ) * np .sin (phi ) ** 2
293
+ - np .cos (2 * (theta - phi ))
294
+ - np .cos (2 * (theta + phi ))
295
+ + 2 * np .cos (2 * theta )
296
+ + 2 * np .cos (2 * phi )
297
+ + 14
298
+ ) / 16
299
+ expected_eigs = get_pauli_eigenvalues (1 )
290
300
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
291
301
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
292
302
for task in tasks :
293
303
result = device .run (task , ** run_kwargs ).result ()
294
304
295
- expected_mean = np .sin (theta ) * np .sin (phi ) * np .sin (varphi )
296
- expected_var = (
297
- 8 * np .sin (theta ) ** 2 * np .cos (2 * varphi ) * np .sin (phi ) ** 2
298
- - np .cos (2 * (theta - phi ))
299
- - np .cos (2 * (theta + phi ))
300
- + 2 * np .cos (2 * theta )
301
- + 2 * np .cos (2 * phi )
302
- + 14
303
- ) / 16
304
- expected_eigs = get_pauli_eigenvalues (1 )
305
-
306
305
assert_variance_expectation_sample_result (
307
306
result , shots , expected_var , expected_mean , expected_eigs
308
307
)
@@ -315,15 +314,15 @@ def result_types_tensor_z_z_testing(device: Device, run_kwargs: dict[str, Any]):
315
314
varphi = - 0.543
316
315
obs = Observable .Z () @ Observable .Z ()
317
316
obs_targets = [0 , 2 ]
317
+ expected_mean = 0.849694136476246
318
+ expected_var = 0.27801987443788634
319
+ expected_eigs = get_pauli_eigenvalues (1 )
320
+
318
321
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
319
322
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
320
323
for task in tasks :
321
324
result = device .run (task , ** run_kwargs ).result ()
322
325
323
- expected_mean = 0.849694136476246
324
- expected_var = 0.27801987443788634
325
- expected_eigs = get_pauli_eigenvalues (1 )
326
-
327
326
assert_variance_expectation_sample_result (
328
327
result , shots , expected_var , expected_mean , expected_eigs
329
328
)
@@ -343,15 +342,15 @@ def result_types_tensor_hermitian_hermitian_testing(device: Device, run_kwargs:
343
342
])
344
343
obs = Observable .Hermitian (matrix1 ) @ Observable .Hermitian (matrix2 )
345
344
obs_targets = [0 , 1 , 2 ]
345
+ expected_mean = - 4.30215023196904
346
+ expected_var = 370.71292282796804
347
+ expected_eigs = np .array ([- 70.90875406 , - 31.04969387 , 0 , 3.26468993 , 38.693758 ])
348
+
346
349
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
347
350
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
348
351
for task in tasks :
349
352
result = device .run (task , ** run_kwargs ).result ()
350
353
351
- expected_mean = - 4.30215023196904
352
- expected_var = 370.71292282796804
353
- expected_eigs = np .array ([- 70.90875406 , - 31.04969387 , 0 , 3.26468993 , 38.693758 ])
354
-
355
354
assert_variance_expectation_sample_result (
356
355
result , shots , expected_var , expected_mean , expected_eigs
357
356
)
@@ -364,21 +363,20 @@ def result_types_tensor_z_h_y_testing(device: Device, run_kwargs: dict[str, Any]
364
363
varphi = - 0.543
365
364
obs = Observable .Z () @ Observable .H () @ Observable .Y ()
366
365
obs_targets = [0 , 1 , 2 ]
366
+ expected_mean = - (np .cos (varphi ) * np .sin (phi ) + np .sin (varphi ) * np .cos (theta )) / np .sqrt (2 )
367
+ expected_var = (
368
+ 3
369
+ + np .cos (2 * phi ) * np .cos (varphi ) ** 2
370
+ - np .cos (2 * theta ) * np .sin (varphi ) ** 2
371
+ - 2 * np .cos (theta ) * np .sin (phi ) * np .sin (2 * varphi )
372
+ ) / 4
373
+ expected_eigs = get_pauli_eigenvalues (1 )
374
+
367
375
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
368
376
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
369
377
for task in tasks :
370
378
result = device .run (task , ** run_kwargs ).result ()
371
379
372
- expected_mean = - (np .cos (varphi ) * np .sin (phi ) + np .sin (varphi ) * np .cos (theta )) / np .sqrt (
373
- 2
374
- )
375
- expected_var = (
376
- 3
377
- + np .cos (2 * phi ) * np .cos (varphi ) ** 2
378
- - np .cos (2 * theta ) * np .sin (varphi ) ** 2
379
- - 2 * np .cos (theta ) * np .sin (phi ) * np .sin (2 * varphi )
380
- ) / 4
381
- expected_eigs = get_pauli_eigenvalues (1 )
382
380
assert_variance_expectation_sample_result (
383
381
result , shots , expected_var , expected_mean , expected_eigs
384
382
)
@@ -397,50 +395,51 @@ def result_types_tensor_z_hermitian_testing(device: Device, run_kwargs: dict[str
397
395
])
398
396
obs = Observable .Z () @ Observable .Hermitian (array )
399
397
obs_targets = [0 , 1 , 2 ]
398
+ expected_mean = 0.5 * (
399
+ - 6 * np .cos (theta ) * (np .cos (varphi ) + 1 )
400
+ - 2 * np .sin (varphi ) * (np .cos (theta ) + np .sin (phi ) - 2 * np .cos (phi ))
401
+ + 3 * np .cos (varphi ) * np .sin (phi )
402
+ + np .sin (phi )
403
+ )
404
+ expected_var = (
405
+ 1057
406
+ - np .cos (2 * phi )
407
+ + 12 * (27 + np .cos (2 * phi )) * np .cos (varphi )
408
+ - 2 * np .cos (2 * varphi ) * np .sin (phi ) * (16 * np .cos (phi ) + 21 * np .sin (phi ))
409
+ + 16 * np .sin (2 * phi )
410
+ - 8 * (- 17 + np .cos (2 * phi ) + 2 * np .sin (2 * phi )) * np .sin (varphi )
411
+ - 8 * np .cos (2 * theta ) * (3 + 3 * np .cos (varphi ) + np .sin (varphi )) ** 2
412
+ - 24 * np .cos (phi ) * (np .cos (phi ) + 2 * np .sin (phi )) * np .sin (2 * varphi )
413
+ - 8
414
+ * np .cos (theta )
415
+ * (
416
+ 4
417
+ * np .cos (phi )
418
+ * (
419
+ 4
420
+ + 8 * np .cos (varphi )
421
+ + np .cos (2 * varphi )
422
+ - (1 + 6 * np .cos (varphi )) * np .sin (varphi )
423
+ )
424
+ + np .sin (phi )
425
+ * (
426
+ 15
427
+ + 8 * np .cos (varphi )
428
+ - 11 * np .cos (2 * varphi )
429
+ + 42 * np .sin (varphi )
430
+ + 3 * np .sin (2 * varphi )
431
+ )
432
+ )
433
+ ) / 16
434
+
435
+ z_array = np .diag ([1 , - 1 ])
436
+ expected_eigs = np .linalg .eigvalsh (np .kron (z_array , array ))
437
+
400
438
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
401
439
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
402
440
for task in tasks :
403
441
result = device .run (task , ** run_kwargs ).result ()
404
442
405
- expected_mean = 0.5 * (
406
- - 6 * np .cos (theta ) * (np .cos (varphi ) + 1 )
407
- - 2 * np .sin (varphi ) * (np .cos (theta ) + np .sin (phi ) - 2 * np .cos (phi ))
408
- + 3 * np .cos (varphi ) * np .sin (phi )
409
- + np .sin (phi )
410
- )
411
- expected_var = (
412
- 1057
413
- - np .cos (2 * phi )
414
- + 12 * (27 + np .cos (2 * phi )) * np .cos (varphi )
415
- - 2 * np .cos (2 * varphi ) * np .sin (phi ) * (16 * np .cos (phi ) + 21 * np .sin (phi ))
416
- + 16 * np .sin (2 * phi )
417
- - 8 * (- 17 + np .cos (2 * phi ) + 2 * np .sin (2 * phi )) * np .sin (varphi )
418
- - 8 * np .cos (2 * theta ) * (3 + 3 * np .cos (varphi ) + np .sin (varphi )) ** 2
419
- - 24 * np .cos (phi ) * (np .cos (phi ) + 2 * np .sin (phi )) * np .sin (2 * varphi )
420
- - 8
421
- * np .cos (theta )
422
- * (
423
- 4
424
- * np .cos (phi )
425
- * (
426
- 4
427
- + 8 * np .cos (varphi )
428
- + np .cos (2 * varphi )
429
- - (1 + 6 * np .cos (varphi )) * np .sin (varphi )
430
- )
431
- + np .sin (phi )
432
- * (
433
- 15
434
- + 8 * np .cos (varphi )
435
- - 11 * np .cos (2 * varphi )
436
- + 42 * np .sin (varphi )
437
- + 3 * np .sin (2 * varphi )
438
- )
439
- )
440
- ) / 16
441
-
442
- z_array = np .diag ([1 , - 1 ])
443
- expected_eigs = np .linalg .eigvalsh (np .kron (z_array , array ))
444
443
assert_variance_expectation_sample_result (
445
444
result , shots , expected_var , expected_mean , expected_eigs
446
445
)
@@ -459,15 +458,16 @@ def result_types_tensor_y_hermitian_testing(device: Device, run_kwargs: dict[str
459
458
])
460
459
obs = Observable .Y () @ Observable .Hermitian (array )
461
460
obs_targets = [0 , 1 , 2 ]
461
+ expected_mean = 1.4499810303182408
462
+ expected_var = 74.03174647518193
463
+ y_array = np .array ([[0 , - 1j ], [1j , 0 ]])
464
+ expected_eigs = np .linalg .eigvalsh (np .kron (y_array , array ))
465
+
462
466
circuit = get_result_types_three_qubit_circuit (theta , phi , varphi , obs , obs_targets , shots )
463
467
tasks = (circuit , circuit .to_ir (ir_type = IRType .OPENQASM ))
464
468
for task in tasks :
465
469
result = device .run (task , ** run_kwargs ).result ()
466
470
467
- expected_mean = 1.4499810303182408
468
- expected_var = 74.03174647518193
469
- y_array = np .array ([[0 , - 1j ], [1j , 0 ]])
470
- expected_eigs = np .linalg .eigvalsh (np .kron (y_array , array ))
471
471
assert_variance_expectation_sample_result (
472
472
result , shots , expected_var , expected_mean , expected_eigs
473
473
)
@@ -490,6 +490,19 @@ def result_types_noncommuting_testing(device: Device, run_kwargs: dict[str, Any]
490
490
obs2_targets = [0 , 2 ]
491
491
obs3 = Observable .Y () @ Observable .Hermitian (array )
492
492
obs3_targets = [0 , 1 , 2 ]
493
+ expected_mean1 = np .sin (theta ) * np .sin (phi ) * np .sin (varphi )
494
+ expected_var1 = (
495
+ 8 * np .sin (theta ) ** 2 * np .cos (2 * varphi ) * np .sin (phi ) ** 2
496
+ - np .cos (2 * (theta - phi ))
497
+ - np .cos (2 * (theta + phi ))
498
+ + 2 * np .cos (2 * theta )
499
+ + 2 * np .cos (2 * phi )
500
+ + 14
501
+ ) / 16
502
+
503
+ expected_mean2 = 0.849694136476246
504
+ expected_mean3 = 1.4499810303182408
505
+
493
506
circuit = (
494
507
get_result_types_three_qubit_circuit (theta , phi , varphi , obs1 , obs1_targets , shots )
495
508
.expectation (obs2 , obs2_targets )
@@ -499,18 +512,6 @@ def result_types_noncommuting_testing(device: Device, run_kwargs: dict[str, Any]
499
512
for task in tasks :
500
513
result = device .run (task , ** run_kwargs ).result ()
501
514
502
- expected_mean1 = np .sin (theta ) * np .sin (phi ) * np .sin (varphi )
503
- expected_var1 = (
504
- 8 * np .sin (theta ) ** 2 * np .cos (2 * varphi ) * np .sin (phi ) ** 2
505
- - np .cos (2 * (theta - phi ))
506
- - np .cos (2 * (theta + phi ))
507
- + 2 * np .cos (2 * theta )
508
- + 2 * np .cos (2 * phi )
509
- + 14
510
- ) / 16
511
-
512
- expected_mean2 = 0.849694136476246
513
- expected_mean3 = 1.4499810303182408
514
515
assert np .allclose (result .values [0 ], expected_var1 )
515
516
assert np .allclose (result .values [1 ], expected_mean1 )
516
517
assert np .allclose (result .values [2 ], expected_mean2 )
0 commit comments