PennyLaneAI / PennyLaneAI/catalyst

`catalyst.draw_graph` doesn't work with `gridsynth`

Open
#2,541 29 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
234
Forks
84
Avg merge
2d 15h
Merged PRs (30d)
66

Description

The following example errors out during the circuit graph construction with a cryptic error message.

import pennylane as qml
from catalyst import *

null_dev = qml.device("null.qubit", wires=1)

@qjit
@qml.transforms.gridsynth
@qml.qnode(null_dev)
def circuit():
    qml.RZ(0.1, 0)
    return qml.probs()

draw_graph(circuit, level=1)()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

File catalyst/python_interface/inspection/draw.py:352, in draw_graph.<locals>._draw_callback(previous_pass, module, next_pass, pass_level)
    350 pass_instance = previous_pass if previous_pass else next_pass
    351 utility = ConstructCircuitDAG(PyDotDAGBuilder())
--> 352 utility.construct(module)
    353 # Default DPI to 300 and let user fine tune control through the return MPL figure
    354 utility.dag_builder.graph.set_dpi(300)

File catalyst/python_interface/inspection/construct_circuit_dag.py:136, in ConstructCircuitDAG.construct(self, module)
    134 self._reset()
    135 for op in module.ops:
--> 136     self._visit_operation(op)

File functools.py:946, in singledispatchmethod.__get__.<locals>._method(*args, **kwargs)
    944 def _method(*args, **kwargs):
    945     method = self.dispatcher.dispatch(args[0].__class__)
--> 946     return method.__get__(obj, cls)(*args, **kwargs)

File catalyst/python_interface/inspection/construct_circuit_dag.py:593, in ConstructCircuitDAG._func_op(self, operation)
    590 self._cluster_uid_counter += 1
    591 self._cluster_uid_stack.append(uid)
--> 593 self._visit_block(operation.regions[0].blocks[0])

File xdsl/ir/core.py:2264, in RegionBlocks.__getitem__(self, idx)
   2262         if i == idx:
   2263             return b
-> 2264     raise IndexError
   2265 else:
   2266     for i, b in enumerate(reversed(self)):

IndexError: 
"builtin.module"() ({
  "transform.named_sequence"() <{sym_name = "__transform_main", function_type = (!transform.op<"builtin.module">) -> ()}> ({
  ^bb0(%arg0 : !transform.op<"builtin.module">):
    %0 = "transform.apply_registered_pass"(%arg0) <{options = {epsilon = 1.000000e-04 : f64, "ppr-basis" = false}, pass_name = "gridsynth"}> : (!transform.op<"builtin.module">) -> !transform.op<"builtin.module">
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | Error while interpreting op
    --------------------------------------
    "transform.yield"() : () -> ()
  }) : () -> ()
}) {transform.with_named_sequence} : () -> ()

I believe this might stem from a subroutine call the transform is generating, which the draw_graph functionality cannot handle. If so, a better error message should be provided to the user.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducing gridsynth example, then inspect catalyst/python_interface/inspection/draw.py around draw_graph and catalyst/python_interface/inspection/construct_circuit_dag.py, especially _func_op. Determine why the generated operation lacks the expected region during graph construction; done means the example no longer raises a cryptic IndexError and receives either supported graph output or a clear user-facing error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.