Skip to content

Dynamic one-shot execution with "hw-like" post-selection does not filter out shots with MCM in higher-order operator #2382

@dime10

Description

@dime10

In addition to issue #2381:

@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()

    return qml.sample(wires=0)

print(circuit(True))

produces unfiltered shots

[[0]
 [1]
 [0]
 [0]
 [0]
 [0]
 [0]
 [1]
 [1]
 [0]]

whereas

@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)

    measure(0, postselect=1)

    return qml.sample(wires=0)

print(circuit(True))

produces correctly filtered shots

[[-2147483648]
 [          1]
 [-2147483648]
 [-2147483648]
 [          1]
 [-2147483648]
 [          1]
 [          1]
 [          1]
 [          1]]

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