qml.workflow.set_shots¶
- set_shots(device, shots)[source]¶
Context manager to temporarily change the shots of a device.
Warning
set_shots
is deprecated and will be removed in PennyLane version v0.40.To dynamically update the shots on the workflow, shots can be manually set on a
QNode
call:>>> circuit(shots=my_new_shots)
When working with the internal tapes, shots should be set on each tape.
>>> tape = qml.tape.QuantumScript([], [qml.sample()], shots=50)
This context manager can be used in two ways.
As a standard context manager:
>>> with qml.workflow.set_shots(dev, shots=100): ... print(dev.shots) 100 >>> print(dev.shots) None
Or as a decorator that acts on a function that uses the device:
>>> qml.workflow.set_shots(dev, shots=100)(lambda: dev.shots)() 100
code/api/pennylane.workflow.set_shots
Download Python script
Download Notebook
View on GitHub