Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Converter.h
Go to the documentation of this file.
1
15#pragma once
16
17#ifndef _CIRCUITCONVERTER_H_
18#define _CIRCUITCONVERTER_H_
19
20#include "Circuit.h"
21
22namespace Circuits {
23
33template <typename Time = Types::time_type>
34class Converter {
35 public:
44 static std::shared_ptr<Circuit<Time>> ToCircuit(
45 const std::shared_ptr<IOperation<Time>> &operation) {
46 if (!operation || operation->GetType() != OperationType::kComposite)
47 return nullptr;
48
49 return Convert<Circuit<Time>>(operation);
50 }
51
60 static std::shared_ptr<IQuantumGate<Time>> ToQuantumGate(
61 const std::shared_ptr<IOperation<Time>> &operation) {
62 if (!operation || operation->GetType() != OperationType::kGate)
63 return nullptr;
64
65 return Convert<IQuantumGate<Time>>(operation);
66 }
67
76 static std::shared_ptr<SingleQubitGate<Time>> ToSingleQubitGate(
77 const std::shared_ptr<IOperation<Time>> &operation) {
78 auto op = ToQuantumGate(operation);
79 if (!op || op->GetNumQubits() != 1) return nullptr;
80
81 return Convert<SingleQubitGate<Time>>(operation);
82 }
83
92 static std::shared_ptr<TwoQubitsGate<Time>> ToTwoQubitsGate(
93 const std::shared_ptr<IOperation<Time>> &operation) {
94 auto op = ToQuantumGate(operation);
95 if (!op || op->GetNumQubits() != 2) return nullptr;
96
97 return Convert<TwoQubitsGate<Time>>(operation);
98 }
99
108 static std::shared_ptr<ThreeQubitsGate<Time>> ToThreeQubitsGate(
109 const std::shared_ptr<IOperation<Time>> &operation) {
110 auto op = ToQuantumGate(operation);
111 if (!op || op->GetNumQubits() != 3) return nullptr;
112
113 return Convert<ThreeQubitsGate<Time>>(operation);
114 }
115
116 // TODO: Add for specific quantum gates
117
126 static std::shared_ptr<Random<Time>> ToRandom(
127 const std::shared_ptr<IOperation<Time>> &operation) {
128 if (!operation || operation->GetType() != OperationType::kRandomGen)
129 return nullptr;
130
131 return Convert<Random<Time>>(operation);
132 }
133
142 static std::shared_ptr<Reset<Time>> ToReset(
143 const std::shared_ptr<IOperation<Time>> &operation) {
144 if (!operation || operation->GetType() != OperationType::kReset)
145 return nullptr;
146
147 return Convert<Reset<Time>>(operation);
148 }
149
158 static std::shared_ptr<MeasurementOperation<Time>> ToMeasurement(
159 const std::shared_ptr<IOperation<Time>> &operation) {
160 if (!operation || operation->GetType() != OperationType::kMeasurement)
161 return nullptr;
162
163 return Convert<MeasurementOperation<Time>>(operation);
164 }
165
174 static std::shared_ptr<ConditionalGate<Time>> ToConditionalGate(
175 const std::shared_ptr<IOperation<Time>> &operation) {
176 if (!operation || operation->GetType() != OperationType::kConditionalGate)
177 return nullptr;
178
179 return Convert<ConditionalGate<Time>>(operation);
180 }
181
190 static std::shared_ptr<ConditionalMeasurement<Time>> ToConditionalMeasurement(
191 const std::shared_ptr<IOperation<Time>> &operation) {
192 if (!operation ||
193 operation->GetType() != OperationType::kConditionalMeasurement)
194 return nullptr;
195
196 return Convert<ConditionalMeasurement<Time>>(operation);
197 }
198
207 static std::shared_ptr<ConditionalRandomGen<Time>> ToConditionalRandom(
208 const std::shared_ptr<IOperation<Time>> &operation) {
209 if (!operation ||
210 operation->GetType() != OperationType::kConditionalRandomGen)
211 return nullptr;
212
213 return Convert<ConditionalRandomGen<Time>>(operation);
214 }
215
224 static std::shared_ptr<EqualCondition> ToEqualCondition(
225 const std::shared_ptr<ICondition> &cond) {
226 if (!cond) return nullptr;
227
228 return std::static_pointer_cast<EqualCondition>(cond);
229 }
230
231 private:
232 template <typename T>
233 static std::shared_ptr<T> Convert(
234 const std::shared_ptr<IOperation<Time>> &operation) {
235 return std::static_pointer_cast<T>(operation);
236 }
237};
238
239} // namespace Circuits
240
241#endif
The converter class.
Definition Converter.h:34
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:190
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:142
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:174
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:60
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:92
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:126
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:207
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:108
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:224
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:44
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:158
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:76
The operation interface.
Definition Operations.h:357
@ kConditionalGate
conditional gate, similar with gate, but conditioned on something from 'OperationState'
@ kComposite
a composite operation, contains other operations - should not be used in the beginning,...
@ kRandomGen
random classical bit generator, result in 'OperationState'
@ kConditionalRandomGen
conditional random generator, similar with random gen, but conditioned on something from 'OperationSt...
@ kConditionalMeasurement
conditional measurement, similar with measurement, but conditioned on something from 'OperationState'
@ kMeasurement
measurement, result in 'OperationState'
@ kGate
the usual quantum gate, result stays in simulator's state
@ kReset
reset, no result in 'state', just apply measurement, then apply not on all qubits that were measured ...