Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hugr-py/src/hugr/std/collections/static_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def to_value(self) -> val.Extension:
# into specialized `Value`s).
serial_val = {
"value": {
"values": [v._to_serial_root().model_dump_json() for v in self.v],
"typ": self.ty.ty._to_serial_root().model_dump_json(),
"values": [v._to_serial_root() for v in self.v],
"typ": self.ty.ty._to_serial_root(),
},
"name": self.name,
}
Expand Down
19 changes: 12 additions & 7 deletions hugr-py/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing_extensions import Self

from hugr import ext, tys
from hugr._serialization import ops as sops
from hugr.envelope import EnvelopeConfig
from hugr.hugr import Hugr
from hugr.ops import AsExtOp, Command, Const, Custom, DataflowOp, ExtOp, RegisteredOp
Expand Down Expand Up @@ -262,14 +263,18 @@ def _hash_node(cls, h: Hugr, n: Node, depth: int, name: str) -> _NodeHash:
elif isinstance(op_type, Const):
# We need every custom value to have the same repr if they compare
# equal. For example, an `IntVal(42)` should be the same as the
# equivalent `Extension` value.
# This needs a lot of extra unwrapping, since each class implements
# different `__repr__` methods.
# equivalent `Extension` value. This needs a lot of extra
# unwrapping, since each class implements different `__repr__`
# methods.
#
# Our solution here is to roundtrip via `sops.Value`. This may miss
# some errors, but it's the best we can do for now.
serial_val = op_type.val._to_serial_root()
val = serial_val.deserialize()
# Our solution here is to roundtrip via JSON. This may miss some
# errors, but it's the best we can do for now. Note that
# roundtripping via `sops.Value` is not enough, since nested
# specialized values don't get serialized straight away. (e.g.
# StaticArrayVal's dictionary payload containing a SumValue
# internally, see `test_val_static_array`).
value_dict = op_type.val._to_serial_root().model_dump()
val = sops.Value(**value_dict).deserialize()
op = repr(Const(val, num_out=op_type.num_out))
else:
op = op_type.name()
Expand Down
Loading