@contextmanager
def mimic_execution_for_expval(device):
    device.reset()
    with device.execution_context():
        (yield)
        if (not (device.shots is None)):
            device._samples = device.generate_samples()
@contextmanager
def mimic_execution_for_expval(device):
    device.reset()
    with device.execution_context():
        (yield)
        if (not (device.shots is None)):
            device._samples = device.generate_samples()