Skip to content

hugr-py does not encode FuncDefn visibility in model export #2445

@aborgna-q

Description

@aborgna-q

#2436 added better roundtrip tests that write the test hugr in a given format, convert them to a different one using hugr convert if necessary, and load them back.

These work fine for json -> json, but if we enable writing hugrs in model-exts format then many tests fail with errors like

FAILED hugr-py/tests/test_hugr_build.py::test_simple_id - RuntimeError:   2025-07-17T10:11:34.474358Z ERROR hugr: Error decoding HUGR envelope.

Caused by:
    0: failed to import hugr
    1: import failed in context: `define-func` node with id 0
    2: No visibility for FuncDefn
    at hugr-cli/src/main.rs:38

That means we successfully produce an encoded model envelope, but it fails to load from the rust side in the hugr convert call.

To reproduce this, add model-exts to this list

# TODO: "model-exts" comes with its own variety of errors.
# Fix them and add it to the list of write formats.
WRITE_FORMATS = ["json"]

And run with just test-python -k test_simple_id.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions