|
| 1 | +# Copyright 2018-2021 Xanadu Quantum Technologies Inc. |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | + |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# The MIT License (MIT) |
| 16 | +# |
| 17 | +# Copyright (c) 2009-2018 Xiuzhe (Roger) Luo, |
| 18 | +# and other contributors. |
| 19 | +# |
| 20 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 21 | +# of this software and associated documentation files (the "Software"), to deal |
| 22 | +# in the Software without restriction, including without limitation the rights |
| 23 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 24 | +# copies of the Software, and to permit persons to whom the Software is |
| 25 | +# furnished to do so, subject to the following conditions: |
| 26 | +# |
| 27 | +# The above copyright notice and this permission notice shall be included in all |
| 28 | +# copies or substantial portions of the Software. |
| 29 | +# |
| 30 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 31 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 32 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 33 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 34 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 35 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 36 | +# SOFTWARE. |
| 37 | + |
| 38 | +# Acknowledging the approach for plotting from the quantum-benchmarks repository |
| 39 | +# at https://github.com/Roger-luo/quantum-benchmarks. |
| 40 | + |
| 41 | +#!/usr/bin/env python3 |
| 42 | +import os |
| 43 | +import matplotlib.pyplot as plt |
| 44 | +from matplotlib.ticker import MaxNLocator |
| 45 | +import json |
| 46 | +from parameters import qubits, ops |
| 47 | +import numpy as np |
| 48 | + |
| 49 | +colors = ["darkblue", "tab:orange", "tab:olive"] |
| 50 | +projects = [ |
| 51 | + "lightning_master.json", |
| 52 | + "lightning_pr.json", |
| 53 | + "default_qubit.json", |
| 54 | +] |
| 55 | + |
| 56 | +COLOR = dict(zip(projects, colors)) |
| 57 | + |
| 58 | +op_results = {o: [] for o in ops} |
| 59 | + |
| 60 | +for p in projects: |
| 61 | + with open(p) as f: |
| 62 | + data = json.load(f) |
| 63 | + for k in data.keys(): |
| 64 | + op_results[k].append(data[k]) |
| 65 | + |
| 66 | +fig, ax = plt.subplots(2, 2, figsize=(10, 8)) |
| 67 | +((ax1, ax2), (ax3, ax4)) = ax |
| 68 | + |
| 69 | +axes = ax.flatten() |
| 70 | + |
| 71 | +for op, a in zip(ops, ax.flatten()): |
| 72 | + a.set_xlabel("nqubits", size=16) |
| 73 | + a.set_ylabel("ns", size=16) |
| 74 | + a.set_title(op + " gate") |
| 75 | + a.xaxis.set_major_locator(MaxNLocator(integer=True)) |
| 76 | + |
| 77 | +for a, op in zip(axes, op_results.keys()): |
| 78 | + for k, v in enumerate(projects): |
| 79 | + data = op_results[op][k] |
| 80 | + data = np.array(data) * 1e9 |
| 81 | + a.semilogy(qubits, data, "-o", markersize=4, color=COLOR[v], linestyle="None") |
| 82 | + |
| 83 | +plots = [] |
| 84 | +plt.tight_layout() |
| 85 | +plt.subplots_adjust(top=0.85) |
| 86 | + |
| 87 | +lgd = fig.legend( |
| 88 | + plots, |
| 89 | + labels=[p.split(".")[0] for p in projects], |
| 90 | + loc="upper center", |
| 91 | + ncol=4, |
| 92 | + frameon=False, |
| 93 | + prop={"size": 15}, |
| 94 | + borderaxespad=-0.4, |
| 95 | + bbox_to_anchor=(0.5, 0.97), |
| 96 | +) |
| 97 | + |
| 98 | +plt.savefig("gates.png") |
0 commit comments