Skip to content

Commit

Permalink
Switched from pytket method flag to separate functions for peephole (…
Browse files Browse the repository at this point in the history
…and next kak)
  • Loading branch information
jordandsullivan committed Feb 27, 2025
1 parent 30c9691 commit 78e4d27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
28 changes: 11 additions & 17 deletions benchmarks/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
SequencePass,
AutoRebase,
FullPeepholeOptimise,
KAKDecomposition,
)
from pytket.predicates import CompilationUnit
import qiskit
Expand Down Expand Up @@ -60,8 +59,8 @@ def get_compile_function(compiler_alias):
match compiler_alias:
case "ucc":
return ucc_compile
case "pytket":
return pytket_compile
case "pytket-peep":
return pytket_peep_compile
case "qiskit":
return qiskit_compile
case "cirq":
Expand All @@ -79,26 +78,21 @@ def get_native_rep(qasm_string, compiler_alias):
if compiler_alias == "ucc":
# Qiskit used for UCC to get raw gate counts
native_circuit = translate(qasm_string, "qiskit")
if compiler_alias == "pytket-peep":
native_circuit = translate(qasm_string, "pytket")
else:
native_circuit = translate(qasm_string, compiler_alias)

return native_circuit


# PyTkets compilation
def pytket_compile(pytket_circuit, method="peephole"):
# Uses FullPeepholeOptimise
def pytket_peep_compile(pytket_circuit):
compilation_unit = CompilationUnit(pytket_circuit)
if method == "peephole":
passes = [FullPeepholeOptimise()]
elif method == "kak":
passes = [KAKDecomposition()]
else:
raise ValueError("Invalid compilation method for PyTKET.")

passes.append(
AutoRebase({OpType.Rx, OpType.Ry, OpType.Rz, OpType.CX, OpType.H})
)

passes = [
FullPeepholeOptimise(),
AutoRebase({OpType.Rx, OpType.Ry, OpType.Rz, OpType.CX, OpType.H}),
]
SequencePass(passes).apply(compilation_unit)
return compilation_unit.circuit

Expand Down Expand Up @@ -289,7 +283,7 @@ def count_multi_qubit_gates(circuit, compiler_alias):
return count_multi_qubit_gates_qiskit(circuit)
case "cirq":
return count_multi_qubit_gates_cirq(circuit)
case "pytket":
case "pytket-peep":
return count_multi_qubit_gates_pytket(circuit)
case _:
return "Unknown compiler alias."
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/scripts/run_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ QASM_FILES=(
)

# Define your list of compilers
COMPILERS=("ucc" "qiskit" "pytket" "cirq")
COMPILERS=("ucc" "qiskit" "pytket-peep" "pytket-kak" "cirq")

# Default parallelism 4 (can be overridden by a command line argument)
PARALLELISM="${1:-4}"
Expand All @@ -38,7 +38,7 @@ for qasm_file in "${QASM_FILES[@]}"; do
for compiler in "${COMPILERS[@]}"; do
# Combine the common folder path with the QASM file
full_qasm_file="${QASM_FOLDER}${qasm_file}"

# Build the command, passing the results folder as an argument
command="python3 $(dirname "$0")/benchmark_script.py \"$full_qasm_file\" \"$compiler\" \"$RESULTS_FOLDER\""

Expand All @@ -59,7 +59,7 @@ for qasm_file in "${QASM_EXPVAL_FILES[@]}"; do
for compiler in "${COMPILERS[@]}"; do
# Combine the common folder path with the QASM file
full_qasm_file="${QASM_FOLDER}${qasm_file}"

# Build the command, passing the results folder as an argument
command="poetry run python $(dirname "$0")/expval_benchmark.py \"$full_qasm_file\" \"$compiler\" \"$RESULTS_FOLDER\" $LOG_EXPVAL"

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/scripts/small_test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
QASM_FILE="qasm2/ucc/qcnn_N100_7layers_basis_rz_rx_ry_h_cx.qasm"
COMPILER="ucc"
COMPILER="pytket-peep"

SCRIPT_DIR=$(dirname "$(realpath "$0")")
RESULTS_FOLDER="$SCRIPT_DIR/../results/test_data"
Expand All @@ -9,4 +9,4 @@ full_qasm_file="$QASM_FOLDER/$QASM_FILE"

command="python3 \"$SCRIPT_DIR/benchmark_script.py\" \"$full_qasm_file\" \"$COMPILER\" \"$RESULTS_FOLDER\""

eval $command
eval $command

0 comments on commit 78e4d27

Please sign in to comment.