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
16 changes: 8 additions & 8 deletions hugr-py/src/hugr/envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
# `make_envelope_str`, but we prioritize speed for binary formats.
payload = json_str.encode("utf-8")

case EnvelopeFormat.MODULE:
case EnvelopeFormat.MODEL:
payload = bytes(package.to_model())

case EnvelopeFormat.MODULE_WITH_EXTS:
case EnvelopeFormat.MODEL_WITH_EXTS:
package_bytes = bytes(package.to_model())
extension_str = json.dumps(
[ext._to_serial().model_dump(mode="json") for ext in package.extensions]
Expand Down Expand Up @@ -105,7 +105,7 @@
match header.format:
case EnvelopeFormat.JSON:
return ext_s.Package.model_validate_json(payload).deserialize()
case EnvelopeFormat.MODULE | EnvelopeFormat.MODULE_WITH_EXTS:
case EnvelopeFormat.MODEL | EnvelopeFormat.MODEL_WITH_EXTS:

Check warning on line 108 in hugr-py/src/hugr/envelope.py

View check run for this annotation

Codecov / codecov/patch

hugr-py/src/hugr/envelope.py#L108

Added line #L108 was not covered by tests
msg = "Decoding HUGR envelopes in MODULE format is not supported yet."
raise ValueError(msg)

Expand Down Expand Up @@ -150,10 +150,10 @@
class EnvelopeFormat(Enum):
"""Format used to encode a HUGR envelope."""

MODULE = 1
"""A capnp-encoded hugr-module."""
MODULE_WITH_EXTS = 2
"""A capnp-encoded hugr-module, immediately followed by a json-encoded
MODEL = 1
"""A capnp-encoded hugr-model."""
MODEL_WITH_EXTS = 2
"""A capnp-encoded hugr-model, immediately followed by a json-encoded
extension registry."""
JSON = 63 # '?' in ASCII
"""A json-encoded hugr-package. This format is ASCII-printable."""
Expand Down Expand Up @@ -232,4 +232,4 @@
# Set EnvelopeConfig's class variables.
# These can only be initialized _after_ the class is defined.
EnvelopeConfig.TEXT = EnvelopeConfig(format=EnvelopeFormat.JSON, zstd=None)
EnvelopeConfig.BINARY = EnvelopeConfig(format=EnvelopeFormat.JSON, zstd=None)
EnvelopeConfig.BINARY = EnvelopeConfig(format=EnvelopeFormat.MODEL_WITH_EXTS, zstd=0)
7 changes: 4 additions & 3 deletions hugr-py/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ def validate(
snapshot: A hugr render snapshot. If not None, it will be compared against the
rendered HUGR. Pass `--snapshot-update` to pytest to update the snapshot file.
"""
# TODO: Use envelopes instead of legacy hugr-json
cmd = [*_base_command(), "validate", "-"]

serial = h.to_bytes(EnvelopeConfig.BINARY)
_run_hugr_cmd(serial, cmd)
# validate text and binary formats
for fmt in (EnvelopeConfig.TEXT, EnvelopeConfig.BINARY):
serial = h.to_bytes(fmt)
_run_hugr_cmd(serial, cmd)

if not roundtrip:
return
Expand Down
2 changes: 1 addition & 1 deletion hugr-py/tests/test_hugr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def test_ancestral_sibling():
@pytest.mark.parametrize(
"val",
[
val.Function(simple_id().hugr),
val.Sum(1, tys.Sum([[INT_T], [tys.Bool, INT_T]]), [val.TRUE, IntVal(34)]),
val.Tuple(val.TRUE, IntVal(23)),
],
Expand Down Expand Up @@ -346,6 +345,7 @@ def test_invalid_recursive_function() -> None:
f_recursive.set_outputs(f_recursive.input_node[0])


@pytest.mark.skip("Value::Function is deprecated and not supported by model encoding.")
def test_higher_order(snapshot) -> None:
noop_fn = Dfg(tys.Qubit)
noop_fn.set_outputs(noop_fn.add(ops.Noop()(noop_fn.input_node[0])))
Expand Down
Loading