-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
bugSomething isn't workingSomething isn't working
Description
This Hugr is expected to optimize to a single Hadamard gates but doesn't seem to work if arrays are used.
from guppylang import guppy
from guppylang.std.quantum import cx, h, qubit
from guppylang.std.builtins import array
from hugr.hugr.base import Hugr
from tket.passes import NormalizeGuppy, PytketPass
from pytket.passes import RemoveRedundancies
@guppy
def arr_cx(arr: array[qubit, 2]) -> None:
h(arr[0])
cx(arr[0], arr[1])
cx(arr[0], arr[1])
normalize = NormalizeGuppy()
hugr_graph: Hugr = normalize(arr_cx.compile_function().modules[0])
opt_pass = PytketPass(RemoveRedundancies())
new_hugr = opt_pass(hugr_graph)
def count_ops(hugr: Hugr, string_name: str) -> int:
count = 0
for _, data in hugr.nodes():
if string_name in data.op.name():
count += 1
return count
print(count_ops(new_hugr, "CX")) # prints 2, should be zeroWe can draw the Hugr as follows
from graphviz import Digraph
from hugr.hugr.render import DotRenderer, RenderConfig
# Configure Hugr visualizer
my_renderer = DotRenderer(RenderConfig(display_node_id=True, display_metadata=False))
def draw(hugr: Hugr) -> Digraph:
"""Draw a Hugr graph with the DotRenderer."""
return my_renderer.render(hugr)
draw(new_hugr)Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working