Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Converter.h
Go to the documentation of this file.
1
15
16#pragma once
17
18#ifndef _CIRCUITCONVERTER_H_
19#define _CIRCUITCONVERTER_H_
20
21#include "Circuit.h"
22
23namespace Circuits
24{
25
35template <typename Time = Types::time_type> class Converter
36{
37 public:
46 static std::shared_ptr<Circuit<Time>> ToCircuit(const std::shared_ptr<IOperation<Time>> &operation)
47 {
48 if (!operation || operation->GetType() != OperationType::kComposite)
49 return nullptr;
50
51 return Convert<Circuit<Time>>(operation);
52 }
53
62 static std::shared_ptr<IQuantumGate<Time>> ToQuantumGate(const std::shared_ptr<IOperation<Time>> &operation)
63 {
64 if (!operation || operation->GetType() != OperationType::kGate)
65 return nullptr;
66
67 return Convert<IQuantumGate<Time>>(operation);
68 }
69
78 static std::shared_ptr<SingleQubitGate<Time>> ToSingleQubitGate(const std::shared_ptr<IOperation<Time>> &operation)
79 {
80 auto op = ToQuantumGate(operation);
81 if (!op || op->GetNumQubits() != 1)
82 return nullptr;
83
84 return Convert<SingleQubitGate<Time>>(operation);
85 }
86
95 static std::shared_ptr<TwoQubitsGate<Time>> ToTwoQubitsGate(const std::shared_ptr<IOperation<Time>> &operation)
96 {
97 auto op = ToQuantumGate(operation);
98 if (!op || op->GetNumQubits() != 2)
99 return nullptr;
100
101 return Convert<TwoQubitsGate<Time>>(operation);
102 }
103
112 static std::shared_ptr<ThreeQubitsGate<Time>> ToThreeQubitsGate(const std::shared_ptr<IOperation<Time>> &operation)
113 {
114 auto op = ToQuantumGate(operation);
115 if (!op || op->GetNumQubits() != 3)
116 return nullptr;
117
118 return Convert<ThreeQubitsGate<Time>>(operation);
119 }
120
121 // TODO: Add for specific quantum gates
122
131 static std::shared_ptr<Random<Time>> ToRandom(const std::shared_ptr<IOperation<Time>> &operation)
132 {
133 if (!operation || operation->GetType() != OperationType::kRandomGen)
134 return nullptr;
135
136 return Convert<Random<Time>>(operation);
137 }
138
147 static std::shared_ptr<Reset<Time>> ToReset(const std::shared_ptr<IOperation<Time>> &operation)
148 {
149 if (!operation || operation->GetType() != OperationType::kReset)
150 return nullptr;
151
152 return Convert<Reset<Time>>(operation);
153 }
154
163 static std::shared_ptr<MeasurementOperation<Time>> ToMeasurement(const std::shared_ptr<IOperation<Time>> &operation)
164 {
165 if (!operation || operation->GetType() != OperationType::kMeasurement)
166 return nullptr;
167
168 return Convert<MeasurementOperation<Time>>(operation);
169 }
170
179 static std::shared_ptr<ConditionalGate<Time>> ToConditionalGate(const std::shared_ptr<IOperation<Time>> &operation)
180 {
181 if (!operation || operation->GetType() != OperationType::kConditionalGate)
182 return nullptr;
183
184 return Convert<ConditionalGate<Time>>(operation);
185 }
186
195 static std::shared_ptr<ConditionalMeasurement<Time>> ToConditionalMeasurement(const std::shared_ptr<IOperation<Time>> &operation)
196 {
197 if (!operation || operation->GetType() != OperationType::kConditionalMeasurement)
198 return nullptr;
199
200 return Convert<ConditionalMeasurement<Time>>(operation);
201 }
202
211 static std::shared_ptr<ConditionalRandomGen<Time>> ToConditionalRandom(const std::shared_ptr<IOperation<Time>> &operation)
212 {
213 if (!operation || operation->GetType() != OperationType::kConditionalRandomGen)
214 return nullptr;
215
216 return Convert<ConditionalRandomGen<Time>>(operation);
217 }
218
227 static std::shared_ptr<EqualCondition> ToEqualCondition(const std::shared_ptr<ICondition> &cond)
228 {
229 if (!cond)
230 return nullptr;
231
232 return std::static_pointer_cast<EqualCondition>(cond);
233 }
234
235 private:
236 template <typename T> static std::shared_ptr<T> Convert(const std::shared_ptr<IOperation<Time>> &operation)
237 {
238 return std::static_pointer_cast<T>(operation);
239 }
240};
241
242} // namespace Circuits
243
244#endif
The converter class.
Definition Converter.h:36
static std::shared_ptr< ConditionalMeasurement< Time > > ToConditionalMeasurement(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Conditional...
Definition Converter.h:195
static std::shared_ptr< Reset< Time > > ToReset(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Reset class...
Definition Converter.h:147
static std::shared_ptr< ConditionalGate< Time > > ToConditionalGate(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Conditional...
Definition Converter.h:179
static std::shared_ptr< IQuantumGate< Time > > ToQuantumGate(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the QuantumGate...
Definition Converter.h:62
static std::shared_ptr< TwoQubitsGate< Time > > ToTwoQubitsGate(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the TwoQubitsGa...
Definition Converter.h:95
static std::shared_ptr< Random< Time > > ToRandom(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Random clas...
Definition Converter.h:131
static std::shared_ptr< ConditionalRandomGen< Time > > ToConditionalRandom(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Conditional...
Definition Converter.h:211
static std::shared_ptr< ThreeQubitsGate< Time > > ToThreeQubitsGate(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the ThreeQubits...
Definition Converter.h:112
static std::shared_ptr< EqualCondition > ToEqualCondition(const std::shared_ptr< ICondition > &cond)
Converts a smart pointer to the ICondition interface/base class to a smart pointer to the EqualCondit...
Definition Converter.h:227
static std::shared_ptr< Circuit< Time > > ToCircuit(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Circuit cla...
Definition Converter.h:46
static std::shared_ptr< MeasurementOperation< Time > > ToMeasurement(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the Measurement...
Definition Converter.h:163
static std::shared_ptr< SingleQubitGate< Time > > ToSingleQubitGate(const std::shared_ptr< IOperation< Time > > &operation)
Converts a smart pointer to the IOperation interface/base class to a smart pointer to the SingleQubit...
Definition Converter.h:78
The operation interface.
Definition Operations.h:402
@ kConditionalGate
conditional gate, similar with gate, but conditioned on something from 'OperationState'
Definition Operations.h:33
@ kComposite
a composite operation, contains other operations - should not be used in the beginning,...
Definition Operations.h:46
@ kRandomGen
random classical bit generator, result in 'OperationState'
Definition Operations.h:32
@ kConditionalRandomGen
conditional random generator, similar with random gen, but conditioned on something from 'OperationSt...
Definition Operations.h:38
@ kConditionalMeasurement
conditional measurement, similar with measurement, but conditioned on something from 'OperationState'
Definition Operations.h:35
@ kMeasurement
measurement, result in 'OperationState'
Definition Operations.h:31
@ kGate
the usual quantum gate, result stays in simulator's state
Definition Operations.h:30
@ kReset
reset, no result in 'state', just apply measurement, then apply not on all qubits that were measured ...
Definition Operations.h:41