Skip to content

guppy_to_circuit always returns num_operations = 0 #1130

@mariagg-quantinuum

Description

@mariagg-quantinuum

Converting a Guppy function definition to a Tk2Circuit through compile_function()-> to_str(json,f_name) -> from_str(json,f_name) always leads to a num_operations() = 0, regardless of the contents of the function.
This showed up whilst testing the guppy_to_circuit(func_def) defined in the __init__.py file of the tket-py examples.

def guppy_to_circuit(func_def: Any) -> Tk2Circuit:
    """Convert a Guppy function definition to a `Tk2Circuit`."""

    pkg = func_def.compile_function()

    f_name = pkg.modules[0].entrypoint_op().f_name

    json = pkg.to_str(EnvelopeConfig.TEXT)
    circ = Tk2Circuit.from_str(json, f_name)

    return lower_to_pytket(circ)

guppy_to_circuit() consistently results in zero TketOp across various tested functions.

In this example:

from hugr import Hugr
from hugr.envelope import EnvelopeConfig
from tket.passes import lower_to_pytket
from tket.circuit import Tk2Circuit
from typing import Any
from guppylang import guppy
from guppylang.std.quantum import qubit, rz
from guppylang.std.angles import angle
from guppylang.std.builtins import owned

@guppy
def one_op(q0: qubit @owned, angle: angle) -> qubit:
    rz(q0, angle)
    return (q0)

def guppy_to_circuit(func_def: Any) -> Tk2Circuit:
    """Convert a Guppy function definition to a `Tk2Circuit`."""

    pkg = func_def.compile_function()

    f_name = pkg.modules[0].entrypoint_op().f_name

    json = pkg.to_str(EnvelopeConfig.TEXT)
    circ = Tk2Circuit.from_str(json, f_name)

    return lower_to_pytket(circ)

def main():
     one_op = guppy_to_circuit(one_op)
     print(one_op.num_operations())

it also returns 0 even though `circ' is non-empty:

one_op.pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-pythonArea: Python codeC-bugfixCategory: PR with bug fix

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions