diff --git a/benchmarks/__init__.py b/benchmarks/__init__.py index 1ca2b7f8..93b87c6b 100644 --- a/benchmarks/__init__.py +++ b/benchmarks/__init__.py @@ -1,2 +1 @@ -from .write_qasm import write_qasm from .scripts import log_performance, save_results \ No newline at end of file diff --git a/benchmarks/circuits/__init__.py b/benchmarks/circuits/__init__.py deleted file mode 100644 index f8137fb5..00000000 --- a/benchmarks/circuits/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .cirq import cirq_prep_select -from .qiskit.circuits import qcnn_circuit, random_clifford_circuit, bv_all_ones diff --git a/benchmarks/generate_qasm.ipynb b/benchmarks/generate_qasm.ipynb deleted file mode 100644 index 3144f064..00000000 --- a/benchmarks/generate_qasm.ipynb +++ /dev/null @@ -1,141 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prepare & Select\n", - "Prepare an N-qubit GHZ state and select the all ones state." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from circuits.cirq import cirq_prep_select \n", - "from write_qasm import write_qasm\n", - "\n", - "num_qubits = 25\n", - "target_state=\"1\" * num_qubits\n", - "\n", - "circuit = cirq_prep_select(num_qubits, target_state=target_state)\n", - "filename = f\"prep_select_N{num_qubits}_ghz\"\n", - "\n", - "write_qasm(circuit, \n", - "circuit_name=filename, \n", - "# basis_gates=['rz', 'rx', 'ry', 'h', 'cx']\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### QCNN\n", - "N-qubit Quantum convolutional neural network " - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from circuits.qiskit import qcnn_circuit\n", - "from numpy import log2, ceil\n", - "\n", - "num_qubits = 100\n", - "num_layers = int(ceil(log2(num_qubits)))\n", - "\n", - "seed = 12345\n", - "\n", - "circuit = qcnn_circuit(num_qubits, seed=seed)\n", - "filename = f\"qcnn_N{num_qubits}_{num_layers}layers\"\n", - "\n", - "write_qasm(circuit, \n", - "circuit_name=filename, \n", - "basis_gates=['rz', 'rx', 'ry', 'h', 'cx'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Parameterized VQE ansatz\n" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "from circuits.qiskit import VQE_ansatz\n", - "\n", - "num_qubits = 50\n", - "num_layers = num_qubits * 2\n", - "\n", - "circuit = VQE_ansatz(num_qubits, num_layers)\n", - "filename = f\"VQE_ansatz_N{num_qubits}_{num_layers}layers\"\n", - "\n", - "write_qasm(circuit, circuit_name=filename, version='3')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### QAOA neighest neighbors Ising model" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "from circuits.qiskit import qaoa_ising_ansatz\n", - "from write_qasm import write_qasm\n", - "\n", - "num_qubits = 50\n", - "num_layers = num_qubits * 3\n", - "\n", - "circuit = qaoa_ising_ansatz(num_qubits, num_layers)\n", - "filename = f\"QAOA_Ising_ansatz_N{num_qubits}_{num_layers}layers\"\n", - "\n", - "write_qasm(circuit, circuit_name=filename, version='3')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "bench", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/benchmarks/circuits/qasm2/benchpress/qaoa_barabasi_albert_N100_3reps_basis_rz_rx_ry_cx.qasm b/benchmarks/qasm_circuits/qasm2/benchpress/qaoa_barabasi_albert_N100_3reps_basis_rz_rx_ry_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/benchpress/qaoa_barabasi_albert_N100_3reps_basis_rz_rx_ry_cx.qasm rename to benchmarks/qasm_circuits/qasm2/benchpress/qaoa_barabasi_albert_N100_3reps_basis_rz_rx_ry_cx.qasm diff --git a/benchmarks/circuits/qasm2/benchpress/qft_N100_basis_rz_rx_ry_cx.qasm b/benchmarks/qasm_circuits/qasm2/benchpress/qft_N100_basis_rz_rx_ry_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/benchpress/qft_N100_basis_rz_rx_ry_cx.qasm rename to benchmarks/qasm_circuits/qasm2/benchpress/qft_N100_basis_rz_rx_ry_cx.qasm diff --git a/benchmarks/circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm b/benchmarks/qasm_circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm rename to benchmarks/qasm_circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm diff --git a/benchmarks/circuits/qasm2/benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm b/benchmarks/qasm_circuits/qasm2/benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm rename to benchmarks/qasm_circuits/qasm2/benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm diff --git a/benchmarks/circuits/qasm2/ucc/prep_select_N10_ghz.qasm b/benchmarks/qasm_circuits/qasm2/ucc/prep_select_N10_ghz.qasm similarity index 100% rename from benchmarks/circuits/qasm2/ucc/prep_select_N10_ghz.qasm rename to benchmarks/qasm_circuits/qasm2/ucc/prep_select_N10_ghz.qasm diff --git a/benchmarks/circuits/qasm2/ucc/prep_select_N25_ghz.qasm b/benchmarks/qasm_circuits/qasm2/ucc/prep_select_N25_ghz.qasm similarity index 100% rename from benchmarks/circuits/qasm2/ucc/prep_select_N25_ghz.qasm rename to benchmarks/qasm_circuits/qasm2/ucc/prep_select_N25_ghz.qasm diff --git a/benchmarks/circuits/qasm2/ucc/prep_select_N25_ghz_basis_rz_rx_ry_h_cx.qasm b/benchmarks/qasm_circuits/qasm2/ucc/prep_select_N25_ghz_basis_rz_rx_ry_h_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/ucc/prep_select_N25_ghz_basis_rz_rx_ry_h_cx.qasm rename to benchmarks/qasm_circuits/qasm2/ucc/prep_select_N25_ghz_basis_rz_rx_ry_h_cx.qasm diff --git a/benchmarks/circuits/qasm2/ucc/qcnn_N100_7layers.qasm b/benchmarks/qasm_circuits/qasm2/ucc/qcnn_N100_7layers.qasm similarity index 100% rename from benchmarks/circuits/qasm2/ucc/qcnn_N100_7layers.qasm rename to benchmarks/qasm_circuits/qasm2/ucc/qcnn_N100_7layers.qasm diff --git a/benchmarks/circuits/qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm b/benchmarks/qasm_circuits/qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm similarity index 100% rename from benchmarks/circuits/qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm rename to benchmarks/qasm_circuits/qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm diff --git a/benchmarks/circuits/qasm3/ucc/QAOA_Ising_ansatz_N50_150layers.qasm b/benchmarks/qasm_circuits/qasm3/ucc/QAOA_Ising_ansatz_N50_150layers.qasm similarity index 100% rename from benchmarks/circuits/qasm3/ucc/QAOA_Ising_ansatz_N50_150layers.qasm rename to benchmarks/qasm_circuits/qasm3/ucc/QAOA_Ising_ansatz_N50_150layers.qasm diff --git a/benchmarks/circuits/qasm3/ucc/VQE_ansatz_N50_25layers.qasm b/benchmarks/qasm_circuits/qasm3/ucc/VQE_ansatz_N50_25layers.qasm similarity index 100% rename from benchmarks/circuits/qasm3/ucc/VQE_ansatz_N50_25layers.qasm rename to benchmarks/qasm_circuits/qasm3/ucc/VQE_ansatz_N50_25layers.qasm diff --git a/benchmarks/scripts/__init__.py b/benchmarks/scripts/__init__.py index e1b90ede..03c4158a 100644 --- a/benchmarks/scripts/__init__.py +++ b/benchmarks/scripts/__init__.py @@ -1 +1,3 @@ -from .common import log_performance, save_results \ No newline at end of file +from .common import log_performance, save_results +from .qiskit_circuits import qaoa_ising_ansatz, qcnn_circuit, VQE_ansatz, random_clifford_circuit +from .cirq_circuits import cirq_prep_select \ No newline at end of file diff --git a/benchmarks/circuits/cirq/__init__.py b/benchmarks/scripts/cirq_circuits/__init__.py similarity index 100% rename from benchmarks/circuits/cirq/__init__.py rename to benchmarks/scripts/cirq_circuits/__init__.py diff --git a/benchmarks/circuits/cirq/circuits.py b/benchmarks/scripts/cirq_circuits/circuits.py similarity index 100% rename from benchmarks/circuits/cirq/circuits.py rename to benchmarks/scripts/cirq_circuits/circuits.py diff --git a/benchmarks/scripts/generate_qasm.py b/benchmarks/scripts/generate_qasm.py new file mode 100644 index 00000000..57b14477 --- /dev/null +++ b/benchmarks/scripts/generate_qasm.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# coding: utf-8 + +# ### Prepare & Select +# Prepare an N-qubit GHZ state and select the all ones state. + +from write_qasm import write_qasm +from cirq_circuits import VQE_ansatz, cirq_prep_select +from qiskit_circuits import qcnn_circuit, qaoa_ising_ansatz +from numpy import log2, ceil + + +# ### Prepare & Select +num_qubits = 25 +target_state="1" * num_qubits + +circuit = cirq_prep_select(num_qubits, target_state=target_state) +filename = f"prep_select_N{num_qubits}_ghz" + +write_qasm(circuit, +circuit_name=filename, +# basis_gates=['rz', 'rx', 'ry', 'h', 'cx'] +) + +# ### QCNN circuit +num_qubits = 100 +num_layers = int(ceil(log2(num_qubits))) + +seed = 12345 + +circuit = qcnn_circuit(num_qubits, seed=seed) +filename = f"qcnn_N{num_qubits}_{num_layers}layers" + +write_qasm(circuit, +circuit_name=filename, +basis_gates=['rz', 'rx', 'ry', 'h', 'cx']) + +# ### Parameterized VQE ansatz +num_qubits = 50 +num_layers = num_qubits * 2 +num_layers = num_qubits * 2 + +circuit = VQE_ansatz(num_qubits, num_layers) +filename = f"VQE_ansatz_N{num_qubits}_{num_layers}layers" + +write_qasm(circuit, circuit_name=filename, version='3') + +# ### QAOA neighest neighbors Ising mode +num_qubits = 50 +num_layers = num_qubits * 3 + +circuit = qaoa_ising_ansatz(num_qubits, num_layers) +filename = f"QAOA_Ising_ansatz_N{num_qubits}_{num_layers}layers" + +write_qasm(circuit, circuit_name=filename, version='3') diff --git a/benchmarks/circuits/qiskit/__init__.py b/benchmarks/scripts/qiskit_circuits/__init__.py similarity index 71% rename from benchmarks/circuits/qiskit/__init__.py rename to benchmarks/scripts/qiskit_circuits/__init__.py index 6c434047..86b4fbb8 100644 --- a/benchmarks/circuits/qiskit/__init__.py +++ b/benchmarks/scripts/qiskit_circuits/__init__.py @@ -1 +1 @@ -from .circuits import qcnn_circuit, VQE_ansatz, qaoa_ising_ansatz \ No newline at end of file +from .circuits import qcnn_circuit, VQE_ansatz, qaoa_ising_ansatz, random_clifford_circuit \ No newline at end of file diff --git a/benchmarks/circuits/qiskit/circuits.py b/benchmarks/scripts/qiskit_circuits/circuits.py similarity index 100% rename from benchmarks/circuits/qiskit/circuits.py rename to benchmarks/scripts/qiskit_circuits/circuits.py diff --git a/benchmarks/scripts/run_benchmarks.sh b/benchmarks/scripts/run_benchmarks.sh index cdb284b2..0e679452 100755 --- a/benchmarks/scripts/run_benchmarks.sh +++ b/benchmarks/scripts/run_benchmarks.sh @@ -10,7 +10,7 @@ RESULTS_FOLDER="$SCRIPT_DIR/../results" mkdir -p "$RESULTS_FOLDER" # Define the common folder path -QASM_FOLDER="$SCRIPT_DIR/../circuits/qasm2/" +QASM_FOLDER="$SCRIPT_DIR/../qasm_circuits/qasm2/" # Define your list of QASM file names (without the common path) QASM_FILES=( diff --git a/benchmarks/scripts/small_test.sh b/benchmarks/scripts/small_test.sh index c94a80f4..0ca79e95 100755 --- a/benchmarks/scripts/small_test.sh +++ b/benchmarks/scripts/small_test.sh @@ -1,10 +1,10 @@ -QASM_FILE="benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm" +QASM_FILE="qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm" COMPILER="ucc" SCRIPT_DIR=$(dirname "$(realpath "$0")") RESULTS_FOLDER="$SCRIPT_DIR/../results/test_data" mkdir -p "$RESULTS_FOLDER" -QASM_FOLDER="$SCRIPT_DIR/../circuits/qasm2/" +QASM_FOLDER="$SCRIPT_DIR/../qasm_circuits/" full_qasm_file="$QASM_FOLDER/$QASM_FILE" command="python3 $SCRIPT_DIR/benchmark_script.py \"$full_qasm_file\" \"$COMPILER\" \"$RESULTS_FOLDER\"" diff --git a/benchmarks/write_qasm.py b/benchmarks/scripts/write_qasm.py similarity index 84% rename from benchmarks/write_qasm.py rename to benchmarks/scripts/write_qasm.py index 62347540..960cfbb8 100644 --- a/benchmarks/write_qasm.py +++ b/benchmarks/scripts/write_qasm.py @@ -1,9 +1,10 @@ from qbraid.transpiler import transpile as translate -from qbraid.programs.alias_manager import get_program_type_alias from qiskit import transpile as qiskit_transpile +from os.path import join -def write_qasm(circuit, circuit_name, version='2', basis_gates=[]): + +def write_qasm(circuit, circuit_name, version='2', basis_gates=[], folder="../qasm_circuits"): qiskit_circuit = translate(circuit, 'qiskit') if basis_gates: decomp_circuit = qiskit_transpile( @@ -17,7 +18,8 @@ def write_qasm(circuit, circuit_name, version='2', basis_gates=[]): qasm_string = translate(decomp_circuit, 'qasm' + version) # Write the string to a .qasm file - filename = f"./circuits/qasm{version}/ucc/{circuit_name}" + + filename = join(folder, f"/qasm{version}/ucc/{circuit_name}") if basis_gates: filename += f"_basis_{'_'.join(basis_gates)}" diff --git a/ucc/tests/test_compile.py b/ucc/tests/test_compile.py index aa28caa8..eb55d6d2 100644 --- a/ucc/tests/test_compile.py +++ b/ucc/tests/test_compile.py @@ -8,7 +8,7 @@ from qiskit.quantum_info import Statevector from qiskit.transpiler.passes import GatesInBasis -from benchmarks.circuits import qcnn_circuit, random_clifford_circuit +from benchmarks.scripts import qcnn_circuit, random_clifford_circuit from ucc import compile from ucc.transpilers.ucc_defaults import UCCDefault1