Skip to content

[BUG] Conditional Behavior in Helper Function Displaying Questionable Visualization #4

@ChiragRaisingh

Description

@ChiragRaisingh

What mode are you using in CircInspect?

  • Real-time development
  • Debugger mode

Expected behavior

When a helper function contains conditional logic and no quantum operations are executed (i.e., the condition is not met), the helper function should not appear in the circuit visualization.

Specifically, if a helper function does not modify the circuit in any way for a given execution path, it should be omitted from the rendered circuit.

Expected behavior

Actual behavior

The helper function is still shown in the circuit visualization even when the conditional branch is not taken and the function performs no operations on the circuit.

Actual behavior 1 Actual behavior 2

Code used for testing

import pennylane as qml

dev = qml.device("default.qubit", wires=2)

@qml.qnode(device=dev)
def my_circuit():
    qml.Hadamard(wires=0)
    qml.CNOT([0,1])
    helper(1)
    return qml.probs()

def helper(a):
    if a == 0:
        qml.PauliX(0)

# Execute a QNode to render a circuit in the righthand pane
my_circuit()

System information

OS: Windows 11 Home

Browser: Google Chrome 143.0.7499.170

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions