Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

145 plot compiler versions over time on graph #173

Merged
merged 17 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.4.0
Binary file removed benchmarks/avg_compiler_benchmarks_over_time.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions benchmarks/results/expval_2025-01-14_10.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Compiler versions: qiskit=1.3.1, cirq=1.4.1, pytket=1.36.0, ucc=0.2.0 # OS: Darwin Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64, Architecture: 64bit, CPU Cores: 16
compiler,circuit_name,observable,expval,absoluate_error,relative_error,ideal_expval
qiskit,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.8365006877842944e-06,0.008099166252094033,1.0003503440169654,0.008096329751406249
pytket,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687800232e-06,0.008099166252094048,1.0003503440169672,0.008096329751406249
ucc,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687794811e-06,0.008099166252094043,1.0003503440169665,0.008096329751406249
cirq,qaoa_barabasi_albert,ZZZZZZZZZZ,0.00032650888149378995,0.007769820869912459,0.9596719882318184,0.008096329751406249
ucc,qft,ZZZZZZZZZZ,5.204170427930421e-18,4.9873280567030744e-18,22.99978564371141,2.1684237122734696e-19
qiskit,qft,ZZZZZZZZZZ,-6.505213034913027e-19,8.673636747186495e-19,3.9999732054639257,2.1684237122734696e-19
pytket,qft,ZZZZZZZZZZ,-3.2526065174565133e-18,3.46944888868386e-18,15.99986602731963,2.1684237122734696e-19
cirq,qft,ZZZZZZZZZZ,-7.589415207398531e-19,9.757838919672e-19,4.499968739707914,2.1684237122734696e-19
ucc,prep_select,ZZZZZZZZZZ,-2.8189256484623115e-18,1.134324764839284e-16,1.0254844512916448,1.1061355083546608e-16
qiskit,prep_select,ZZZZZZZZZZ,-3.0357660829594124e-18,1.136493169184255e-16,1.0274447936986943,1.1061355083546608e-16
pytket,prep_select,ZZZZZZZZZZ,-6.7220534694101275e-18,1.173356043048762e-16,1.0607706146185376,1.1061355083546608e-16
ucc,qcnn,ZZZZZZZZZZ,-0.000616808474649776,0.0027601976170682566,0.8173504998517849,-0.0033770060917180326
qiskit,qcnn,ZZZZZZZZZZ,-0.0006168084746498157,0.0027601976170682167,0.8173504998517731,-0.0033770060917180326
pytket,qcnn,ZZZZZZZZZZ,-0.0006168084746497968,0.0027601976170682357,0.8173504998517788,-0.0033770060917180326
cirq,prep_select,ZZZZZZZZZZ,2.0102192480053738e-15,1.8996056971699076e-15,17.173354284553316,1.1061355083546608e-16
cirq,qcnn,ZZZZZZZZZZ,-0.000583198919178234,0.0027938071725397986,0.8273029709337791,-0.0033770060917180326
qiskit,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.8365006877842944e-06,0.008099166252094033,1.0003503440169654,0.008096329751406249
ucc,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687794811e-06,0.008099166252094043,1.0003503440169665,0.008096329751406249
pytket,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687800232e-06,0.008099166252094048,1.0003503440169672,0.008096329751406249
qiskit,qft,ZZZZZZZZZZ,-6.505213034913027e-19,8.673636747186495e-19,3.9999732054639257,2.1684237122734696e-19
ucc,qft,ZZZZZZZZZZ,5.204170427930421e-18,4.9873280567030744e-18,22.99978564371141,2.1684237122734696e-19
pytket,qft,ZZZZZZZZZZ,-3.2526065174565133e-18,3.46944888868386e-18,15.99986602731963,2.1684237122734696e-19
cirq,qaoa_barabasi_albert,ZZZZZZZZZZ,0.0003265088814937855,0.0077698208699124634,0.959671988231819,0.008096329751406249
cirq,qft,ZZZZZZZZZZ,1.4094628242311558e-18,1.1926204530038089e-18,5.49994194517184,2.1684237122734696e-19
ucc,qcnn,ZZZZZZZZZZ,-0.000616808474649776,0.0027601976170682566,0.8173504998517849,-0.0033770060917180326
qiskit,qcnn,ZZZZZZZZZZ,-0.0006168084746498157,0.0027601976170682167,0.8173504998517731,-0.0033770060917180326
pytket,qcnn,ZZZZZZZZZZ,-0.0006168084746497968,0.0027601976170682357,0.8173504998517788,-0.0033770060917180326
cirq,qcnn,ZZZZZZZZZZ,-0.0005831989191782427,0.00279380717253979,0.8273029709337766,-0.0033770060917180326
qiskit,prep_select,ZZZZZZZZZZ,-3.0357660829594124e-18,1.136493169184255e-16,1.0274447936986943,1.1061355083546608e-16
pytket,prep_select,ZZZZZZZZZZ,-6.7220534694101275e-18,1.173356043048762e-16,1.0607706146185376,1.1061355083546608e-16
ucc,prep_select,ZZZZZZZZZZ,-2.8189256484623115e-18,1.134324764839284e-16,1.0254844512916448,1.1061355083546608e-16
cirq,prep_select,ZZZZZZZZZZ,2.0006782688875013e-15,1.890064718052035e-15,17.087099218643136,1.1061355083546608e-16
qiskit,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.8365006877842944e-06,0.008099166252094033,1.0003503440169654,0.008096329751406249
pytket,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687800232e-06,0.008099166252094048,1.0003503440169672,0.008096329751406249
ucc,qaoa_barabasi_albert,ZZZZZZZZZZ,-2.836500687794811e-06,0.008099166252094043,1.0003503440169665,0.008096329751406249
qiskit,qft,ZZZZZZZZZZ,-6.505213034913027e-19,8.673636747186495e-19,3.9999732054639257,2.1684237122734696e-19
ucc,qft,ZZZZZZZZZZ,5.204170427930421e-18,4.9873280567030744e-18,22.99978564371141,2.1684237122734696e-19
pytket,qft,ZZZZZZZZZZ,-3.2526065174565133e-18,3.46944888868386e-18,15.99986602731963,2.1684237122734696e-19
cirq,qaoa_barabasi_albert,ZZZZZZZZZZ,0.00032650888149378106,0.007769820869912468,0.9596719882318194,0.008096329751406249
cirq,qft,ZZZZZZZZZZ,-1.734723475976807e-18,1.951565847204154e-18,8.999928547903803,2.1684237122734696e-19
qiskit,qv,ZZZZZZZZZZ,5.1571072402243636e-05,0.0070951933270006024,0.9927839971321074,0.007146764399402846
ucc,qv,ZZZZZZZZZZ,5.157107240225025e-05,0.0070951933270005955,0.9927839971321065,0.007146764399402846
pytket,qv,ZZZZZZZZZZ,5.157107240225079e-05,0.007095193327000595,0.9927839971321064,0.007146764399402846
qiskit,qcnn,ZZZZZZZZZZ,-0.0006168084746498157,0.0027601976170682167,0.8173504998517731,-0.0033770060917180326
ucc,qcnn,ZZZZZZZZZZ,-0.000616808474649776,0.0027601976170682566,0.8173504998517849,-0.0033770060917180326
pytket,qcnn,ZZZZZZZZZZ,-0.0006168084746497968,0.0027601976170682357,0.8173504998517788,-0.0033770060917180326
cirq,qcnn,ZZZZZZZZZZ,-0.0005831989191782399,0.002793807172539793,0.8273029709337775,-0.0033770060917180326
cirq,qv,ZZZZZZZZZZ,5.726778341950641e-05,0.00708949661598334,0.9919868936179999,0.007146764399402846
qiskit,prep_select,ZZZZZZZZZZ,-3.0357660829594124e-18,1.136493169184255e-16,1.0274447936986943,1.1061355083546608e-16
pytket,prep_select,ZZZZZZZZZZ,-6.7220534694101275e-18,1.173356043048762e-16,1.0607706146185376,1.1061355083546608e-16
ucc,prep_select,ZZZZZZZZZZ,-2.8189256484623115e-18,1.134324764839284e-16,1.0254844512916448,1.1061355083546608e-16
cirq,prep_select,ZZZZZZZZZZ,2.008701364963894e-15,1.898087814128428e-15,17.15963188770397,1.1061355083546608e-16
26 changes: 0 additions & 26 deletions benchmarks/results/gates_2024-11-14_12-22-50.csv

