Skip to content

Commit

Permalink
merge in new shell script changes (#104)
Browse files Browse the repository at this point in the history
* Move and expand test for logical equivalence

Test moved to test_compile.py

* Delete test_circuit_equivalence.py

Test moved to test_compile.py

* Remove unnecessary qubit parameterizations

Remove unnecessary qubit parameterizations in `test_compiled_circuits_equivalent` and `test_compilation_retains_gateset`

* add basic expectation value benchmark (#96)

* add basic expectation value benchmark

* move compile function to `common.py`

* write data out to json

* make data pipeline more functional

* simplify real check

* Add bug label to new bug report issues

* Add feature tag to feature template issues

* 97 reorg files (#98)

* add basic expectation value benchmark

* move compile function to `common.py`

* write data out to json

* make data pipeline more functional

* simplify real check

* Update naming convention for different benchmarks

* Dry up save results into common function

* Fix init import issue

* Move gate_counters into scripts/common.py for simplicity

* Fix notebook errors, remove old data

* Remove duplicate funciton definitions

* Remove duplicate lines

* Add folder to docstring, call out alterntive benchmark name

---------

Co-authored-by: nate stemen <nate@unitary.fund>

---------

Co-authored-by: Misty-W <82074193+Misty-W@users.noreply.github.com>
Co-authored-by: nate stemen <nate@unitary.fund>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent b88e071 commit 67f7b89
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
labels: 'bug'
assignees: ''

---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
labels: 'feature'
assignees: ''

---
Expand Down
1 change: 1 addition & 0 deletions benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .write_qasm import write_qasm
from .scripts import qasm_files, log_performance, save_results
33 changes: 20 additions & 13 deletions benchmarks/load_ucc_benchmarks.ipynb

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions benchmarks/results/expval_2024-11-27_12-41-04.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
compiler,expval,absoluate_error,relative_error,ideal
uncompiled,4.553649124439119e-18,1.0605990171102696e-16,0.9588328094519584,1.1061355083546608e-16
ucc,-8.890457814381136e-18,1.1950400864984722e-16,1.0803740386890337,1.1061355083546608e-16
cirq,2.0143392162608187e-15,1.9037256654253525e-15,17.21060079028726,1.1061355083546608e-16
qiskit,-2.3852447794681098e-18,1.129987956149342e-16,1.0215637664775457,1.1061355083546608e-16
pytket,-3.469446951953614e-18,1.140829977874197e-16,1.0313654785127937,1.1061355083546608e-16
196 changes: 20 additions & 176 deletions benchmarks/run_ucc_benchmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -74,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -129,7 +129,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -164,7 +164,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -188,7 +188,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -218,7 +218,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -234,166 +234,9 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"./circuits/qasm2/benchpress/qaoa_barabasi_albert_N100_3reps_basis_rz_rx_ry_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 1176\n",
"compile_time: 0.17149901390075684\n",
"compiled_multiq_gates: 1176\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 1176\n",
"compile_time: 0.008548974990844727\n",
"compiled_multiq_gates: 1176\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 1176\n",
"compile_time: 0.2241971492767334\n",
"compiled_multiq_gates: 1176\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 1176\n",
"compile_time: 1.997459888458252\n",
"compiled_multiq_gates: 1176\n",
"\n",
"\n",
"./circuits/qasm2/benchpress/qv_N100_12345_basis_rz_rx_ry_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 15000\n",
"compile_time: 3.832437753677368\n",
"compiled_multiq_gates: 14856\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 15000\n",
"compile_time: 1.8110430240631104\n",
"compiled_multiq_gates: 15000\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 15000\n",
"compile_time: 14.523398876190186\n",
"compiled_multiq_gates: 14856\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 15000\n",
"compile_time: 80.02735781669617\n",
"compiled_multiq_gates: 14856\n",
"\n",
"\n",
"./circuits/qasm2/benchpress/qft_N100_basis_rz_rx_ry_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 10050\n",
"compile_time: 1.4312050342559814\n",
"compiled_multiq_gates: 2740\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 10050\n",
"compile_time: 0.060137033462524414\n",
"compiled_multiq_gates: 5890\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 10050\n",
"compile_time: 12.443096160888672\n",
"compiled_multiq_gates: 3244\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 10050\n",
"compile_time: 11.917328834533691\n",
"compiled_multiq_gates: 4648\n",
"\n",
"\n",
"./circuits/qasm2/benchpress/square_heisenberg_N100_basis_rz_rx_ry_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 2160\n",
"compile_time: 0.1506800651550293\n",
"compiled_multiq_gates: 540\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 2160\n",
"compile_time: 0.03105902671813965\n",
"compiled_multiq_gates: 2160\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 2160\n",
"compile_time: 0.27074503898620605\n",
"compiled_multiq_gates: 540\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 2160\n",
"compile_time: 2.410604238510132\n",
"compiled_multiq_gates: 540\n",
"\n",
"\n",
"./circuits/qasm2/ucc/prep_select_N25_ghz_basis_rz_rx_ry_h_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 9744\n",
"compile_time: 1.677304983139038\n",
"compiled_multiq_gates: 9702\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 9744\n",
"compile_time: 0.06841206550598145\n",
"compiled_multiq_gates: 9712\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 9744\n",
"compile_time: 2.6884899139404297\n",
"compiled_multiq_gates: 9708\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 9744\n",
"compile_time: 29.770545721054077\n",
"compiled_multiq_gates: 9712\n",
"\n",
"\n",
"./circuits/qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm\n",
"compiler: ucc\n",
"raw_multiq_gates: 388\n",
"compile_time: 0.05575394630432129\n",
"compiled_multiq_gates: 388\n",
"\n",
"\n",
"compiler: pytket\n",
"raw_multiq_gates: 388\n",
"compile_time: 0.007879018783569336\n",
"compiled_multiq_gates: 388\n",
"\n",
"\n",
"compiler: qiskit\n",
"raw_multiq_gates: 388\n",
"compile_time: 0.08799529075622559\n",
"compiled_multiq_gates: 388\n",
"\n",
"\n",
"compiler: cirq\n",
"raw_multiq_gates: 388\n",
"compile_time: 0.8741302490234375\n",
"compiled_multiq_gates: 388\n",
"\n",
"\n"
]
}
],
"outputs": [],
"source": [
"compiler_specs = [\n",
" ('ucc', ucc_compile), \n",
Expand Down Expand Up @@ -427,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -457,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -475,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -485,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -568,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -618,7 +461,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -717,7 +560,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -811,7 +654,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -828,6 +671,7 @@
],
"source": [
"# Create a new DataFrame with gate reduction data\n",
"avg_gate_reduction = df.groupby(\"compiler\")[\"reduction_factor\"].mean()\n",
"factor_df = pd.DataFrame(avg_gate_reduction).reset_index()\n",
"\n",
"# Get the UCC gate reduction\n",
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .gate_counters import count_multi_qubit_gates_cirq, count_multi_qubit_gates_pytket, count_multi_qubit_gates_qiskit
from .common import count_multi_qubit_gates_cirq, count_multi_qubit_gates_pytket, count_multi_qubit_gates_qiskit
from .common import log_performance, qasm_files, save_results
18 changes: 4 additions & 14 deletions benchmarks/scripts/cirq_compile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
# cirq_compile.py

from common import qasm_files, log_performance
from cirq.transformers import optimize_for_target_gateset, CZTargetGateset
from common import qasm_files, log_performance, cirq_compile, save_results
from qbraid.transpiler import transpile as translate

def cirq_compile(cirq_circuit):
return optimize_for_target_gateset(cirq_circuit, gateset=CZTargetGateset())

results_log = []

for filename in qasm_files:
with open(filename, "r") as file:
print(f"Compiling {filename} with Cirq")
qasm_string = file.read()
native_circuit = translate(qasm_string, 'cirq')
native_circuit = translate(qasm_string, "cirq")
log_entry = log_performance(cirq_compile, native_circuit, "cirq")
log_entry['circuit_name'] = filename.split('/')[-1].split('_N')[0]
log_entry["circuit_name"] = filename.split("/")[-1].split("_N")[0]
results_log.append(log_entry)

# Save results
import pandas as pd
from datetime import datetime
df = pd.DataFrame(results_log)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
df.to_csv(f"../results/cirq-results_{timestamp}.csv", index=False)
save_results(results_log, "gates")
Loading

0 comments on commit 67f7b89

Please sign in to comment.