Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing the same hugr twice causes an error #82

Closed
aborgna-q opened this issue Jan 10, 2024 · 0 comments · Fixed by #84
Closed

Serializing the same hugr twice causes an error #82

aborgna-q opened this issue Jan 10, 2024 · 0 comments · Fixed by #84
Assignees
Labels
bug Something isn't working

Comments

@aborgna-q
Copy link
Collaborator

This test fails. (I just added the repeated validation to test_discard.

def test_discard(validate):
    @guppy
    def discard(x: int) -> None:
        return

    validate(discard)
    validate(discard)

Running pytest -v throws out this error.

validate = <function validate.<locals>.validate_impl at 0x7fddf2cf71a0>

    def test_discard(validate):
        @guppy
        def discard(x: int) -> None:
            return
    
        validate(discard)
>       validate(discard)

tests/integration/test_basic.py:36: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/integration/conftest.py:17: in validate_impl
    bs = hugr.serialize()
guppy/hugr/hugr.py:773: in serialize
    return self.to_raw().packb()
guppy/hugr/hugr.py:708: in to_raw
    self.insert_order_edges()
guppy/hugr/hugr.py:688: in insert_order_edges
    if all(
guppy/hugr/hugr.py:689: in <genexpr>
    next(self.out_edges(p), None) is None for p in n.out_ports
guppy/hugr/hugr.py:623: in out_edges
    src, tgt = self._to_edge(*e)
guppy/hugr/hugr.py:644: in _to_edge
    return src_node.out_port(key[0]), tgt_node.in_port(key[1])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = VNode(idx=6, op=MakeTuple(parent=1, input_extensions=[], op='LeafOp', lop='MakeTuple', tys=[]), parent=BlockNode(idx=4...types=[]), meta_data={}), meta_data={}, in_port_types=[], out_port_types=[TupleType(element_types=[], preserve=False)])
offset = -1

    def in_port(self, offset: PortOffset | None) -> InPortV:
        """Returns the input port at the given offset."""
        assert offset is not None
        assert offset < self.num_in_ports
>       return InPortV(self, offset, self.in_port_types[offset])
E       IndexError: list index out of range

guppy/hugr/hugr.py:157: IndexError

This is the only tests that fails if we call hugr.serialize() twice in a row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant