diff --git a/VERSION.txt b/VERSION.txt index 341cf11f..60a2d3e9 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.2.0 \ No newline at end of file +0.4.0 \ No newline at end of file diff --git a/benchmarks/avg_compiler_benchmarks_over_time.png b/benchmarks/avg_compiler_benchmarks_over_time.png index 2935f595..6d1bf2f6 100644 Binary files a/benchmarks/avg_compiler_benchmarks_over_time.png and b/benchmarks/avg_compiler_benchmarks_over_time.png differ diff --git a/benchmarks/results/expval_2025-01-14_10.csv b/benchmarks/results/expval_2025-01-14_10.csv new file mode 100644 index 00000000..1a5f3769 --- /dev/null +++ b/benchmarks/results/expval_2025-01-14_10.csv @@ -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 diff --git a/benchmarks/results/gates_2024-11-14_12-22-50.csv b/benchmarks/results/gates_2024-11-14_12-22-50.csv deleted file mode 100644 index 8168eb10..00000000 --- a/benchmarks/results/gates_2024-11-14_12-22-50.csv +++ /dev/null @@ -1,26 +0,0 @@ -# Compiler versions: qiskit=1.2.0, cirq=1.4.1, pytket=1.35.0, ucc=0.1.0 -circuit_name,compiler,compile_time,raw_multiq_gates,compiled_multiq_gates,gate_reduction_per_s,reduction_factor,compiled_ratio -prep_select,cirq,29.483647346496582,9744.0,9712.0,0.03402885949370838,1.0032948929159802,0.9967159277504105 -prep_select,pytket,0.06683492660522461,9744.0,9712.0,15.011535792388388,1.0032948929159802,0.9967159277504105 -prep_select,qiskit,3.6553268432617188,9744.0,9708.0,0.27458783437647144,1.003708281829419,0.9963054187192119 -prep_select,ucc,1.8089511394500732,9744.0,9710.0,0.5547422055325628,1.0035015447991762,0.9965106732348111 -qaoa_barabasi_albert,cirq,1.919739007949829,1176.0,1176.0,0.5209041415832575,1.0,1.0 -qaoa_barabasi_albert,pytket,0.007522106170654297,1176.0,1176.0,132.94148969889065,1.0,1.0 -qaoa_barabasi_albert,qiskit,0.21543478965759277,1176.0,1176.0,4.641775831978566,1.0,1.0 -qaoa_barabasi_albert,ucc,0.14392304420471191,1176.0,1176.0,6.948157645815422,1.0,1.0 -qcnn,cirq,0.8787519931793213,388.0,388.0,1.1379775041897815,1.0,1.0 -qcnn,pytket,0.007745027542114258,388.0,388.0,129.1150992765892,1.0,1.0 -qcnn,qiskit,0.08719897270202637,388.0,388.0,11.46802501237221,1.0,1.0 -qcnn,ucc,0.030181169509887695,388.0,388.0,33.13324222483786,1.0,1.0 -qft,cirq,12.202542781829834,10050.0,4648.0,0.17719424127160777,2.1622203098106714,0.46248756218905474 -qft,pytket,0.05506706237792969,10050.0,5890.0,30.985524920613145,1.7062818336162988,0.5860696517412936 -qft,qiskit,12.401751041412354,10050.0,3244.0,0.2498056215334964,3.098027127003699,0.3227860696517413 -qft,ucc,0.4927549362182617,10050.0,4548.0,4.484506131873095,2.2097625329815305,0.4525373134328358 -qv,cirq,79.42516779899597,15000.0,14856.0,0.012712507650812378,1.0096930533117932,0.9904 -qv,pytket,1.973799228668213,15000.0,15000.0,0.5066371419522404,1.0,1.0 -qv,qiskit,13.70786714553833,15000.0,14856.0,0.07365792523313378,1.0096930533117932,0.9904 -qv,ucc,3.3503639698028564,15000.0,14856.0,0.30136816847729114,1.0096930533117932,0.9904 -square_heisenberg,cirq,2.4587621688842773,2160.0,540.0,1.6268348564249695,4.0,0.25 -square_heisenberg,pytket,0.030429840087890625,2160.0,2160.0,32.86247962893318,1.0,1.0 -square_heisenberg,qiskit,0.25329041481018066,2160.0,540.0,15.79214911467398,4.0,0.25 -square_heisenberg,ucc,0.14473700523376465,2160.0,540.0,27.636332488292144,4.0,0.25 diff --git a/benchmarks/results/gates_2024-11-15_09-49-13.csv b/benchmarks/results/gates_2024-11-15_09-49-13.csv index 5c437d28..b28d02ea 100644 --- a/benchmarks/results/gates_2024-11-15_09-49-13.csv +++ b/benchmarks/results/gates_2024-11-15_09-49-13.csv @@ -1,4 +1,4 @@ -# Compiler versions: qiskit=1.2.0, cirq=1.4.1, pytket=1.35.0, ucc=0.1.0 +# Compiler versions: qiskit=1.2.0, cirq=1.4.1, pytket=1.35.0, ucc=0.1.1 circuit_name,compiler,compile_time,raw_multiq_gates,compiled_multiq_gates,gate_reduction_per_s,reduction_factor,compiled_ratio prep_select,cirq,30.072205781936646,9744.0,9712.0,0.03336286337594249,1.0032948929159802,0.9967159277504105 prep_select,pytket,0.06765508651733398,9744.0,9712.0,14.829555981114959,1.0032948929159802,0.9967159277504105 diff --git a/benchmarks/scripts/__init__.py b/benchmarks/scripts/__init__.py index d43d3c7b..5c74aa01 100644 --- a/benchmarks/scripts/__init__.py +++ b/benchmarks/scripts/__init__.py @@ -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 \ No newline at end of file diff --git a/benchmarks/scripts/common.py b/benchmarks/scripts/common.py index 637b6067..afa37809 100644 --- a/benchmarks/scripts/common.py +++ b/benchmarks/scripts/common.py @@ -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 @@ -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 @@ -188,6 +188,7 @@ 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: @@ -195,3 +196,143 @@ def get_qasm_files(): 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. + #TODO: Add margin parameter to adjust the bounding box size. Can be an issue when comparing dates which are strings + 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=0, # Shrink arrow length to avoid overlap + shrinkB=5 + ), + bbox=dict( + boxstyle="round,pad=0.2", + edgecolor=color, + facecolor="white", + alpha=0.25 + ) + ) + + # Force a renderer update to ensure bounding box accuracy + ax.figure.canvas.draw() + renderer = ax.figure.canvas.get_renderer() + + # Get the bounding box of the annotation in data coordinates + bbox = annotation.get_tightbbox(renderer).transformed(ax.transData.inverted()) + # print(f"Initial annotation: '{text}' at {xy}, bbox: {bbox}", '\n') + + attempts = 0 + current_offset = offset[1] + # Adjust position to avoid overlap + while any(bbox.overlaps(prev_bbox) for prev_bbox in previous_bboxes): + for prev_bbox in previous_bboxes: + if bbox.overlaps(prev_bbox): + # print(f"\nOverlapping with previous annotation:\n" + # f" Previous bbox: {prev_bbox}\n" + # f" Annotation text: '{annotation.get_text()}'\n") + break + # Increase vertical offset to move annotation upward + current_offset += increment + annotation.set_position((offset[0], current_offset)) + + # Force the renderer to update after position adjustment + ax.figure.canvas.draw() + bbox = annotation.get_tightbbox(renderer).transformed(ax.transData.inverted()) + + # Update the plot to show the new position + ax.figure.canvas.flush_events() + # 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) + + + +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) diff --git a/benchmarks/scripts/plot_avg_benchmarks_over_time.py b/benchmarks/scripts/plot_avg_benchmarks_over_time.py index 1ee41900..84022f66 100644 --- a/benchmarks/scripts/plot_avg_benchmarks_over_time.py +++ b/benchmarks/scripts/plot_avg_benchmarks_over_time.py @@ -1,52 +1,59 @@ +from common import annotate_and_adjust, adjust_axes_to_fit_labels + import glob import pandas as pd import matplotlib.pyplot as plt import os +import re + +### Load data # Get the directory of the current script directory_of_this_file = os.path.dirname(os.path.abspath(__file__)) - -# Construct the correct path to the results folder results_folder = os.path.join(directory_of_this_file, "../results") - -# Use glob to find all CSV files in the results folder csv_files = glob.glob(os.path.join(results_folder, "gates*.csv")) dataframes = [] -print("Loading data files...", ) -# Loop through each CSV file and read it into a DataFrame +def extract_compiler_versions(header): + pattern = r"(\w+)=([\d\.]+)" + return dict(re.findall(pattern, header)) + +print("Loading data files...") for file in csv_files: - print(file) - # Note, this will combine results from the same date + with open(file, 'r') as f: + header_line = f.readline().strip() + compiler_versions = extract_compiler_versions(header_line) date_label = str(file).split('_')[1].split('.')[0] - df = pd.read_csv(file, header=1) # Load the CSV file into a DataFrame + df = pd.read_csv(file, header=1) df['date'] = date_label - df['reduction_factor'] = df['raw_multiq_gates'] / df['compiled_multiq_gates'] - df['gate_reduction_per_s'] = df['reduction_factor'] / df['compile_time'] df['compiled_ratio'] = df['compiled_multiq_gates'] / df['raw_multiq_gates'] - - dataframes.append(df) # Append the DataFrame to the list + df['compiler_version'] = df['compiler'].map(compiler_versions) + + dataframes.append(df) -# Concatenate all DataFrames into a single DataFrame df_dates = pd.concat(dataframes, ignore_index=True) -# Calculate averages for plotting -avg_compiled_ratio = df_dates.groupby(["compiler", "date"])["compiled_ratio"].mean().reset_index().sort_values("date") -avg_compile_time = df_dates.groupby(["compiler", "date"])["compile_time"].mean().reset_index().sort_values("date") +# Find the average compiled ratio for each compiler on each date +avg_compiled_ratio = df_dates.groupby(["compiler", "date", "compiler_version"])["compiled_ratio"].mean().reset_index().sort_values("date") -# Set global DPI -plt.rcParams['figure.dpi'] = 150 # Adjust DPI as needed +# Find the average compile time for each compiler on each date +avg_compile_time = df_dates.groupby(["compiler", "date", "compiler_version"])["compile_time"].mean().reset_index().sort_values("date") -# Create a colormap for unique compilers + +###### Plotting +# Ensure colors are consistently assigned to each compiler unique_compilers = sorted(df_dates["compiler"].unique()) colormap = plt.get_cmap("tab10", len(unique_compilers)) color_map = {compiler: colormap(i) for i, compiler in enumerate(unique_compilers)} -# Create subplots -fig, ax = plt.subplots(2, 1, figsize=(8, 8), sharex=True) +fig, ax = plt.subplots(2, 1, figsize=(8, 8), sharex=False, dpi=150) +# Rotate x labels on axes 0 +plt.setp(ax[0].xaxis.get_majorticklabels(), rotation=45) + -# Plot avg_compiled_ratio +#### Plot Compiled ratio +print("Plotting compiled ratio...") for compiler in unique_compilers: compiler_data = avg_compiled_ratio[avg_compiled_ratio["compiler"] == compiler] ax[0].plot( @@ -57,11 +64,63 @@ linestyle="-", color=color_map[compiler] ) + +# Keep track of last compiler version seen over time to track version changes +last_version_seen = {compiler: None for compiler in unique_compilers} + +previous_bboxes = [] +# Now iterate over each compiler entry and annotate if it's a new version, if so label it +for date in avg_compiled_ratio["date"].unique(): + date_data = avg_compiled_ratio[avg_compiled_ratio["date"] == date] + # Sort date_data in order of compiled_ratio + date_data = date_data.sort_values("compiled_ratio") + # print('Date data for \n', date, date_data, '\n') + # Now iterate over each compiler entry and annotate if it's a new version + for _, row in date_data.iterrows(): + # Get the version for this date + current_version = row["compiler_version"] + compiler = row["compiler"] + compiled_ratio = row["compiled_ratio"] + + # Check if the version has changed + if current_version != last_version_seen[compiler]: + text = f"{compiler}={current_version}" + xy = (row["date"], compiled_ratio) + color = color_map[compiler] + + # Add the annotation and adjust for overlap + annotate_and_adjust( + ax=ax[0], + text=text, + xy=xy, + color=color, + previous_bboxes=previous_bboxes, + offset=(0, 15), # Initial offset + increment=2, # Vertical adjustment step + max_attempts=10, + ) + plt.pause(0.1) + # Update the last seen version for this compiler + last_version_seen[compiler] = current_version + previous_bboxes = [] # Reset previous bboxes for next date +adjust_axes_to_fit_labels(ax[0], x_scale=1.01, y_scale=1.05) +# Set y axis range to be slightly larger than data range + ax[0].set_title("Average Compiled Ratio over Time") ax[0].set_ylabel("Compiled Ratio") -ax[0].legend(title="Compiler") +# ax[0].legend(title="Compiler", loc='center left') +# Expand axes to be slightly larger than data range +ax[0].legend(title="Compiler", loc="center right") + + +#### Plot Compile time +# Get runtime data only after we created GitHub Actions pipeline for standardization +avg_compile_time = avg_compile_time[avg_compile_time["date"] >= "2024-12-16"] -# Plot avg_compile_time +previous_annotations = [] +last_version_seen = {compiler: None for compiler in unique_compilers} + +print("Plotting compile time...") for compiler in unique_compilers: compiler_data = avg_compile_time[avg_compile_time["compiler"] == compiler] ax[1].plot( @@ -72,18 +131,49 @@ linestyle="-", color=color_map[compiler] ) + +# Add annotations for version changes +for date in avg_compile_time["date"].unique(): + date_data = avg_compile_time[avg_compile_time["date"] == date] + # Sort date_data in order of compiled_ratio + date_data = date_data.sort_values("compile_time") + for _, row in date_data.iterrows(): + # print(row, '\n') + # Get the version for this date + current_version = row["compiler_version"] + compiler = row["compiler"] + compile_time = row["compile_time"] + + # Check if the version has changed + if current_version != last_version_seen[compiler]: + text = f"{compiler}={current_version}" + xy = (row["date"], compile_time) + color = color_map[compiler] + + # Add the annotation and adjust for overlap + annotate_and_adjust( + ax=ax[1], + text=text, + xy=xy, + color=color, + previous_bboxes=previous_bboxes, + offset=(0, 25), # Initial offset + increment=2, # Vertical adjustment step + max_attempts=10, + ) + # plt.pause(0.1) + # Update the last seen version for this compiler + last_version_seen[compiler] = current_version + ax[1].set_title("Average Compile Time over Time") -ax[1].set_ylabel("Compile Time") +ax[1].set_ylabel("Compile Time (s)") ax[1].set_xlabel("Date") ax[1].set_yscale("log") +ax[1].legend(title="Compiler", loc="center right") +adjust_axes_to_fit_labels(ax[1], x_scale=1.01, y_scale=1.75, y_log=True) plt.xticks(rotation=45) - -# Adjust layout and save the figure plt.tight_layout() filename = os.path.join(directory_of_this_file, "../avg_compiler_benchmarks_over_time.png") -print(f"\n Saving plot to {filename}") +print(f"\nSaving plot to {filename}") fig.savefig(filename) - -# Show the plot (optional) -# plt.show() diff --git a/setup.py b/setup.py index cf8d9217..f7366c90 100644 --- a/setup.py +++ b/setup.py @@ -16,8 +16,8 @@ setup( name="ucc", version=__version__, - author="Jordan Sullivan", - author_email="jordan@unitary.fund", + author="Jordan Sullivan, Misty Wahl, Nate Stemen", + author_email="jordan@unitary.foundation", description="Unitary Compiler Collection: A quantum circuit interface and compiler for multiple quantum frameworks", long_description=long_description, long_description_content_type="text/markdown", diff --git a/ucc/_version.py b/ucc/_version.py index 7fd229a3..abeeedbf 100644 --- a/ucc/_version.py +++ b/ucc/_version.py @@ -1 +1 @@ -__version__ = '0.2.0' +__version__ = '0.4.0'