StatevectorSampler
always samples the same outcomes when seed
is an integer
#13047
Labels
StatevectorSampler
always samples the same outcomes when seed
is an integer
#13047
Environment
What is happening?
Suppose you have a
StatevectorSampler
with theseed
set to an integer. Then if you run the same circuit multiple times, it will always sample the same outcomes.The same issue probably affects
StatevectorEstimator
.How can we reproduce the issue?
Output:
What should happen?
It should give different outcomes for each
pub
and for each call to therun
method, even if the circuits are the same.If you set the
seed
to anumpy.random.Generator
it has the expected behavior. For instance keeping the code snippet from above but only changing the seed asthen it will output:
Any suggestions?
Currently the
StatevectorSampler
class stores the private attribute_seed
as it is (eitherGenerator
,int
orNone
). Therun
method iterates over the circuits. Inside thisfor
loop, it fixes the seed of thestatevector
, which transforms the integerseed
into aGenerator
when needed. It means the exact sameGenerator
is instantiated each single time.Instead we could transform an integer seed into a
Generator
at the initiliazation ofStatevectorSampler
objects, such that the attribute_seed
is either aGenerator
orNone
.For instance:
The text was updated successfully, but these errors were encountered: