Skip to content

✨ Added clifford+t gateset #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ filterwarnings = [
'ignore:.*Values in x.*:RuntimeWarning:',
'ignore:.*divide by zero encountered in det.*:RuntimeWarning:',
'ignore:.*invalid value encountered in det.*:RuntimeWarning:',
'ignore:.*invalid value encountered in divide.*:RuntimeWarning:',
'ignore:.*The iteration is not making good progress.*:RuntimeWarning:',
# Qiskit 1.2 deprecations
'ignore:.*The class ``qiskit.qobj.pulse_qobj.Pulse.*`` is deprecated as of qiskit 1.2.*:DeprecationWarning:qiskit.*',
# Qiskit 1.3 deprecations
Expand All @@ -123,6 +125,7 @@ filterwarnings = [
'ignore:.*Providing non-standard gates.*is deprecated for both ``transpile`` and ``generate_preset_pass_manager`` as of Qiskit 1.3.0.*:DeprecationWarning:qiskit.*',
'ignore:.*is pending deprecation as of qiskit 1.3..*:PendingDeprecationWarning:',
'ignore:.*The class ``qiskit.providers.exceptions.BackendPropertyError`` is deprecated as of qiskit 1.4.*:DeprecationWarning:',
'ignore:.*he SolovayKitaev algorithm relies *.:RuntimeWarning:qiskit.synthesis.discrete_basis.generate_basis_approximations',
]

[tool.coverage]
Expand Down
26 changes: 25 additions & 1 deletion src/mqt/bench/benchmark_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,31 @@ def get_native_gates_level(
if file_precheck and path.is_file():
return True

compiled = transpile(qc, basis_gates=gateset.gates, optimization_level=opt_level, seed_transpiler=10)
if gateset.name == "clifford+t":
from qiskit.transpiler import PassManager # 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
pm = PassManager(SolovayKitaev())
new_qc = pm.run(compiled_for_sk.remove_final_measurements(inplace=False))
new_qc.measure_all()
# Transpile once more to remove unnecessary gates and optimize the circuit
compiled = transpile(
new_qc,
basis_gates=gateset.gates,
optimization_level=opt_level,
seed_transpiler=10,
)
else:
compiled = transpile(qc, basis_gates=gateset.gates, optimization_level=opt_level, seed_transpiler=10)

if return_qc:
return compiled
Expand Down
27 changes: 27 additions & 0 deletions src/mqt/bench/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ def get_available_native_gatesets() -> list[Gateset]:
for device in get_available_devices():
if device.gateset not in available_gatesets:
available_gatesets.append(device.gateset)
available_gatesets.append(
Gateset(
"clifford+t",
[
"i",
"x",
"y",
"z",
"h",
"s",
"sdg",
"t",
"tdg",
"sx",
"sxdg",
"cx",
"cy",
"cz",
"swap",
"iswap",
"dcx",
"ecr",
"measure",
"barrier",
],
)
)
return available_gatesets


Expand Down
15 changes: 14 additions & 1 deletion tests/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def sample_filenames() -> list[str]:
(vqesu2random, 3, True),
(vqetwolocalrandom, 3, True),
(wstate, 3, True),
# (shor, 3, False),
(shor, 3, False),
],
)
def test_quantumcircuit_alg_level(
Expand Down Expand Up @@ -568,6 +568,19 @@ def test_oqc_benchmarks() -> None:
path.unlink()


def test_clifford_t() -> None:
"""Test the Clifford+T gateset."""
qc = get_benchmark(
benchmark_name="qft",
level="nativegates",
circuit_size=4,
gateset="clifford+t",
)

for gate_type in qc.count_ops():
assert gate_type in get_native_gateset_by_name("clifford+t").gates


def test_get_module_for_benchmark() -> None:
"""Test the get_module_for_benchmark function."""
for benchmark in get_supported_benchmarks():
Expand Down
Loading