In [ ]:
# Configuration parameters. Feel free to mess with these!
import cirq
num_circuits = 10
depth = 4
routing_attempts = range(1, 100, 10) # [1, 6, 11, 16, 21, 26, 31]
device = cirq.google.Bristlecone
compiler = lambda circuit: cirq.google.optimized_for_xmon(
circuit=circuit,
new_device=device)
print(f"Configuration: depth {depth} with "
f"{num_circuits} circuits of routing attempts {routing_attempts}")
In [ ]:
# Run the Quantum Volume algorithm over the above parameters.
import numpy as np
from cirq.contrib import quantum_volume
samplers = [
cirq.DensityMatrixSimulator(noise=cirq.ConstantQubitNoiseModel(
qubit_noise_gate=cirq.DepolarizingChannel(p=.005)))]
results = []
for r in routing_attempts:
print(f"Running with {r} routing attempt(s)")
results.append(quantum_volume.calculate_quantum_volume(num_circuits=num_circuits,
depth=depth,
num_qubits=depth,
device=device,
samplers=samplers,
compiler=compiler,
seed=None,
routing_attempts=r))
In [ ]:
# Create a chart that plots the HOG rate relative to the simulated error ratio.
from matplotlib import pyplot as plt
import statistics
probs = []
for idx, r in enumerate(routing_attempts):
result = results[idx]
probs.append(statistics.mean([res.sampler_result for res in result]))
fig, axs = plt.subplots()
axs.plot(routing_attempts, probs)
# Line markers for asymptotic ideal heavy output probability and the ideal Heavy
# Output Generation threshold.
axs.axhline((1 + np.log(2)) / 2,
color='tab:green',
label='Asymptotic ideal',
linestyle='dashed')
axs.axhline(2 / 3, label='HOG threshold', color='k', linestyle='dotted')
axs.set_ybound(0.4, 1)
axs.set_xlabel("Number of routing attempts")
axs.set_ylabel("est. heavy output probability")
fig.suptitle(f'HOG probability by number of routing attempts for d={depth}')