Skip to content

qml.shadow_expval should respect the device RNG seed for sampling #9209

@andrijapau

Description

@andrijapau

Expected behavior

Setting the seed kwarg at the device should result in a deterministic sampling execution.

Actual behavior

Doesn't get properly seeded.

Additional information

If you seed both at the MP and device level it works as expected,

import pennylane as qp

@qp.set_shots(10)
@qp.qnode(qp.device("default.qubit", seed=123, wires=1))
def circuit():
    qp.H(0)
    return qp.shadow_expval(qp.Z(0), seed=42) # SET HERE
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))
(array(-1.2), np.float64(0.0))

Source code

import pennylane as qp

for i in range(10):
    @qp.set_shots(10)
    @qp.qnode(qp.device("default.qubit", wires=1, seed=42))
    def circuit():
        qp.H(0)
        return qp.shadow_expval(qp.Z(0)), qp.expval(qp.Z(0))
    print(circuit())

Tracebacks

(array(-0.6), np.float64(-0.2))
(array(0.6), np.float64(-0.2))
(array(0.6), np.float64(-0.2))
(array(-0.3), np.float64(-0.2))
(array(-0.3), np.float64(-0.2))
(array(-0.6), np.float64(-0.2))
(array(-0.3), np.float64(-0.2))
(array(-0.3), np.float64(-0.2))
(array(-0.3), np.float64(-0.2))
(array(0.3), np.float64(-0.2))

System information

PL v0.44

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions