2 #ifndef AST_SEMANTIC_HPP 21 if (!qasm_str_input) {
22 throw std::invalid_argument(
"received null string");
24 new_to_old::handle_parse_result(
33 throw std::invalid_argument(
"received null file pointer");
35 new_to_old::handle_parse_result(
61 if (subcircuit.numberIterations() < 1)
63 std::string base_error_message(
"Iteration count invalid for subcircuit");
64 std::string entire_error_message = base_error_message +
65 " " + subcircuit.nameSubCircuit() +
67 std::to_string(subcircuit.getLineNumber());
68 throw std::runtime_error(entire_error_message);
70 for (
auto ops_cluster : subcircuit.getOperationsCluster())
72 int linenumber = ops_cluster->getLineNumber();
73 for (
auto ops : ops_cluster->getOperations())
81 throw std::runtime_error(std::string(
"Qasm file invalid\n"));
87 std::string type_ = op.
getType();
88 if (type_ ==
"measure_parity")
92 else if (type_ ==
"u")
96 else if (type_ ==
"cnot" || type_ ==
"cz" || type_ ==
"swap" || type_ ==
"cr" || type_ ==
"crk")
100 else if (type_ ==
"toffoli")
104 else if (type_ ==
"measure_all")
108 else if (type_ ==
"reset-averaging")
112 else if (type_ ==
"skip" || type_ ==
"wait" || type_ ==
"display" || type_ ==
"display_binary" || type_ ==
"not" || type_ ==
"load_state")
125 throw std::runtime_error(std::string(
"Operation invalid.") + std::string(
" Line: ") + std::to_string(linenumber));
129 throw std::runtime_error(std::string(
"Operation invalid. ") +
"Line " + std::to_string(linenumber));
139 throw std::runtime_error(std::string(
"Qubit indices exceed the number in qubit register. Line: ")
140 + std::to_string(linenumber));
145 int linenumber)
const 150 if (qubits1.getSelectedQubits().getIndices().size() ==
151 qubits2.getSelectedQubits().getIndices().size())
164 std::string base_error_message(
"Matrix is not unitary. Line: ");
165 std::string entire_error_message = base_error_message +
166 std::to_string(linenumber);
167 throw std::runtime_error(entire_error_message);
169 result *= resultlist;
212 std::string base_error_message(
"Mismatch in the qubit pair sizes. Line: ");
213 std::string entire_error_message = base_error_message +
214 std::to_string(linenumber);
215 throw std::runtime_error(entire_error_message);
217 result *= resultlist;
229 std::string base_error_message(
"Mismatch in the qubit pair sizes. Line: ");
230 std::string entire_error_message = base_error_message +
231 std::to_string(linenumber);
232 throw std::runtime_error(entire_error_message);
234 result *= resultlist;
242 int resultlist =
checkQubitList(measureParityProperties.first.first, linenumber);
243 resultlist +=
checkQubitList(measureParityProperties.first.second, linenumber);
244 result *= resultlist;
int checkWaitDisplayNot(const compiler::Operation &op, int linenumber) const
compiler::QasmRepresentation qasm_
QasmSemanticChecker(FILE *qasm_file)
int checkTwoQubits(const compiler::Operation &op, int linenumber) const
int checkQubitListLength(const compiler::Qubits &qubits1, const compiler::Qubits &qubits2, int linenumber) const
SubCircuits & getSubCircuits()
const compiler::QasmRepresentation & getQasmRepresentation() const
const std::pair< Qubits, std::pair< Qubits, Qubits > > & getToffoliQubitPairs() const
int checkUnitaryGate(const compiler::Operation &op, int linenumber) const
const NumericalIdentifiers & getSelectedQubits() const
const Qubits & getQubitsInvolved() const
const std::vector< SubCircuit > & getAllSubCircuits() const
const std::pair< std::pair< Qubits, Qubits >, std::pair< std::string, std::string > > getMeasureParityQubitsAndAxis() const
Namespace used for most of the original API.
int checkMeasureParity(const compiler::Operation &op, int linenumber) const
int checkToffoli(const compiler::Operation &op, int linenumber) const
std::string getType() const
const std::pair< Qubits, Qubits > & getTwoQubitPairs() const
int checkQubitList(const compiler::Qubits &qubits, int linenumber) const
Contains the guts of the compatibility layer, parsing using Analyzer and converting the result to an ...
ParseResult parse_string(const std::string &data, const std::string &filename)
Parse the given string.
QasmSemanticChecker(const char *qasm_str_input)
int checkResetAveraging(const compiler::Operation &op, int linenumber) const
bool allQubitsBits() const
void checkQubits(compiler::Operation &op, int &result, int linenumber)
int checkMeasureAll(const compiler::Operation &op, int linenumber) const
const std::vector< size_t > & getIndices() const
ParseResult parse_file(const std::string &filename)
Parse the given file.
int checkSingleQubit(const compiler::Operation &op, int linenumber) const