"""Guppy functions for the logical operations and types for the Steane QEC architecture.This module contains bindings for the fundamental ops in the HUGR extensions, as wellas composite operations that comprise multiple logical operations.The physical implementation for these ops is provided in:py:mod:`~guppyft.code.steane.primitives`."""fromcollections.abcimportCallablefromtypingimportno_type_checkfromguppylangimportguppyfromguppylang.std.langimportownedfromguppylang_internals.decoratorimportcustom_type,hugr_opfromguppylang_internals.tys.commonimportToHugrContextfromguppylang_internals.tys.substimportInstfromhugrimporttysashtfromhugr.opsimportDataflowOp,ExtOpfromguppyft.extensionsimportsteane_ops,steane_types_OPS_EXTN=steane_ops()def_steane_op(op_name:str,)->Callable[[ht.FunctionType,Inst,ToHugrContext],DataflowOp]:defop(ty:ht.FunctionType,inst:Inst,ctx:ToHugrContext)->DataflowOp:returnExtOp(_OPS_EXTN.get_op(op_name),ty,[arg.to_hugr(ctx)forargininst])returnop
[docs]@custom_type(steane_types.steane_measurement(),copyable=True,droppable=True)classMeasurement:"""A measurement outcome of a logical Steane qubit."""
[docs]@hugr_op(_steane_op("decode"))@no_type_checkdefdecode(self:"Measurement")->bool:"""Return the decoded logical measurement outcome."""
[docs]@custom_type(steane_types.steane_qubit(),copyable=False,droppable=False)classQubit:"""A logical qubit encoded in the Steane code. Constructing a ``Qubit`` instance prepares it in the logical zero state. """
[docs]@guppy@no_type_checkdeffree(self:"Qubit"@owned)->None:"""Free the qubit."""free(self)
[docs]@guppy@no_type_checkdefmeasure_z(self:"Qubit"@owned)->Measurement:"""Destructive measurement of the qubit in the Z basis."""returnmeasure_z(self)
[docs]@guppy@no_type_checkdefqec_cycle(self:"Qubit")->None:"""Perform a QEC cycle on the logical qubit."""qec_cycle(self)
[docs]@guppydeft(self:"Qubit")->None:r"""Apply a logical :math:`T` gate using magic-state injection."""t(self)
[docs]@guppydeftdg(self:"Qubit")->None:r"""Apply a logical :math:`T^\dagger` gate using magic-state injection."""tdg(self)
[docs]@hugr_op(_steane_op("free"))@no_type_checkdeffree(qubit:"Qubit"@owned)->None:"""Free a qubit."""
[docs]@hugr_op(_steane_op("measure_z"))@no_type_checkdefmeasure_z(qubit:"Qubit"@owned)->Measurement:"""Destructive measurement of the qubit in the Z basis."""
[docs]@hugr_op(_steane_op("qec_cycle"))@no_type_checkdefqec_cycle(qubit:Qubit)->None:"""Perform a QEC cycle on the logical qubit."""
[docs]@hugr_op(_steane_op("prep_t_state"))@no_type_checkdefprep_t_state()->"Qubit":r"""Prepare a logical :math:`T\ket{+}` magic state for :math:`T` and :math:`T^\dagger` injection."""
[docs]@hugr_op(_steane_op("inject_t"))@no_type_checkdefinject_t(qubit:"Qubit",magic:"Qubit"@owned)->None:"""Apply a logical :math:`T` gate by consuming a magic-state qubit."""
[docs]@hugr_op(_steane_op("inject_tdg"))@no_type_checkdefinject_tdg(qubit:"Qubit",magic:"Qubit"@owned)->None:r"""Apply a logical :math:`T^\dagger` gate by consuming a magic-state qubit."""