32template <
typename Time = Types::time_type>
43 Random(
const std::vector<size_t> &ind = {},
size_t seed = 0, Time delay = 0)
44 :
IOperation<Time>(delay), indices(ind), s(seed) {
55 void Execute(
const std::shared_ptr<Simulators::ISimulator> &sim,
57 for (
size_t i : indices)
58 state.
SetBit(i, dist_bool(rng));
93 std::seed_seq seed{uint32_t(s & 0xffffffff), uint32_t(s >> 32)};
103 std::shared_ptr<IOperation<Time>>
Clone()
const override {
126 std::shared_ptr<IOperation<Time>>
127 Remap(
const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
128 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
130 auto newOp =
Clone();
132 for (
size_t i = 0; i < indices.size(); ++i) {
133 const auto bitit = bitsMap.find(indices[i]);
134 if (bitit != bitsMap.end())
135 std::static_pointer_cast<Random<Time>>(newOp)->
SetBit(i, bitit->second);
161 if (index < indices.size())
162 indices[index] = bit;
166 std::vector<size_t> indices;
168 mutable std::mt19937_64 rng;
169 mutable std::bernoulli_distribution
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.
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.
OperationType GetType() const override
Get the type of the operation.
Random(const std::vector< size_t > &ind={}, size_t seed=0, Time delay=0)
Construct a new Random object.
void SetBitsIndices(const std::vector< size_t > &ind)
Set the indices of the classical bits affected by this operation.
bool IsClifford() const override
Checks if the operation is a Clifford one.
OperationType
The type of operations.
@ kRandomGen
random classical bit generator, result in 'OperationState'
uint_fast64_t qubit_t
The type of a qubit.