Created
November 5, 2019 17:41
-
-
Save willzeng/f55dc6d412fd1d94005ab1c60a6fc685 to your computer and use it in GitHub Desktop.
Function for calculating the cross-entropy benchmarking fidelity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fidelity_xeb(n_qubits: int, trials: int, n_samples: int, sampler: Callable[[np.ndarray, int], float]) -> float: | |
| dim = 2**n_qubits | |
| # keep track of the ideal simulated probabilities | |
| ideal_probs = [] | |
| # loop over the random programs | |
| for _ in range(trials): | |
| unitary = random_unitary(dim) | |
| sample_probs = [sampler(unitary, bb) for bb in range(dim)] | |
| samples = np.random.choice(dim, size=n_samples, p=sample_probs) | |
| for sample in samples: | |
| ideal_prob = simulate_probability(unitary, sample) | |
| ideal_probs.append(ideal_prob) | |
| return dim*np.mean(ideal_probs) - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment