`qp.allocate(1)`: using the qubit without index works but not formally supported

Open
#2,580 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start by reproducing the provided qp.allocate(1) and qp.H(w) example with the listed PennyLane and Catalyst versions. Trace how qp.allocate and the unindexed register reach capture and operator handling; done means the behavior is formally supported or a clear warning/error directs users to qp.H(w[0]), with coverage for the chosen outcome.

Written by the indexing model from the issue text.

Description

When using qp.allocate(1) to allocate a single qubit, calling qp.H(w) (without indexing w[0]) silently succeeds. This behavior is not guaranteed and relies on implementation details. PL / Catalyst should either formally support this pattern or emit a warning/error directing users to always index their qubit registers.

Example:

import pennylane as qp

@qp.qjit(capture=True)
@qp.qnode(qp.device("null.qubit", wires=2))
def circuit():
    with qp.allocate(1) as w:
        # This works but is not guaranteed:
        qp.H(w)

        # This is the correct, explicit form:
        # qp.H(w[0])

    return qp.state()

print(circuit())

Versions:

Name: pennylane
Version: 0.45.0.dev52
JAX version:             0.7.1
Catalyst version:        0.15.0.dev47
Dominant language
Python
Stars
234
Forks
84
Avg merge
3d 11h
Merged PRs (30d)
78

Getting set up

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.

More from PennyLaneAI/catalyst

All issues in PennyLaneAI/catalyst

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.