Skip to content

mcm_config is not propagated through higher-order operators #2381

@dime10

Description

@dime10

Tracing an MCM operation requires a postselect_mode argument in order to generate the correct primitive:

def trace_quantum(self, ctx, device, trace, qrp, postselect_mode=None) -> QRegPromise:

In particular, with

  • "hw-like" execution, the postselect kwarg is removed from the primitive in order to generate both valid and invalid shots
  • "fill-whots" execution, the postselect kwarg is included in the mcm primitive which then acts like a project operation

While the mcm_config is provided when tracing top-level mcm operations:

qrp_out = trace_quantum_operations(
tape, device, qreg_in, ctx, trace, mcm_config, snapshot_results

there are several instances where this not the case. Specifically, whenever a higher-order operator traces its body region:
https://github.com/search?q=repo%3APennyLaneAI%2Fcatalyst%20trace_quantum_operations(&type=code

As a result, the mcm primitive is incorrectly configured when an MCM operation is used from within a higher-order operator:

@qjit
@qml.qnode(
    qml.device("lightning.qubit", wires=1),
    shots=10,
    mcm_method="one-shot",
    postselect_mode="hw-like",
)
def circuit(b: bool):
    qml.H(0)

    @cond(b)
    def nested():
        measure(0, postselect=1)
    nested()

print(circuit.mlir)

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