16#ifndef _RESET_STATE_H_
17#define _RESET_STATE_H_
31template <
typename Time = Types::time_type>
44 const std::vector<bool> &resetTargets = {})
45 :
IOperation<Time>(delay), qubits(qubits), resetTargets(resetTargets) {}
57 void Execute(
const std::shared_ptr<Simulators::ISimulator> &sim,
59 size_t res = sim->Measure(qubits);
61 for (
size_t qi = 0; res && qi < qubits.size(); ++qi) {
63 (resetTargets.size() <= qi ? 1 : (resetTargets[qi] ? 0 : 1))) {
64 xgate.SetQubit(qubits[qi]);
65 xgate.Execute(sim, state);
90 const std::vector<bool> &resetTgts = {}) {
92 resetTargets = resetTgts;
118 std::shared_ptr<IOperation<Time>>
Clone()
const override {
119 return std::make_shared<Reset<Time>>(
142 std::shared_ptr<IOperation<Time>>
143 Remap(
const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
144 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
146 auto newOp = this->
Clone();
148 for (
size_t i = 0; i < qubits.size(); ++i) {
149 const auto qubitit = qubitsMap.find(qubits[i]);
150 if (qubitit != qubitsMap.end())
151 std::static_pointer_cast<Reset<Time>>(newOp)->
SetQubit(i,
178 if (index < qubits.size())
179 qubits[index] = qubit;
184 std::vector<bool> resetTargets;
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 SetQubits(const Types::qubits_vector &qs, const std::vector< bool > &resetTgts={})
Set the qubits to reset and the values to reset them to.
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Reset(const Types::qubits_vector &qubits={}, Time delay=0, const std::vector< bool > &resetTargets={})
Construct a new Reset object.
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the operation.
void SetQubit(size_t index, Types::qubit_t qubit)
Set the qubit to reset.
OperationType GetType() const override
Get the type of operation.
const Types::qubits_vector & GetQubits() const
Get the qubits to reset.
bool IsClifford() const override
Checks if the operation is a Clifford one.
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.
const std::vector< bool > & GetResetTargets() const
Get the values to reset the qubits to.
Types::qubits_vector AffectedQubits() const override
Get the qubits affected by this operation.
OperationType
The type of operations.
@ kReset
reset, no result in 'state', just apply measurement, then apply not on all qubits that were measured ...
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
uint_fast64_t qubit_t
The type of a qubit.