Skip to content

Program.get_qubit_indices ignores literal qubits inside DEFCIRCUIT bodies #1868

Description

@bramathon

Program.get_qubit_indices() only reports qubits named by top-level instructions. A qubit that appears literally inside a DEFCIRCUIT body is not reported, even though invoking the circuit acts on it:

from pyquil import Program
from pyquil.gates import H, X
from pyquil.quilatom import FormalArgument, Qubit
from pyquil.quilbase import DefCircuit, Gate

q = FormalArgument("q")
dc = DefCircuit("C", [], [q], [X(q), X(Qubit(3))])   # body touches qubit 3 literally
p = Program(dc, Gate("C", [], [Qubit(0)]), H(1))
p.get_qubit_indices()   # {0, 1} -- qubit 3 is missing

Anything that sizes a register from get_qubit_indices() (the experimental simulators in #1860, for one) therefore cannot see such a qubit. The simulators currently reject literal qubits in DEFCIRCUIT bodies outright to avoid silently mis-simulating; that check can be rolled back once get_qubit_indices expands circuit definitions (or reports their literal qubits) itself.

Raised from the review of #1860.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JfZKmgqinMhR4BS87y4G4F

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions