diff --git a/src/quartz/parser/qasm_parser.cpp b/src/quartz/parser/qasm_parser.cpp index 5c81c78e..372394b3 100644 --- a/src/quartz/parser/qasm_parser.cpp +++ b/src/quartz/parser/qasm_parser.cpp @@ -505,4 +505,6 @@ int QubitParser::finalize() { return num_qubits; } +bool QubitParser::is_finalized() { return finalized_; } + } // namespace quartz diff --git a/src/quartz/parser/qasm_parser.h b/src/quartz/parser/qasm_parser.h index e6534bf7..21e975de 100644 --- a/src/quartz/parser/qasm_parser.h +++ b/src/quartz/parser/qasm_parser.h @@ -248,6 +248,11 @@ class QubitParser { */ int finalize(); + /** + * @return If finalize() has been called. + */ + [[nodiscard]] bool is_finalized(); + private: /** * Implementation details for parse_qasm2_decl and parse_qasm3_decl. This @@ -485,6 +490,12 @@ bool QASMParser::load_qasm_stream( } } + if (!qubit_parser.is_finalized()) { + // A circuit with no gates. + int num_qubits = qubit_parser.finalize(); + seq = new CircuitSeq(num_qubits); + } + // Successfully parsed file. param_parser_.end_file(); return true;