Skip to content

Commit

Permalink
test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nealerickson-qtm committed Oct 11, 2023
1 parent 90565f1 commit 7dc92df
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ repos:
additional_dependencies: [
pytest,
pytket==1.20.1,
pytket-quantinuum==0.23.0,
types-setuptools,
]
Empty file.
18 changes: 18 additions & 0 deletions pytket/phir/rebasing/rebaser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pytket.circuit import Circuit
from pytket.extensions.quantinuum.backends.api_wrappers import QuantinuumAPIOffline
from pytket.extensions.quantinuum.backends.quantinuum import (
QuantinuumBackend,
)


def rebase_to_qtm_machine(circuit: Circuit, qtm_machine: str) -> Circuit:
"""Rebases a circuit's gate to the gate set appropriate for the given machine."""
qapi_offline = QuantinuumAPIOffline()
backend = QuantinuumBackend(
device_name=qtm_machine,
machine_debug=False,
api_handler=qapi_offline, # type: ignore [arg-type]
)
# Optimization level 0 includes rebasing and little else
# see: https://cqcl.github.io/pytket-quantinuum/api/#default-compilation
return backend.get_compiled_circuit(circuit, 0)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pre-commit==3.4.0
pytest==7.4.2
ruff==0.0.292
pytket==1.20.1
pytket-quantinuum==0.23.0
wheel==0.41.2
23 changes: 23 additions & 0 deletions tests/test_rebaser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pytket.circuit import Circuit, OpType
from pytket.phir.rebasing.rebaser import rebase_to_qtm_machine

from .sample_data import QasmFiles, get_qasm_as_circuit

EXPECTED_GATES = [
OpType.Measure,
OpType.Rz,
OpType.PhasedX,
OpType.ZZPhase,
]


class TestRebaser:
def test_rebaser_happy_path_arc1a(self) -> None:
circ = get_qasm_as_circuit(QasmFiles.baby)
rebased: Circuit = rebase_to_qtm_machine(circ, "H1-1")

print(rebased)
for command in rebased.get_commands():
print(command)
if command.op.is_gate():
assert command.op.type in EXPECTED_GATES

0 comments on commit 7dc92df

Please sign in to comment.