Skip to content

[Bug]: PanicException when applying NormalizeGuppy to hugr that returns sum of float extern symbols #1473

@ferbetanzo

Description

@ferbetanzo

Description

Observed when running NormalizeGuppy on the hugr generated by the guppylang integration test: test_extern.py::test_extern_float.

Traces

    def _normalize(self, hugr: Hugr, inplace: bool) -> PassResult:
        compiler_state, registry = _hugr_to_tk2circuit(hugr)
>       opt_program = normalize_guppy(
            compiler_state,
            simplify_cfgs=self.simplify_cfgs,
            remove_tuple_untuple=self.remove_tuple_untuple,
            constant_folding=self.constant_folding,
            remove_dead_funcs=self.remove_dead_funcs,
            inline_dfgs=self.inline_dfgs,
            remove_redundant_order_edges=self.remove_redundant_order_edges,
        )
E       pyo3_runtime.PanicException: This function assumes all incoming constants are floats.

.devenv/state/venv/lib/python3.14/site-packages/tket/passes.py:180: PanicException
thread '<unnamed>' (1318164) panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/hugr-core-0.25.4/src/std_extensions/arithmetic/float_ops/const_fold.rs:31:14:
This function assumes all incoming constants are floats.

Steps to Reproduce

  1. Run NormalizeGuppy on a hugr with extern symbols:
from guppylang.decorator import guppy
from tket.passes import NormalizeGuppy
from hugr.package import Package

normalize = NormalizeGuppy()
ext = guppy._extern("ext", ty="float")


@guppy
def main() -> float:
    return ext + ext
    # return ext


pkg = main.compile_function()
hg = pkg.modules[0]
normalize(hg)
  1. Check that using return ext instead of return ext + ext is ok.

Expected Behaviour

No response

Actual Behaviour

No response

Component

No response

Environment

Additional Context

No response

Metadata

Metadata

Assignees

Labels

A-rustArea: Rust codeC-bugfixCategory: PR with bug fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions