@@ -320,7 +320,7 @@ def cross_entropy_benchmarking(
320
320
Then, take the average of $f_{mn}^{meas}$ over all circuit_mn with fixed
321
321
n to obtain:
322
322
323
- $f_{n} ^ {meas} = (\sum_m f_{mn}^{meas}) / M$
323
+ $f_{n}^ {meas} = (\sum_m f_{mn}^{meas}) / M$
324
324
325
325
4) Compute a theoretical XEB function for each circuit_mn:
326
326
@@ -332,7 +332,7 @@ def cross_entropy_benchmarking(
332
332
Similarly, we then average $f_m^{th}$ over all circuit_mn with fixed n to
333
333
obtain:
334
334
335
- $f_{n} ^ {th} = (\sum_m f_{mn}^{th}) / M$
335
+ $f_{n}^ {th} = (\sum_m f_{mn}^{th}) / M$
336
336
337
337
5) Calculate the XEB fidelity $\alpha_n$ at fixed n:
338
338
@@ -383,7 +383,7 @@ def cross_entropy_benchmarking(
383
383
# numbers of cycles. The values are 2D arrays with each row being the
384
384
# probabilities obtained from a single trial.
385
385
probs_meas = {n : np .zeros ((num_circuits , 2 ** num_qubits )) for n in cycle_range }
386
- probs_exp = {n : np .zeros ((num_circuits , 2 ** num_qubits )) for n in cycle_range }
386
+ probs_th = {n : np .zeros ((num_circuits , 2 ** num_qubits )) for n in cycle_range }
387
387
388
388
for k in range (num_circuits ):
389
389
@@ -402,17 +402,17 @@ def cross_entropy_benchmarking(
402
402
# Simulate each circuit with the Cirq simulator to obtain the
403
403
# state vector at the end of each circuit, from which the
404
404
# theoretically expected bit-string probabilities are obtained.
405
- probs_exp_k : List [np .ndarray ] = []
405
+ probs_th_k : List [np .ndarray ] = []
406
406
for circ_k in circuits_k :
407
407
res = simulator .simulate (circ_k , qubit_order = qubits )
408
408
state_probs = value .state_vector_to_probabilities (np .asarray (res .final_state_vector ))
409
- probs_exp_k .append (state_probs )
409
+ probs_th_k .append (state_probs )
410
410
411
411
for i , num_cycle in enumerate (cycle_range ):
412
- probs_exp [num_cycle ][k , :] = probs_exp_k [i ]
412
+ probs_th [num_cycle ][k , :] = probs_th_k [i ]
413
413
probs_meas [num_cycle ][k , :] = probs_meas_k [i ]
414
414
415
- fidelity_vals = _xeb_fidelities (probs_exp , probs_meas )
415
+ fidelity_vals = _xeb_fidelities (probs_th , probs_meas )
416
416
xeb_data = [CrossEntropyPair (c , k ) for (c , k ) in zip (cycle_range , fidelity_vals )]
417
417
return CrossEntropyResult (data = xeb_data , repetitions = repetitions ) # type: ignore
418
418
@@ -527,19 +527,35 @@ def _measure_prob_distribution(
527
527
528
528
529
529
def _xeb_fidelities (
530
- ideal_probs : Dict [int , np .ndarray ], actual_probs : Dict [int , np .ndarray ]
530
+ probs_th : Dict [int , np .ndarray ], probs_meas : Dict [int , np .ndarray ]
531
531
) -> List [float ]:
532
- num_cycles = sorted (list (ideal_probs .keys ()))
533
- return [_compute_fidelity (ideal_probs [n ], actual_probs [n ]) for n in num_cycles ]
532
+ """Compute XEB fidelity estimates for all circuit depths.
533
+
534
+ Args:
535
+ probs_th: Theoretical output probabilities by cycle number.
536
+ probs_meas: Experimental output probabilities by cycle number.
537
+ Returns:
538
+ List of fidelity estimates for each circuit depth.
539
+ """
540
+ num_cycles = sorted (list (probs_th .keys ()))
541
+ return [_compute_fidelity (probs_th [n ], probs_meas [n ]) for n in num_cycles ]
534
542
535
543
536
- def _compute_fidelity (probs_exp : np .ndarray , probs_meas : np .ndarray ) -> float :
537
- _ , num_states = probs_exp .shape
538
- pp_cross = probs_exp * probs_meas
539
- pp_exp = probs_exp ** 2
544
+ def _compute_fidelity (probs_th : np .ndarray , probs_meas : np .ndarray ) -> float :
545
+ """Compute XEB fidelity estimate.
546
+
547
+ Args:
548
+ probs_th: Theoretical output probabilities.
549
+ probs_meas: Experimental output probabilities.
550
+ Returns:
551
+ XEB fidelity estimate.
552
+ """
553
+ _ , num_states = probs_th .shape
554
+ pp_cross = probs_th * probs_meas
555
+ pp_th = probs_th ** 2
540
556
f_meas = np .mean (num_states * np .sum (pp_cross , axis = 1 ) - 1.0 )
541
- f_exp = np .mean (num_states * np .sum (pp_exp , axis = 1 ) - 1.0 )
542
- return float (f_meas / f_exp )
557
+ f_th = np .mean (num_states * np .sum (pp_th , axis = 1 ) - 1.0 )
558
+ return float (f_meas / f_th )
543
559
544
560
545
561
def _random_half_rotations (qubits : Sequence [ops .Qid ], num_layers : int ) -> List [List [ops .OP_TREE ]]:
0 commit comments