diff --git a/hugr-py/src/hugr/ops.py b/hugr-py/src/hugr/ops.py index 5719ab092..f7451742f 100644 --- a/hugr-py/src/hugr/ops.py +++ b/hugr-py/src/hugr/ops.py @@ -197,7 +197,7 @@ def _set_in_types(self, types: tys.TypeRow) -> None: self._types = types -@dataclass() +@dataclass(frozen=True) class Custom(DataflowOp): """A non-core dataflow operation defined in an extension.""" diff --git a/hugr-py/tests/conftest.py b/hugr-py/tests/conftest.py index d72eb46e1..9f3ed3e62 100644 --- a/hugr-py/tests/conftest.py +++ b/hugr-py/tests/conftest.py @@ -52,7 +52,7 @@ def to_value(self) -> val.Extension: return val.Extension("float", FLOAT_T, self.v) -@dataclass +@dataclass(frozen=True) class LogicOps(Custom): extension: tys.ExtensionId = "logic" @@ -61,7 +61,7 @@ class LogicOps(Custom): # TODO get from YAML -@dataclass +@dataclass(frozen=True) class NotDef(LogicOps): num_out: int = 1 op_name: str = "Not" @@ -74,7 +74,7 @@ def __call__(self, a: ComWire) -> Command: Not = NotDef() -@dataclass +@dataclass(frozen=True) class QuantumOps(Custom): extension: tys.ExtensionId = "tket2.quantum" @@ -82,7 +82,7 @@ class QuantumOps(Custom): _OneQbSig = tys.FunctionType.endo([tys.Qubit]) -@dataclass +@dataclass(frozen=True) class OneQbGate(QuantumOps): op_name: str num_out: int = 1 @@ -98,7 +98,7 @@ def __call__(self, q: ComWire) -> Command: _TwoQbSig = tys.FunctionType.endo([tys.Qubit] * 2) -@dataclass +@dataclass(frozen=True) class TwoQbGate(QuantumOps): op_name: str num_out: int = 2 @@ -113,7 +113,7 @@ def __call__(self, q0: ComWire, q1: ComWire) -> Command: _MeasSig = tys.FunctionType([tys.Qubit], [tys.Qubit, tys.Bool]) -@dataclass +@dataclass(frozen=True) class MeasureDef(QuantumOps): op_name: str = "Measure" num_out: int = 2 @@ -128,7 +128,7 @@ def __call__(self, q: ComWire) -> Command: _RzSig = tys.FunctionType([tys.Qubit, FLOAT_T], [tys.Qubit]) -@dataclass +@dataclass(frozen=True) class RzDef(QuantumOps): op_name: str = "Rz" num_out: int = 1 @@ -141,7 +141,7 @@ def __call__(self, q: ComWire, fl_wire: ComWire) -> Command: Rz = RzDef() -@dataclass +@dataclass(frozen=True) class IntOps(Custom): extension: tys.ExtensionId = "arithmetic.int" @@ -149,7 +149,7 @@ class IntOps(Custom): ARG_5 = tys.BoundedNatArg(n=5) -@dataclass +@dataclass(frozen=True) class DivModDef(IntOps): num_out: int = 2 extension: tys.ExtensionId = "arithmetic.int"