Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Reset.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#ifndef _RESET_STATE_H_
17#define _RESET_STATE_H_
18
19#include "QuantumGates.h"
20
21namespace Circuits {
22
31template <typename Time = Types::time_type>
32class Reset : public IOperation<Time> {
33public:
43 Reset(const Types::qubits_vector &qubits = {}, Time delay = 0,
44 const std::vector<bool> &resetTargets = {})
45 : IOperation<Time>(delay), qubits(qubits), resetTargets(resetTargets) {}
46
57 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
58 OperationState &state) const override {
59 size_t res = sim->Measure(qubits);
60
61 for (size_t qi = 0; res && qi < qubits.size(); ++qi) {
62 if ((res & 1) ==
63 (resetTargets.size() <= qi ? 1 : (resetTargets[qi] ? 0 : 1))) {
64 xgate.SetQubit(qubits[qi]);
65 xgate.Execute(sim, state);
66 }
67
68 res >>= 1;
69 }
70 }
71
79 OperationType GetType() const override { return OperationType::kReset; }
80
90 const std::vector<bool> &resetTgts = {}) {
91 qubits = qs;
92 resetTargets = resetTgts;
93 }
94
101 const Types::qubits_vector &GetQubits() const { return qubits; }
102
110 const std::vector<bool> &GetResetTargets() const { return resetTargets; }
111
118 std::shared_ptr<IOperation<Time>> Clone() const override {
119 return std::make_shared<Reset<Time>>(
121 }
122
130 Types::qubits_vector AffectedQubits() const override { return qubits; }
131
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 = {})
145 const override {
146 auto newOp = this->Clone();
147
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,
152 qubitit->second);
153 }
154
155 return newOp;
156 }
157
167 bool IsClifford() const override { return true; }
168
169protected:
177 void SetQubit(size_t index, Types::qubit_t qubit) {
178 if (index < qubits.size())
179 qubits[index] = qubit;
180 }
181
182private:
183 Types::qubits_vector qubits;
184 std::vector<bool> resetTargets;
185 mutable XGate<Time> xgate;
187};
188
189} // namespace Circuits
190
191#endif // !_RESET_STATE_H_
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:500
IOperation(Types::time_type delay=0)
Definition Operations.h:369
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:62
void SetQubits(const Types::qubits_vector &qs, const std::vector< bool > &resetTgts={})
Set the qubits to reset and the values to reset them to.
Definition Reset.h:89
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Definition Reset.h:118
Reset(const Types::qubits_vector &qubits={}, Time delay=0, const std::vector< bool > &resetTargets={})
Construct a new Reset object.
Definition Reset.h:43
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the operation.
Definition Reset.h:57
void SetQubit(size_t index, Types::qubit_t qubit)
Set the qubit to reset.
Definition Reset.h:177
OperationType GetType() const override
Get the type of operation.
Definition Reset.h:79
const Types::qubits_vector & GetQubits() const
Get the qubits to reset.
Definition Reset.h:101
bool IsClifford() const override
Checks if the operation is a Clifford one.
Definition Reset.h:167
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.
Definition Reset.h:143
const std::vector< bool > & GetResetTargets() const
Get the values to reset the qubits to.
Definition Reset.h:110
Types::qubits_vector AffectedQubits() const override
Get the qubits affected by this operation.
Definition Reset.h:130
The X gate.
OperationType
The type of operations.
Definition Operations.h:26
@ kReset
reset, no result in 'state', just apply measurement, then apply not on all qubits that were measured ...
Definition Operations.h:38
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:21
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:20