PennyLaneAI / PennyLaneAI/catalyst
`decompose-lowering`'s `prepareCallOperands` doesn't support qreg + multiple individual qubit indices
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 234
- Forks
- 84
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 66
Description
Signatures of the form (qreg, *params, first_qubit_index, second_qubit_index, ...) are not supported by decompose lowering.
MWE:
@qjit(capture=True)
@qnode(device("lightning.qubit", wires=2))
def circuit(wires):
qp.PauliRot(0.2, "XZ", wires)
return qp.probs()
circuit([0, 1])
print(circuit.mlir)
generates the IR
func.func public @circuit(%arg0: tensor<i64>, %arg1: tensor<i64>) -> tensor<4xf64> attributes {diff_method = "parameter-shift", llvm.linkage = #llvm.linkage<internal>, quantum.node} {
%cst = arith.constant 2.000000e-01 : f64
%c0_i64 = arith.constant 0 : i64
quantum.device shots(%c0_i64) ["/Users/river.mccubbin/Github/catalyst/.venv/lib/python3.14/site-packages/pennylane_lightning/liblightning_qubit_catalyst.dylib", "LightningSimulator", "{'mcmc': False, 'num_burnin': 0, 'kernel_name': None}"]
%0 = quantum.alloc( 2) : !quantum.reg
%extracted = tensor.extract %arg0[] : tensor<i64>
%1 = quantum.extract %0[%extracted] : !quantum.reg -> !quantum.bit
%extracted_0 = tensor.extract %arg1[] : tensor<i64>
%2 = quantum.extract %0[%extracted_0] : !quantum.reg -> !quantum.bit
%out_qubits:2 = quantum.paulirot ["X", "Z"](%cst) %1, %2 : !quantum.bit, !quantum.bit
%extracted_1 = tensor.extract %arg0[] : tensor<i64>
%3 = quantum.insert %0[%extracted_1], %out_qubits#0 : !quantum.reg, !quantum.bit
%extracted_2 = tensor.extract %arg1[] : tensor<i64>
%4 = quantum.insert %3[%extracted_2], %out_qubits#1 : !quantum.reg, !quantum.bit
%5 = quantum.compbasis qreg %4 : !quantum.obs
%6 = quantum.probs %5 : tensor<4xf64>
quantum.dealloc %4 : !quantum.reg
quantum.device_release
return %6 : tensor<4xf64>
}
which fails with decompose-lowering:
Assertion failed: (idx < size()), function operator[], file SmallVector.h, line 295.
because of the assumption that qubit indices with qregs will be represented as a tensor (eg. tensor<2xi64>).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in decompose-lowering at prepareCallOperands and reproduce the supplied qjit capture example with a qreg plus individual qubit indices. Trace the handling of qreg index operands and verify that the example lowers without the SmallVector assertion and produces valid MLIR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100