Source code for guppyft.extensions.steane

"""Steane code extension."""

import functools

from hugr.ext import Extension, OpDef, TypeDef
from hugr.ops import ExtOp
from hugr.tys import ExtType

from ._util import load_extension


[docs] class SteaneTypesExtension: """Extension providing the Steane logical types."""
[docs] def __call__(self) -> Extension: """Returns the Steane types extension.""" return load_extension("guppyft.steane.types")
@functools.cached_property def steane_qubit_def(self) -> TypeDef: """A Steane logical qubit. This is the generic type definition. For the instantiated type, see `steane_qubit`. """ return self().get_type("qubit")
[docs] def steane_qubit(self) -> ExtType: """A Steane logical qubit.""" return self.steane_qubit_def.instantiate([])
@functools.cached_property def steane_measurement_def(self) -> TypeDef: """A Steane logical measurement type. This is the generic type definition. For the instantiated type, see `steane_measurement`. """ return self().get_type("measurement")
[docs] def steane_measurement(self) -> ExtType: """A Steane logical measurement.""" return self.steane_measurement_def.instantiate([])
[docs] class SteaneOpsExtension: """Extension providing the Steane logical operations."""
[docs] def __call__(self) -> Extension: """Returns the Steane ops extension.""" return load_extension("guppyft.steane.ops", ["guppyft.std.types"])
@functools.cached_property def prep_zero_def(self) -> OpDef: """Prepare a logical qubit in the all-zero state. This is the generic operation definition. For the instantiated operation, see `prep_zero`.""" return self().get_op("prep_zero")
[docs] def prep_zero(self) -> ExtOp: """Allocate a block in the all-zero state.""" return self.prep_zero_def.instantiate([])
@functools.cached_property def free_def(self) -> OpDef: """Free a logical qubit. This is the generic operation definition. For the instantiated operation, see `free`.""" return self().get_op("free")
[docs] def free(self) -> ExtOp: """Free a block.""" return self.free_def.instantiate([])
@functools.cached_property def measure_z_def(self) -> OpDef: """Destructive measurement of a logical qubit in the Z basis. This is the generic operation definition. For the instantiated operation, see `measure_z`.""" return self().get_op("measure_z")
[docs] def measure_z(self) -> ExtOp: """Destructive measurement of a logical qubit in the Z basis.""" return self.measure_z_def.instantiate([])
@functools.cached_property def qec_cycle_def(self) -> OpDef: """Perform a QEC cycle on a logical qubit. This is the generic operation definition. For the instantiated operation, see `qec_cycle`.""" return self().get_op("qec_cycle")
[docs] def qec_cycle(self) -> ExtOp: """Perform a QEC cycle on a logical qubit.""" return self.qec_cycle_def.instantiate([])
@functools.cached_property def decode_def(self) -> OpDef: """Decode a measurement of a Steane logical qubit. This is the generic operation definition. For the instantiated operation, see `decode`.""" return self().get_op("decode")
[docs] def decode(self) -> ExtOp: """Decode a measurement of a Steane logical qubit.""" return self.decode_def.instantiate([])
@functools.cached_property def x_def(self) -> OpDef: """Apply an X gate to one qubit. This is the generic operation definition. For the instantiated operation, see `x`.""" return self().get_op("x")
[docs] def x(self) -> ExtOp: """Apply an X gate to one qubit.""" return self.x_def.instantiate([])
@functools.cached_property def y_def(self) -> OpDef: """Apply a Y gate to one qubit. This is the generic operation definition. For the instantiated operation, see `y`.""" return self().get_op("y")
[docs] def y(self) -> ExtOp: """Apply an Y gate to one qubit.""" return self.y_def.instantiate([])
@functools.cached_property def z_def(self) -> OpDef: """Apply a Z gate to one qubit. This is the generic operation definition. For the instantiated operation, see `z`.""" return self().get_op("z")
[docs] def z(self) -> ExtOp: """Apply a Z gate to one qubit.""" return self.z_def.instantiate([])
@functools.cached_property def h_def(self) -> OpDef: """Apply an H gate to one qubit. This is the generic operation definition. For the instantiated operation, see `h`.""" return self().get_op("h")
[docs] def h(self) -> ExtOp: """Apply an H gate to one qubit.""" return self.h_def.instantiate([])
@functools.cached_property def s_def(self) -> OpDef: """Apply an S gate to one qubit. This is the generic operation definition. For the instantiated operation, see `s`.""" return self().get_op("s")
[docs] def s(self) -> ExtOp: """Apply an S gate to one qubit.""" return self.s_def.instantiate([])
@functools.cached_property def sdg_def(self) -> OpDef: """Apply an Sdg gate to one qubit. This is the generic operation definition. For the instantiated operation, see `sdg`.""" return self().get_op("sdg")
[docs] def sdg(self) -> ExtOp: """Apply an Sdg gate to one qubit.""" return self.sdg_def.instantiate([])
@functools.cached_property def rz_def(self) -> OpDef: """Apply an Rz gate to one qubit. This is the generic operation definition. For the instantiated operation, see `rz`.""" return self().get_op("rz")
[docs] def rz(self) -> ExtOp: """Apply an Rz gate to one qubit.""" return self.rz_def.instantiate([])
@functools.cached_property def prep_t_state_def(self) -> OpDef: """Prepare a magic state that can be used to produce T-like states (T and Tdg). This is the generic operation definition. For the instantiated operation, see `prep_t_state`.""" return self().get_op("prep_t_state")
[docs] def prep_t_state(self) -> ExtOp: """Prepare a magic state that can be used to produce T-like states (T and Tdg).""" return self.prep_t_state_def.instantiate([])
@functools.cached_property def inject_t_def(self) -> OpDef: """Perform a T gate by injecting a magic state. This is the generic operation definition. For the instantiated operation, see `inject_t`.""" return self().get_op("inject_t")
[docs] def inject_t(self) -> ExtOp: """Perform a T gate by injecting a magic state.""" return self.inject_t_def.instantiate([])
@functools.cached_property def inject_tdg_def(self) -> OpDef: """Perform a Tdg gate by injecting a magic state. This is the generic operation definition. For the instantiated operation, see `inject_tdg`.""" return self().get_op("inject_tdg")
[docs] def inject_tdg(self) -> ExtOp: """Perform a Tdg gate by injecting a magic state.""" return self.inject_tdg_def.instantiate([])
@functools.cached_property def cx_def(self) -> OpDef: """Apply a CX gate to two qubits. This is the generic operation definition. For the instantiated operation, see `cx`.""" return self().get_op("cx")
[docs] def cx(self) -> ExtOp: """Apply a CX gate to two qubits.""" return self.cx_def.instantiate([])
@functools.cached_property def cz_def(self) -> OpDef: """Apply a CZ gate to two qubits. This is the generic operation definition. For the instantiated operation, see `cz`.""" return self().get_op("cz")
[docs] def cz(self) -> ExtOp: """Apply a CZ gate to two qubits.""" return self.cz_def.instantiate([])
@functools.cached_property def swap_def(self) -> OpDef: """Apply a SWAP gate to two qubits. This is the generic operation definition. For the instantiated operation, see `swap`.""" return self().get_op("swap")
[docs] def swap(self) -> ExtOp: """Apply a SWAP gate to two qubits.""" return self.swap_def.instantiate([])