Maestro 0.2.5
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Converter.h
Go to the documentation of this file.
1
16#pragma once
17
18#ifndef _CIRCUITCONVERTER_H_
19#define _CIRCUITCONVERTER_H_
20
21#include "Circuit.h"
22
23namespace Circuits {
24
34template <typename Time = Types::time_type>
35class Converter {
36 public:
45 static std::shared_ptr<Circuit<Time>> ToCircuit(
46 const std::shared_ptr<IOperation<Time>> &operation) {
47 if (!operation || operation->GetType() != OperationType::kComposite)
48 return nullptr;
49
50 return Convert<Circuit<Time>>(operation);
51 }
52
61 static std::shared_ptr<IQuantumGate<Time>> ToQuantumGate(
62 const std::shared_ptr<IOperation<Time>> &operation) {
63 if (!operation || operation->GetType() != OperationType::kGate)
64 return nullptr;
65
66 return Convert<IQuantumGate<Time>>(operation);
67 }
68
77 static std::shared_ptr<SingleQubitGate<Time>> ToSingleQubitGate(
78 const std::shared_ptr<IOperation<Time>> &operation) {
79 auto op = ToQuantumGate(operation);
80 if (!op || op->GetNumQubits() != 1) return nullptr;
81
82 return Convert<SingleQubitGate<Time>>(operation);
83 }
84
93 static std::shared_ptr<TwoQubitsGate<Time>> ToTwoQubitsGate(
94 const std::shared_ptr<IOperation<Time>> &operation) {
95 auto op = ToQuantumGate(operation);
96 if (!op || op->GetNumQubits() != 2) return nullptr;
97
98 return Convert<TwoQubitsGate<Time>>(operation);
99 }
100
109 static std::shared_ptr<ThreeQubitsGate<Time>> ToThreeQubitsGate(
110 const std::shared_ptr<IOperation<Time>> &operation) {
111 auto op = ToQuantumGate(operation);
112 if (!op || op->GetNumQubits() != 3) return nullptr;
113
114 return Convert<ThreeQubitsGate<Time>>(operation);
115 }
116
117 // TODO: Add for specific quantum gates
118
127 static std::shared_ptr<Random<Time>> ToRandom(
128 const std::shared_ptr<IOperation<Time>> &operation) {
129 if (!operation || operation->GetType() != OperationType::kRandomGen)
130 return nullptr;
131
132 return Convert<Random<Time>>(operation);
133 }
134
143 static std::shared_ptr<Reset<Time>> ToReset(
144 const std::shared_ptr<IOperation<Time>> &operation) {
145 if (!operation || operation->GetType() != OperationType::kReset)
146 return nullptr;
147
148 return Convert<Reset<Time>>(operation);
149 }
150
159 static std::shared_ptr<MeasurementOperation<Time>> ToMeasurement(
160 const std::shared_ptr<IOperation<Time>> &operation) {
161 if (!operation || operation->GetType() != OperationType::kMeasurement)
162 return nullptr;
163
164 return Convert<MeasurementOperation<Time>>(operation);
165 }
166
175 static std::shared_ptr<ConditionalGate<Time>> ToConditionalGate(
176 const std::shared_ptr<IOperation<Time>> &operation) {
177 if (!operation || operation->GetType() != OperationType::kConditionalGate)
178 return nullptr;
179
180 return Convert<ConditionalGate<Time>>(operation);
181 }
182
191 static std::shared_ptr<ConditionalMeasurement<Time>> ToConditionalMeasurement(
192 const std::shared_ptr<IOperation<Time>> &operation) {
193 if (!operation ||
194 operation->GetType() != OperationType::kConditionalMeasurement)
195 return nullptr;
196
197 return Convert<ConditionalMeasurement<Time>>(operation);
198 }
199
208 static std::shared_ptr<ConditionalRandomGen<Time>> ToConditionalRandom(
209 const std::shared_ptr<IOperation<Time>> &operation) {
210 if (!operation ||
211 operation->GetType() != OperationType::kConditionalRandomGen)
212 return nullptr;
213
214 return Convert<ConditionalRandomGen<Time>>(operation);
215 }
216
225 static std::shared_ptr<EqualCondition> ToEqualCondition(
226 const std::shared_ptr<ICondition> &cond) {
227 if (!cond) return nullptr;
228
229 return std::static_pointer_cast<EqualCondition>(cond);
230 }
231
232 private:
233 template <typename T>
234 static std::shared_ptr<T> Convert(
235 const std::shared_ptr<IOperation<Time>> &operation) {
236 return std::static_pointer_cast<T>(operation);
237 }
238};
239
240} // namespace Circuits
241
242#endif
The converter class.
Definition Converter.h:35
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:191
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:143
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:175
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:61
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:93
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:127
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:208
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:109
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:225
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:45
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:159
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:77
The operation interface.
Definition Operations.h:358
@ 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 ...