42 Random(
const std::vector<size_t> &ind = {}) :
Random(ind, GenerateSeed())
44 explicitlySeeded =
false;
55 Random(
const std::vector<size_t> &ind,
size_t seed, Time delay = 0) :
IOperation<Time>(delay), indices(ind), s(seed)
69 for (
size_t i : indices)
70 state.
SetBit(i, dist_bool(rng));
115 explicitlySeeded =
true;
116 std::seed_seq seed{uint32_t(s & 0xffffffff), uint32_t(s >> 32)};
122 return explicitlySeeded;
131 std::shared_ptr<IOperation<Time>>
Clone()
const override
134 copy->explicitlySeeded = explicitlySeeded;
146 std::shared_ptr<Random<Time>>
CloneForExecution(uint64_t stream, uint64_t defaultSeed = 0)
const
148 auto copy = std::static_pointer_cast<Random<Time>>(
Clone());
174 std::shared_ptr<IOperation<Time>>
Remap(
const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
175 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
const override
177 auto newOp =
Clone();
179 for (
size_t i = 0; i < indices.size(); ++i)
181 const auto bitit = bitsMap.find(indices[i]);
182 if (bitit != bitsMap.end())
183 std::static_pointer_cast<Random<Time>>(newOp)->
SetBit(i, bitit->second);
213 if (index < indices.size())
214 indices[index] = bit;
218 static size_t GenerateSeed()
220 std::random_device entropy;
221 return std::uniform_int_distribution<size_t>{}(entropy);
224 std::vector<size_t> indices;
226 mutable std::mt19937_64 rng;
227 mutable std::bernoulli_distribution dist_bool;
230 bool explicitlySeeded =
false;
Time GetDelay() const
Get the delay of the operation.
IOperation(Types::time_type delay=0)
The state class that stores the classical state of a quantum circuit execution.
void SetBit(size_t index, bool value=true)
Set the classical bit at the specified index.
void Seed(size_t sd)
Seeds the random generator.
std::vector< size_t > AffectedBits() const override
Get the affected bits.
void SetBit(size_t index, Types::qubit_t bit)
Set the classical bit to index.
std::shared_ptr< IOperation< Time > > Remap(const std::unordered_map< Types::qubit_t, Types::qubit_t > &qubitsMap, const std::unordered_map< Types::qubit_t, Types::qubit_t > &bitsMap={}) const override
Get a shared pointer to a remapped operation.
Random(const std::vector< size_t > &ind, size_t seed, Time delay=0)
Construct a new Random object.
bool HasExplicitSeed() const
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
const std::vector< size_t > & GetBitsIndices() const
Get the indices of the classical bits affected by this operation.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the operation.
Random(const std::vector< size_t > &ind={})
Construct a generator with a fresh random seed.
OperationType GetType() const override
Get the type of the operation.
void SetBitsIndices(const std::vector< size_t > &ind)
Set the indices of the classical bits affected by this operation.
std::shared_ptr< Random< Time > > CloneForExecution(uint64_t stream, uint64_t defaultSeed=0) const
Clone the generator for an independent execution stream.
bool IsClifford() const override
Checks if the operation is a Clifford one.
static uint64_t DeriveSeed(uint64_t seed, uint64_t stream)
OperationType
The type of operations.
@ kRandomGen
random classical bit generator, result in 'OperationState'
uint_fast64_t qubit_t
The type of a qubit.