šŸ› `qjit` capture skips measurement diagonalization for devices that only support PauliZ

Open
#3,550 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend, compilers

Research direction

Start by reading the measurement compilation path that invokes diagonalize_measurements and how qjit handles device observable capabilities. Reproduce the issue with the supplied one wire lightning.qubit example and inspect the QuantumCompilationStage IR. Done means the unsupported PauliX observable is converted to a supported PauliZ measurement with a Hadamard, and the assertion passes.

Written by the indexing model from the issue text.

Description

bug

When a device supports Hadamard gates but can only measure PauliZ, I’d expect qp.expval(qp.X(0)) to compile to a Hadamard followed by a PauliZ measurement. With capture enabled, qjit warns that it skips diagonalize_measurements and emits a PauliX measurement that the device cannot execute.

This reproduces on PennyLane 2.0.0.dev3 and Catalyst 0.16.0.dev162 by restricting the observables that lightning.qubit advertises to qjit:

from dataclasses import replace

import pennylane2 as qp
from catalyst.debug import get_compilation_stage

dev = qp.device("lightning.qubit", wires=1)
dev.qjit_capabilities = replace(
    dev.capabilities, observables={"PauliZ": dev.capabilities.observables["PauliZ"]}
)

@qp.qjit(keep_intermediate=True)
@qp.qnode(dev)
def circuit():
    return qp.expval(qp.X(0))

ir = get_compilation_stage(circuit, "QuantumCompilationStage")
assert "PauliX" not in ir

The assertion fails. The compiled program still contains %2 = quantum.namedobs %1[ PauliX] : !quantum.obs.

Related discussion in #3548

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.