Skip to content

Commit

Permalink
♻️ improve implementation of Clifford+T compilation
Browse files Browse the repository at this point in the history
Signed-off-by: burgholzer <[email protected]>
  • Loading branch information
burgholzer committed Dec 2, 2024
1 parent f7296a9 commit e87b7e0
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/mqt/bench/qiskit_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from .devices import Device, Gateset

from qiskit import transpile
from qiskit.synthesis import generate_basic_approximations
from qiskit.transpiler.passes import SolovayKitaev

from .utils import get_openqasm_gates, save_as_qasm

Expand Down Expand Up @@ -191,12 +189,28 @@ def get_native_gates_level(
return True

if gateset.gateset_name == "clifford+t":
gateset_without_cx = gateset.gates.copy()
gateset_without_cx.remove("cx")
approx = generate_basic_approximations(gateset_without_cx, depth=3)
skd = SolovayKitaev(recursion_degree=2, basic_approximations=approx)
compiled_without_architecture = skd(qc.decompose(reps=3).remove_final_measurements(inplace=False))
compiled_without_architecture.measure_all()
from qiskit.converters import circuit_to_dag, dag_to_circuit # noqa: PLC0415
from qiskit.transpiler.passes.synthesis import SolovayKitaev # noqa: PLC0415

# Transpile the circuit to single- and two-qubit gates including rotations
compiled_for_sk = transpile(
qc,
basis_gates=[*gateset.gates, "rx", "ry", "rz"],
optimization_level=opt_level,
seed_transpiler=10,
)
# Synthesize the rotations to Clifford+T gates
# Measurements are removed and added back after the synthesis to avoid errors in the Solovay-Kitaev pass
pass_ = SolovayKitaev()
new_qc = dag_to_circuit(pass_.run(circuit_to_dag(compiled_for_sk.remove_final_measurements(inplace=False))))
new_qc.measure_all()
# Transpile once more to remove unnecessary gates and optimize the circuit
compiled_without_architecture = transpile(
new_qc,
basis_gates=gateset.gates,
optimization_level=opt_level,
seed_transpiler=10,
)
else:
compiled_without_architecture = transpile(
qc, basis_gates=gateset.gates, optimization_level=opt_level, seed_transpiler=10
Expand Down

0 comments on commit e87b7e0

Please sign in to comment.