|
| 1 | +import datetime |
| 2 | +import json |
| 3 | +import os |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +import matplotlib.pyplot as plt |
| 7 | + |
| 8 | +COMPILE_VERSIONS = ["nqasm_retry", "host_retry"] |
| 9 | +FORMATS = { |
| 10 | + "nqasm_retry": "-ro", |
| 11 | + "host_retry": "-bs", |
| 12 | +} |
| 13 | +FORMATS_2 = { |
| 14 | + "nqasm_retry": "--ro", |
| 15 | + "host_retry": "--bo", |
| 16 | +} |
| 17 | +VERSION_LABELS = { |
| 18 | + "nqasm_retry": "NetQASM retry", |
| 19 | + "host_retry": "Host retry", |
| 20 | +} |
| 21 | + |
| 22 | +X_LABELS = { |
| 23 | + "fidelity": "Fidelity", |
| 24 | + "rate": "Success probability per entanglement attempt", |
| 25 | + "t2": "T2 (ns)", |
| 26 | + "gate_noise": "2-qubit gate depolarising probability", |
| 27 | + "gate_noise_trap": "2-qubit gate depolarising probability", |
| 28 | + "gate_time": "2-qubit gate duration (ms)", |
| 29 | + "gate_time_trap": "2-qubit gate duration (ms)", |
| 30 | + "latency": "Host <-> QNodeOS latency (ms)", |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +def create_png(param_name): |
| 35 | + output_dir = os.path.join(os.path.dirname(__file__), "plots") |
| 36 | + Path(output_dir).mkdir(parents=True, exist_ok=True) |
| 37 | + timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") |
| 38 | + output_path = os.path.join(output_dir, f"bqc_sweep_{param_name}_{timestamp}.png") |
| 39 | + plt.savefig(output_path) |
| 40 | + print(f"plot written to {output_path}") |
| 41 | + |
| 42 | + |
| 43 | +def plot_host_qnos_latency(data: Dict[float, SimulationOutput]): |
| 44 | + param_name = "host_qnos_latency" |
| 45 | + |
| 46 | + data_path = os.path.join( |
| 47 | + os.path.dirname(__file__), f"sweep_data_bqc/sweep_{param_name}.json" |
| 48 | + ) |
| 49 | + |
| 50 | + with open(data_path, "r") as f: |
| 51 | + all_data = json.load(f) |
| 52 | + |
| 53 | + fig, ax = plt.subplots() |
| 54 | + |
| 55 | + ax.grid() |
| 56 | + ax.set_xlabel(X_LABELS[param_name]) |
| 57 | + ax.set_ylabel("Error rate") |
| 58 | + |
| 59 | + for version in COMPILE_VERSIONS: |
| 60 | + data = all_data[version] |
| 61 | + sweep_values = [v["sweep_value"] for v in data] |
| 62 | + error_rates = [v["error_rate"] for v in data] |
| 63 | + std_errs = [v["std_err"] for v in data] |
| 64 | + ax.errorbar( |
| 65 | + x=sweep_values, |
| 66 | + y=error_rates, |
| 67 | + yerr=std_errs, |
| 68 | + fmt=FORMATS[version], |
| 69 | + label=VERSION_LABELS[version], |
| 70 | + ) |
| 71 | + |
| 72 | + ax.set_title( |
| 73 | + "BQC trap round error rate vs two-qubit gate noise probability", |
| 74 | + wrap=True, |
| 75 | + ) |
| 76 | + |
| 77 | + # ax.set_ylim(0.10, 0.35) |
| 78 | + # ax.axhline(y=0.25, color="red", label="BQC threshold") |
| 79 | + ax.legend() |
| 80 | + # plt.tight_layout() |
| 81 | + |
| 82 | + create_png(param_name) |
| 83 | + |
| 84 | + |
| 85 | +if __name__ == "__main__": |
| 86 | + plot_gate_noise_trap() |
0 commit comments