This file was deleted.

2 changes: 1 addition & 1 deletion benchmarks/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .common import log_performance, save_results
from .common import log_performance, save_results, annotate_and_adjust, adjust_axes_to_fit_labels
from .qiskit_circuits import qaoa_ising_ansatz, qcnn_circuit, VQE_ansatz, random_clifford_circuit
from .cirq_circuits import cirq_prep_select
from .generate_layouts import generate_tilted_square_coupling_list, generate_heavy_hex_coupling_list
128 changes: 127 additions & 1 deletion benchmarks/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
import os
import pandas as pd
import matplotlib
from datetime import datetime
from cirq import CZTargetGateset, optimize_for_target_gateset
from pytket.circuit import OpType
Expand All @@ -21,7 +22,6 @@
from ucc import __version__ as ucc_version

import sys # Add sys to accept command line arguments
import os
from ucc import compile as ucc_compile


Expand Down Expand Up @@ -188,10 +188,136 @@ def save_results(results_log, benchmark_name="gates", folder="../results", appen

print(f"Results saved to {file_path}")


# Read the QASM files passed as command-line arguments
def get_qasm_files():
if len(sys.argv) < 2:
print("No QASM files provided. Please provide them as command-line arguments.")
sys.exit(1)

return sys.argv[1:]


def annotate_and_adjust(ax, text, xy, color, previous_bboxes, offset=(0, 15), increment=5, fontsize=8, max_attempts=20):
"""
Annotates the plot while dynamically adjusting the position to avoid overlaps. In-place operation.

Parameters:
ax (matplotlib.axes.Axes): The axis object to annotate.
text (str): The annotation text.
xy (tuple): The (x, y) coordinates for the annotation anchor point.
color (str): The color for the text and arrow.
previous_bboxes (list): A list to track previous annotation bounding boxes (in data coordinates).
offset (tuple): The initial offset in points (x_offset, y_offset).
increment (int): The vertical adjustment increment in points to resolve overlaps.
fontsize (int): Font size of the annotation text.
max_attempts (int): The maximum number of position adjustments to resolve overlaps.

Returns:
None
"""
# Create the annotation
annotation = ax.annotate(
text,
xy,
textcoords="offset points",
xytext=offset, # Default offset
ha='center',
fontsize=fontsize,
color=color,
arrowprops=dict(
arrowstyle="->",
color=color,
lw=0.5,
shrinkA=5, # Shrink arrow length to avoid overlap
shrinkB=5
),
bbox=dict(
boxstyle="round,pad=0.2",
edgecolor=color,
facecolor="white",
alpha=0.5
)
)

# Get the bounding box of the annotation in data coordinates
renderer = ax.figure.canvas.get_renderer()
bbox = annotation.get_tightbbox(renderer).transformed(ax.transData.inverted())

attempts = 0
# Adjust position to avoid overlap
while any(bbox.overlaps(prev_bbox) for prev_bbox in previous_bboxes):
# Increase vertical offset to move annotation upward
current_offset = annotation.xyann[1]
annotation.set_position((offset[0], current_offset + increment))
# Update the bounding box after adjustment
bbox = annotation.get_window_extent(renderer).transformed(ax.transData.inverted())

# Increment the attempt counter and check for max attempts
attempts += 1
if attempts >= max_attempts:
print(f"Warning: Maximum adjustment attempts reached for annotation '{text}'.")
break
# Add the final bounding box to the list of previous bounding boxes
previous_bboxes.append(bbox)
# Needed to plot points in correct order
ax.figure.canvas.flush_events()


def adjust_axes_to_fit_labels(ax, x_scale=1.0, y_scale=1.0, x_log=False, y_log=False):
"""
Adjust the axes limits to ensure all labels and annotations fit within the view. In-place operation.

Parameters:
- ax: The Matplotlib axes object to adjust.
- x_scale: The factor by which to expand the x-axis limits.
- y_scale: The factor by which to expand the y-axis limits.
- x_log: Set to True if the x-axis uses a logarithmic scale.
- y_log: Set to True if the y-axis uses a logarithmic scale.
"""
renderer = ax.figure.canvas.get_renderer()

# Get the current axes limits
x_min, x_max = ax.get_xlim()
y_min, y_max = ax.get_ylim()

# Check the position of all annotations
all_bboxes = [
child.get_window_extent(renderer=renderer).transformed(ax.transData.inverted())
for child in ax.get_children() if isinstance(child, matplotlib.text.Annotation)
]

# Expand x-axis limits if annotations are off the edge
for bbox in all_bboxes:
if bbox.x0 < x_min: # Left edge
x_min = bbox.x0
if bbox.x1 > x_max: # Right edge
x_max = bbox.x1

# Expand y-axis limits if annotations are off the edge
for bbox in all_bboxes:
if bbox.y0 < y_min: # Bottom edge
y_min = bbox.y0
if bbox.y1 > y_max: # Top edge
y_max = bbox.y1

# Apply scaling factors based on whether axes are logarithmic
if x_log:
x_min = x_min / x_scale
x_max = x_max * x_scale
else:
x_range = x_max - x_min
x_min -= (x_scale - 1) * x_range
x_max += (x_scale - 1) * x_range

if y_log:
y_min = y_min / y_scale
y_max = y_max * y_scale
else:
y_range = y_max - y_min
y_min -= (y_scale - 1) * y_range
y_max += (y_scale - 1) * y_range

# Set the new axis limits
ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)
Loading
Loading