qml.measurements.Shots¶

class
Shots
(shots=None)[source]¶ Bases:
object
A data class that stores shot information.
 Parameters
shots (Union[None, int, Sequence[int, Tuple[int, int]]]) – Raw shot information
Defining shots enables users to specify circuit executions, and the Shots class standardizes the internal representation of shots. There are three ways to specify shot values:
The value
None
A positive integer
A sequence consisting of either positive integers or a tuplepair of positive integers of the form
(shots, copies)
The tuplepair of the form
(shots, copies)
is represented internally by a NamedTuple calledShotCopies
. The first value is the number of shots to execute, and the second value is the number of times to repeat a circuit with that number of shots.The
Shots
class exposes two properties:total_shots
, the total number of shots to be executedshot_vector
, the tuple ofShotCopies
to be executed
Instances of this class are static. If an instance is passed to the constructor, that same instance is returned. If an instance is constructed with a
None
value,total_shots
will beNone
. This indicates analytic execution. AShots
object created with aNone
value is Falsy, while any other value results in a Truthy object:>>> bool(Shots(None)), bool(Shots(1)) (False, True)
Examples
Example constructing a Shots instance with
None
:>>> shots = Shots(None) >>> shots.total_shots, shots.shot_vector (None, ())
Example constructing a Shots instance with an int:
>>> shots = Shots(100) >>> shots.total_shots, shots.shot_vector (100, (ShotCopies(100 shots),))
Example constructing a Shots instance with another instance:
>>> shots = Shots(100) >>> Shots(shots) is shots True
Example constructing a Shots instance with a sequence of ints:
>>> shots = Shots([100, 200]) >>> shots.total_shots, shots.shot_vector (300, (ShotCopies(100 shots x 1), ShotCopies(200 shots x 1)))
Example constructing a Shots instance with a sequence of tuplepairs:
>>> shots = Shots(((100, 3), (200, 4),)) >>> shots.total_shots, shots.shot_vector (1100, (ShotCopies(100 shots x 3), ShotCopies(200 shots x 4)))
Example constructing a Shots instance with a sequence of both ints and tuplepairs. Note that the first standalone
100
gets absorbed into the subsequent tuple because the shot value matches:>>> shots = Shots((10, 100, (100, 3), (200, 4),)) >>> shots.total_shots, shots.shot_vector (1210, (ShotCopies(10 shots x 1), ShotCopies(100 shots x 4), ShotCopies(200 shots x 4)))
One should also note that specifying a single tuple of length 2 is considered two different shot values, and not a tuplepair representing shots and copies to avoid special behaviour depending on the iterable type:
>>> shots = Shots((100, 2)) >>> shots.total_shots, shots.shot_vector (102, (ShotCopies(100 shots x 1), ShotCopies(2 shots x 1)))
>>> shots = Shots(((100, 2),)) >>> shots.total_shots, shots.shot_vector (200, (ShotCopies(100 shots x 2),))
Attributes
Evaluates to True if this instance represents either multiple shot quantities, or the same shot quantity repeated multiple times.
The total number of copies of any shot quantity.
The tuple of
ShotCopies
to be executed.The total number of shots to be executed.

has_partitioned_shots
¶ Evaluates to True if this instance represents either multiple shot quantities, or the same shot quantity repeated multiple times.
 Returns
whether shots are partitioned
 Return type
bool

num_copies
¶ The total number of copies of any shot quantity.

shot_vector
: Tuple[pennylane.measurements.shots.ShotCopies] = None¶ The tuple of
ShotCopies
to be executed. Each element is of the form(shots, copies)
.

total_shots
: int = None¶ The total number of shots to be executed.