32 operator std::string()
const {
33 return declType +
" " +
id +
"[" + std::to_string(
index) +
"]";
43 template <
typename,
typename>
48 template <
typename ID,
typename IND>
63 boost::fusion::vector<std::string, std::vector<Expression>,
MixedListType>;
64using GatecallType = std::variant<SimpleGatecallType, ExpGatecallType>;
67 boost::fusion::vector<std::vector<Expression>,
ArgumentType>;
70using UopType = std::variant<UGateCallType, CXGateCallType, GatecallType>;
107 boost::fusion::vector<std::vector<std::string>, double,
108 std::vector<std::string>, std::vector<StatementType>>;
111using MeasureType = boost::fusion::vector<ArgumentType, ArgumentType>;
115using CondOpType = boost::fusion::vector<std::string, int, QopType>;
118 boost::fusion::vector<std::string, std::vector<std::string>,
119 std::vector<std::string>>;
123 boost::fusion::vector<std::string, std::vector<std::string>,
124 std::vector<std::string>>;
132 std::unordered_map<std::string, IndexedId> &creg_map,
135 id_copy.
base = counter;
137 counter +=
static_cast<int>(std::round(id_copy.
Eval()));
139 creg_map[id_copy.
id] = id_copy;
155 std::unordered_map<std::string, IndexedId> &qreg_map,
158 id_copy.
base = counter;
160 counter +=
static_cast<int>(std::round(id_copy.
Eval()));
161 qreg_map[id_copy.
id] = id_copy;
211 const std::unordered_map<std::string, IndexedId> &creg_map,
212 const std::unordered_map<std::string, IndexedId> &qreg_map)
const {
220 if (std::holds_alternative<IndexedId>(arg1)) {
221 IndexedId indexedId = std::get<IndexedId>(arg1);
222 auto it = qreg_map.find(indexedId.
id);
223 if (it != qreg_map.end()) {
224 int base = it->second.base;
227 }
else if (std::holds_alternative<std::string>(arg1)) {
228 std::string
id = std::get<std::string>(arg1);
229 auto it = qreg_map.find(
id);
230 if (it != qreg_map.end()) {
231 int base = it->second.base;
232 int size =
static_cast<int>(std::round(it->second.Eval()));
233 for (
int i = 0; i < size; ++i) stmt.
qubits.push_back(base + i);
241 if (std::holds_alternative<IndexedId>(arg2)) {
242 IndexedId indexedId = std::get<IndexedId>(arg2);
243 auto it = creg_map.find(indexedId.
id);
244 if (it != creg_map.end()) {
245 int base = it->second.base;
248 }
else if (std::holds_alternative<std::string>(arg2)) {
249 std::string
id = std::get<std::string>(arg2);
250 auto it = creg_map.find(
id);
251 if (it != creg_map.end()) {
252 int base = it->second.base;
253 int size =
static_cast<int>(std::round(it->second.Eval()));
254 for (
int i = 0; i < size; ++i) stmt.
cbits.push_back(base + i);
271 const std::unordered_map<std::string, IndexedId> &qreg_map)
const {
277 if (std::holds_alternative<IndexedId>(reset)) {
278 IndexedId indexedId = std::get<IndexedId>(reset);
279 auto it = qreg_map.find(indexedId.
id);
280 if (it != qreg_map.end()) {
281 int base = it->second.base;
284 }
else if (std::holds_alternative<std::string>(reset)) {
285 std::string
id = std::get<std::string>(reset);
286 auto it = qreg_map.find(
id);
287 if (it != qreg_map.end()) {
288 int base = it->second.base;
289 int size =
static_cast<int>(std::round(it->second.Eval()));
290 for (
int i = 0; i < size; ++i) stmt.
qubits.push_back(base + i);
307 const std::unordered_map<std::string, IndexedId> &qreg_map)
const {
310 std::set<int> qubit_set;
312 for (
const auto &b : barrier) {
315 if (std::holds_alternative<IndexedId>(b)) {
316 IndexedId indexedId = std::get<IndexedId>(b);
317 auto it = qreg_map.find(indexedId.
id);
318 if (it != qreg_map.end()) {
319 int base = it->second.base;
320 qubit_set.insert(base + indexedId.
index);
322 }
else if (std::holds_alternative<std::string>(b)) {
323 std::string
id = std::get<std::string>(b);
324 auto it = qreg_map.find(
id);
325 if (it != qreg_map.end()) {
326 int base = it->second.base;
327 int size =
static_cast<int>(std::round(it->second.Eval()));
328 for (
int i = 0; i < size; ++i) qubit_set.insert(base + i);
333 stmt.
qubits.assign(qubit_set.begin(), qubit_set.end());
348 std::unordered_map<std::string, StatementType> &opaqueGates,
349 const std::unordered_map<std::string, IndexedId> &qreg_map)
const {
353 std::string gateName = boost::fusion::at_c<0>(opaqueDecl);
358 const std::vector<std::string> ¶ms = boost::fusion::at_c<1>(opaqueDecl);
359 const std::vector<std::string> &args = boost::fusion::at_c<2>(opaqueDecl);
365 opaqueGates[gateName] = stmt;
379 const boost::fusion::vector<
GateDeclType, std::vector<GateDeclOpType>>
381 std::unordered_map<std::string, StatementType> &definedGates)
const {
385 const GateDeclType &declInfo = boost::fusion::at_c<0>(gateDecl);
387 const std::string &gateName = boost::fusion::at_c<0>(declInfo);
388 const std::vector<std::string> ¶ms = boost::fusion::at_c<1>(declInfo);
389 const std::vector<std::string> &args = boost::fusion::at_c<2>(declInfo);
392 throw std::invalid_argument(
393 "Gate declaration must have at least one qubit argument: " +
395 else if (definedGates.find(gateName) !=
401 throw std::invalid_argument(
"Gate already defined: " + gateName);
407 const std::vector<GateDeclOpType> &declOps =
408 boost::fusion::at_c<1>(gateDecl);
410 for (
const auto &op : declOps) {
411 if (std::holds_alternative<UopType>(op)) {
412 const UopType &uop = std::get<UopType>(op);
422 definedGates[gateName] = stmt;
IndexedId(const std::string &id, int index)
QuantumGateType
The type of quantum gates.
std::vector< std::string > SimpleBarrierType
std::variant< std::string, IndexedId > ArgumentType
boost::fusion::vector< std::string, MixedListType > SimpleGatecallType
QoperationStatement StatementType
std::variant< double, int, std::string > SimpleExpType
MixedListType BarrierType
std::variant< UopType, SimpleBarrierType > GateDeclOpType
boost::fusion::vector< std::string, std::vector< std::string >, std::vector< std::string > > GateDeclType
phx::function< AddQregExpr > AddQreg
std::variant< SimpleGatecallType, ExpGatecallType > GatecallType
boost::fusion::vector< std::vector< Expression >, ArgumentType > UGateCallType
phx::function< MakeIndexedIdExpression > MakeIndexedId
std::variant< UGateCallType, CXGateCallType, GatecallType > UopType
phx::function< AddCommentExpr > AddComment
boost::fusion::vector< std::string, int, QopType > CondOpType
boost::fusion::vector< std::string, std::vector< std::string >, std::vector< std::string > > OpaqueDeclType
phx::function< AddDeclarationExpr > AddDeclaration
phx::function< AddBarrierExpr > AddBarrier
boost::fusion::vector< std::string, std::vector< Expression >, MixedListType > ExpGatecallType
phx::function< AddCregExpr > AddCreg
phx::function< AddOpaqueDeclExpr > AddOpaqueDecl
boost::fusion::vector< ArgumentType, ArgumentType > MeasureType
boost::fusion::vector< ArgumentType, ArgumentType > CXGateCallType
phx::function< AddMeasureExpr > AddMeasure
boost::fusion::vector< std::vector< std::string >, double, std::vector< std::string >, std::vector< StatementType > > ProgramType
phx::function< AddGateDeclExpr > AddGateDecl
std::vector< ArgumentType > MixedListType
phx::function< AddResetExpr > AddReset
QoperationStatement operator()(const BarrierType &barrier, const std::unordered_map< std::string, IndexedId > &qreg_map) const
IndexedId operator()(int &counter, std::unordered_map< std::string, IndexedId > &creg_map, const IndexedId &id) const
QoperationStatement operator()(const IndexedId &id) const
QoperationStatement operator()(const boost::fusion::vector< GateDeclType, std::vector< GateDeclOpType > > &gateDecl, std::unordered_map< std::string, StatementType > &definedGates) const
QoperationStatement operator()(const MeasureType &measure, const std::unordered_map< std::string, IndexedId > &creg_map, const std::unordered_map< std::string, IndexedId > &qreg_map) const
QoperationStatement operator()(const OpaqueDeclType &opaqueDecl, std::unordered_map< std::string, StatementType > &opaqueGates, const std::unordered_map< std::string, IndexedId > &qreg_map) const
IndexedId operator()(int &counter, std::unordered_map< std::string, IndexedId > &qreg_map, const IndexedId &id) const
QoperationStatement operator()(const ResetType &reset, const std::unordered_map< std::string, IndexedId > &qreg_map) const
IndexedId operator()(const ID &id, IND index) const
std::vector< UopType > declOps
std::vector< std::string > qubitsDecl
std::vector< double > parameters
std::vector< std::string > paramsDecl
std::vector< int > qubits
Circuits::QuantumGateType gateType