Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Delay.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#ifndef _CIRCUIT_DELAY_H_
10#define _CIRCUIT_DELAY_H_
11
12#include "Operations.h"
13#include <cmath>
14#include <stdexcept>
15
16namespace Circuits
17{
18
30template <typename Time = Types::time_type> class Delay : public IOperation<Time>
31{
32 public:
38 Delay(Types::qubit_t qubit = 0, Time duration = 0) : IOperation<Time>(duration), qubit_(qubit)
39 {
40 ValidateDuration(duration);
41 }
42
48 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim, OperationState &state) const override
49 {
50 (void)sim;
51 (void)state;
52 }
53
57 OperationType GetType() const override
58 {
60 }
61
66 {
67 return {qubit_};
68 }
69
74 {
75 return qubit_;
76 }
77
82 {
83 qubit_ = q;
84 }
85
89 Time GetDuration() const
90 {
92 }
93
97 void SetDuration(Time d)
98 {
99 ValidateDuration(d);
101 }
102
106 void SetDelay(Time d) override
107 {
108 SetDuration(d);
109 }
110
111 bool CanAffectQuantumState() const override
112 {
113 return false;
114 }
115
116 bool IsClifford() const override
117 {
118 return true;
119 }
120
121 std::shared_ptr<IOperation<Time>> Clone() const override
122 {
123 return std::make_shared<Delay<Time>>(qubit_, GetDuration());
124 }
125
126 std::shared_ptr<IOperation<Time>> Remap(const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
127 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {}) const override
128 {
129 (void)bitsMap;
130 Types::qubit_t mappedQubit = qubit_;
131 const auto it = qubitsMap.find(qubit_);
132 if (it != qubitsMap.end())
133 mappedQubit = it->second;
134 return std::make_shared<Delay<Time>>(mappedQubit, GetDuration());
135 }
136
137 private:
138 static void ValidateDuration(Time d)
139 {
140 if (std::isnan(static_cast<double>(d)) || std::isinf(static_cast<double>(d)) || d < 0)
141 {
142 throw std::invalid_argument("Delay duration must be finite and nonnegative");
143 }
144 }
145
146 Types::qubit_t qubit_ = 0;
147};
148
149} // namespace Circuits
150
151#endif // _CIRCUIT_DELAY_H_
Time GetDuration() const
Get the delay duration.
Definition Delay.h:89
bool IsClifford() const override
Checks if the operation is a Clifford one.
Definition Delay.h:116
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Definition Delay.h:121
Types::qubits_vector AffectedQubits() const override
Return the affected qubits.
Definition Delay.h:65
void SetDelay(Time d) override
Set the delay of the operation.
Definition Delay.h:106
Delay(Types::qubit_t qubit=0, Time duration=0)
Construct a new Delay object.
Definition Delay.h:38
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the delay operation on the simulator.
Definition Delay.h:48
OperationType GetType() const override
Get the operation type.
Definition Delay.h:57
void SetQubit(Types::qubit_t q)
Set the target qubit.
Definition Delay.h:81
bool CanAffectQuantumState() const override
Find if the operation can affect the quantum state.
Definition Delay.h:111
Types::qubit_t GetQubit() const
Get the target qubit.
Definition Delay.h:73
void SetDuration(Time d)
Set the delay duration.
Definition Delay.h:97
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 Delay.h:126
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:546
virtual void SetDelay(Time d)
Set the delay of the operation.
Definition Operations.h:557
IOperation(Types::time_type delay=0)
Definition Operations.h:410
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:68
OperationType
The type of operations.
Definition Operations.h:29
@ kDelay
a delay or idle period on one or more qubits
Definition Operations.h:50
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:24
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:23