Maestro 0.2.5
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
QasmCirc.h
Go to the documentation of this file.
1
12#pragma once
13
14#ifndef _QASMCIRC_H_
15#define _QASMCIRC_H_
16
17#include "qasm.h"
18
19namespace qasm {
20template <typename Time = Types::time_type>
22 public:
23 void clear() {
24 grammar.clear();
25 program.clear();
26 errorMessage.clear();
27 error = false;
28 }
29
30 std::shared_ptr<Circuits::Circuit<Time>> ParseAndTranslate(
31 const std::string &qasmInputStr) {
32 clear();
33
34 std::string qasmInput = qasmInputStr;
35
36 try {
37 auto it = qasmInput.begin();
38 if (boost::spirit::qi::phrase_parse(it, qasmInput.end(), grammar,
39 qasm::ascii::space, program)) {
40 if (it == qasmInput.end()) {
41 return program.ToCircuit<Time>(grammar.opaqueGates,
42 grammar.definedGates);
43 } else {
44 error = true;
45 errorMessage = "Error: Unparsed input remaining: '" +
46 std::string(it, qasmInput.end()) + "'";
47 }
48 } else {
49 error = true;
50 errorMessage = "Error: Parsing failed, unparsed input remaining: '" +
51 std::string(it, qasmInput.end()) + "'";
52 }
53 } catch (const std::exception &ex) {
54 error = true;
55 errorMessage = ex.what();
56 }
57
58 return nullptr;
59 }
60
61 bool Failed() const { return error; }
62
63 const std::string &GetErrorMessage() const { return errorMessage; }
64
65 double GetVersion() const { return program.version; }
66
67 const std::vector<std::string> &GetComments() const {
68 return program.comments;
69 }
70
71 const std::vector<std::string> &GetIncludes() const {
72 return program.includes;
73 }
74
75 protected:
76 qasm::QasmGrammar<> grammar;
78 std::string errorMessage;
79 bool error = false;
80};
81} // namespace qasm
82
83#endif //_QASMCIRC_H_
bool Failed() const
Definition QasmCirc.h:61
qasm::Program program
Definition QasmCirc.h:77
double GetVersion() const
Definition QasmCirc.h:65
const std::string & GetErrorMessage() const
Definition QasmCirc.h:63
const std::vector< std::string > & GetIncludes() const
Definition QasmCirc.h:71
std::string errorMessage
Definition QasmCirc.h:78
std::shared_ptr< Circuits::Circuit< Time > > ParseAndTranslate(const std::string &qasmInputStr)
Definition QasmCirc.h:30
const std::vector< std::string > & GetComments() const
Definition QasmCirc.h:67
qasm::QasmGrammar grammar
Definition QasmCirc.h:76
std::shared_ptr< Circuits::Circuit< Time > > ToCircuit(std::unordered_map< std::string, StatementType > &opaqueGates, std::unordered_map< std::string, StatementType > &definedGates) const
Definition SyntaxTree.h:579
std::vector< std::string > comments
Definition SyntaxTree.h:561
std::vector< std::string > includes
Definition SyntaxTree.h:562