Maestro 0.3.1
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 <cmath>
13#include <stdexcept>
14#include "Operations.h"
15
16namespace Circuits {
17
29template <typename Time = Types::time_type>
30class Delay : public IOperation<Time> {
31 public:
37 Delay(Types::qubit_t qubit = 0, Time duration = 0)
38 : IOperation<Time>(duration), qubit_(qubit) {
39 ValidateDuration(duration);
40 }
41
47 void Execute(const std::shared_ptr<Simulators::ISimulator> &sim,
48 OperationState &state) const override {
49 (void)sim;
50 (void)state;
51 }
52
56 OperationType GetType() const override { return OperationType::kDelay; }
57
61 Types::qubits_vector AffectedQubits() const override { return {qubit_}; }
62
66 Types::qubit_t GetQubit() const { return qubit_; }
67
71 void SetQubit(Types::qubit_t q) { qubit_ = q; }
72
76 Time GetDuration() const { return IOperation<Time>::GetDelay(); }
77
81 void SetDuration(Time d) {
82 ValidateDuration(d);
84 }
85
89 void SetDelay(Time d) override { SetDuration(d); }
90
91 bool CanAffectQuantumState() const override { return false; }
92 bool IsClifford() const override { return true; }
93
94 std::shared_ptr<IOperation<Time>> Clone() const override {
95 return std::make_shared<Delay<Time>>(qubit_, GetDuration());
96 }
97
98 std::shared_ptr<IOperation<Time>> Remap(
99 const std::unordered_map<Types::qubit_t, Types::qubit_t> &qubitsMap,
100 const std::unordered_map<Types::qubit_t, Types::qubit_t> &bitsMap = {})
101 const override {
102 (void)bitsMap;
103 Types::qubit_t mappedQubit = qubit_;
104 const auto it = qubitsMap.find(qubit_);
105 if (it != qubitsMap.end()) mappedQubit = it->second;
106 return std::make_shared<Delay<Time>>(mappedQubit, GetDuration());
107 }
108
109 private:
110 static void ValidateDuration(Time d) {
111 if (std::isnan(static_cast<double>(d)) ||
112 std::isinf(static_cast<double>(d)) ||
113 d < 0) {
114 throw std::invalid_argument("Delay duration must be finite and nonnegative");
115 }
116 }
117
118 Types::qubit_t qubit_ = 0;
119};
120
121} // namespace Circuits
122
123#endif // _CIRCUIT_DELAY_H_
Time GetDuration() const
Get the delay duration.
Definition Delay.h:76
bool IsClifford() const override
Checks if the operation is a Clifford one.
Definition Delay.h:92
std::shared_ptr< IOperation< Time > > Clone() const override
Get a shared pointer to a clone of this object.
Definition Delay.h:94
Types::qubits_vector AffectedQubits() const override
Return the affected qubits.
Definition Delay.h:61
void SetDelay(Time d) override
Set the delay of the operation.
Definition Delay.h:89
Delay(Types::qubit_t qubit=0, Time duration=0)
Construct a new Delay object.
Definition Delay.h:37
void Execute(const std::shared_ptr< Simulators::ISimulator > &sim, OperationState &state) const override
Execute the delay operation on the simulator.
Definition Delay.h:47
OperationType GetType() const override
Get the operation type.
Definition Delay.h:56
void SetQubit(Types::qubit_t q)
Set the target qubit.
Definition Delay.h:71
bool CanAffectQuantumState() const override
Find if the operation can affect the quantum state.
Definition Delay.h:91
Types::qubit_t GetQubit() const
Get the target qubit.
Definition Delay.h:66
void SetDuration(Time d)
Set the delay duration.
Definition Delay.h:81
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:98
Time GetDelay() const
Get the delay of the operation.
Definition Operations.h:501
virtual void SetDelay(Time d)
Set the delay of the operation.
Definition Operations.h:509
IOperation(Types::time_type delay=0)
Definition Operations.h:368
The state class that stores the classical state of a quantum circuit execution.
Definition Operations.h:65
OperationType
The type of operations.
Definition Operations.h:27
@ kDelay
a delay or idle period on one or more qubits
Definition Operations.h:48
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
Definition Types.h:22
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:21