Pytket to QIR¶
pytket-qir is an client-side extension (plugin) for pytket, the quantum circuit toolkit & compiler framework by Quantinuum. Its purpose is to provide functionality for 1-way conversion of pytket circuits into the QIR (Quantum Intermediate Representation) format. It allows users of pytket to target QIR-compliant hardware providers or off-the-shelf simulation tool.
pytket-qir is cross-platform on Windows, Linux and macOS. It is compatible with Python 3.10 - 3.13, and available on PyPi. An API reference is available at https://docs.quantinuum.com/tket/extensions/pytket-qir/. The package is opensource (Apache 2.0), available at https://github.com/quantinuum/pytket-qir.git, and downloadable via PyPI.
pip install pytket-qir
Basic Usage¶
from pytket.circuit import Circuit, Qubit
from pytket.circuit.clexpr import wired_clexpr_from_logic_exp
circ = Circuit(3)
a = circ.add_c_register("a", 5)
b = circ.add_c_register("b", 5)
c = circ.add_c_register("c", 5)
d = circ.add_c_register("d", 5)
circ.H(0)
circ.add_clexpr(*wired_clexpr_from_logic_exp(a | b, c)) # type: ignore
circ.add_clexpr(*wired_clexpr_from_logic_exp(c | b, d)) # type: ignore
circ.add_clexpr(*wired_clexpr_from_logic_exp(c | b, d), condition=a[4]) # type: ignore
circ.H(0)
circ.Measure(Qubit(0), d[4])
circ.H(1)
circ.Measure(Qubit(1), d[3])
circ.H(2)
circ.Measure(Qubit(2), d[2])
from pytket.qir.conversion.api import QIRFormat, QIRProfile, pytket_to_qir
gen_qir_ll = pytket_to_qir(
circ,
name="conditional",
qir_format=QIRFormat.STRING,
profile=QIRProfile.ADAPTIVE,
cut_pytket_register=True,
)
print(gen_qir_ll)
Use Cases¶
Wasm Callouts¶
from pytket import wasm
from pytket.circuit import Bit, Circuit, Qubit
from pytket.wasm import WasmFileHandler
w = WasmFileHandler("testfile.wasm")
c = Circuit(6, 6)
c0 = c.add_c_register("c0", 3)
c1 = c.add_c_register("c1", 4)
c2 = c.add_c_register("c2", 5)
c.add_wasm_to_reg("multi", w, [c0, c1], [c2])
c.add_wasm_to_reg("add_one", w, [c2], [c2])
c.add_wasm_to_reg("no_return", w, [c2], [])
c.add_wasm_to_reg("init", w, [], [])
c.add_wasm_to_reg("no_parameters", w, [], [c2])
from pytket.qir.conversion.api import QIRFormat, QIRProfile, pytket_to_qir
profile = QIRProfile.ADAPTIVE
result = pytket_to_qir(
c,
name=f"pytket_qir_wasm_2-{profile}",
qir_format=QIRFormat.STRING,
int_type=32,
profile=profile,
)
RNG Callouts¶
circ = Circuit()
creg = circ.add_c_register("c", 64)
circ.add_c_setbits([True, True], [creg[3], creg[11]])
circ.set_rng_seed(creg)
from pytket.qir.conversion.api import QIRFormat, QIRProfile, pytket_to_qir
profile = QIRProfile.ADAPTIVE
result = pytket_to_qir(
circ,
name=f"pytket_rng_wasm-{profile}",
qir_format=QIRFormat.STRING,
int_type=64,
profile=profile,
cut_pytket_register=True
)