diff --git a/include/API/errors.h b/include/API/errors.h index c5e878b6f..1c0ebf006 100644 --- a/include/API/errors.h +++ b/include/API/errors.h @@ -48,6 +48,7 @@ enum class ErrorCategory { QSSLinkInvalidPatchTypeError, QSSControlSystemResourcesExceeded, QSSTargetUnsupportedOperation, + QSSUnsupportedQASM3, UncategorizedError, }; diff --git a/lib/API/api.cpp b/lib/API/api.cpp index 206f2f708..728c06daa 100644 --- a/lib/API/api.cpp +++ b/lib/API/api.cpp @@ -347,7 +347,7 @@ void diagEngineHandler(mlir::Diagnostic &diagnostic, // emit diagnostic cast to void to discard result as it is not needed here if (qssc_severity == qssc::Severity::Error) { (void)qssc::emitDiagnostic(diagnosticCb, qssc_severity, - qssc::ErrorCategory::QSSCompilationFailure, + qssc::ErrorCategory::QSSUnsupportedQASM3, diagnostic.str()); } diff --git a/lib/API/errors.cpp b/lib/API/errors.cpp index eb4911101..7b665287b 100644 --- a/lib/API/errors.cpp +++ b/lib/API/errors.cpp @@ -85,6 +85,9 @@ std::string_view getErrorCategoryAsString(qssc::ErrorCategory category) { case ErrorCategory::QSSTargetUnsupportedOperation: return "An unsupported operation on a target was used"; + case ErrorCategory::QSSUnsupportedQASM3: + return "The provided QASM3 is not supported by the compiler"; + case ErrorCategory::UncategorizedError: return "Compilation failure"; } diff --git a/python_lib/qss_compiler/compile.py b/python_lib/qss_compiler/compile.py index 36ba39799..52c9019f7 100644 --- a/python_lib/qss_compiler/compile.py +++ b/python_lib/qss_compiler/compile.py @@ -316,6 +316,12 @@ def compile(self) -> Union[bytes, str, None]: diagnostics, return_diagnostics=self.return_diagnostics, ) + if diag.category == ErrorCategory.QSSUnsupportedQASM3: + raise exceptions.QSSUnsupportedQASM3( + diag.message, + diagnostics, + return_diagnostics=self.return_diagnostics, + ) if not success: raise exceptions.QSSCompilationFailure( diff --git a/python_lib/qss_compiler/exceptions.py b/python_lib/qss_compiler/exceptions.py index 6bffa238b..98cb03d11 100644 --- a/python_lib/qss_compiler/exceptions.py +++ b/python_lib/qss_compiler/exceptions.py @@ -123,3 +123,7 @@ class QSSTargetUnsupportedOperation(QSSCompilerError): class OpenQASM3ParseFailure(QSSCompilerError): """Raised when a parser failure is received""" + + +class QSSUnsupportedQASM3(QSSCompilerError): + """Raised when an unsupported QASM3 is received.""" diff --git a/python_lib/qss_compiler/lib_enums.cpp b/python_lib/qss_compiler/lib_enums.cpp index fe65c3c03..34618def0 100644 --- a/python_lib/qss_compiler/lib_enums.cpp +++ b/python_lib/qss_compiler/lib_enums.cpp @@ -45,6 +45,7 @@ void addErrorCategory(py::module &m) { qssc::ErrorCategory::QSSControlSystemResourcesExceeded) .value("QSSTargetUnsupportedOperation", qssc::ErrorCategory::QSSTargetUnsupportedOperation) + .value("QSSUnsupportedQASM3", qssc::ErrorCategory::QSSUnsupportedQASM3) .value("UncategorizedError", qssc::ErrorCategory::UncategorizedError) .export_values(); } diff --git a/releasenotes/notes/soo-ER-add-QSSUnsupportedQASM3-5f32fb45a26a7d8d.yaml b/releasenotes/notes/soo-ER-add-QSSUnsupportedQASM3-5f32fb45a26a7d8d.yaml new file mode 100644 index 000000000..8f19c80c5 --- /dev/null +++ b/releasenotes/notes/soo-ER-add-QSSUnsupportedQASM3-5f32fb45a26a7d8d.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Added ``QSSUnsupportedQASM3`` error category for the cases which + fail to generate MLIR from the QUIRGen. These errors used to be + categorized under ``QSSCompilationFailure``. diff --git a/targets/systems/mock/test/python_lib/test_compile_mock.py b/targets/systems/mock/test/python_lib/test_compile_mock.py index 755d9da5c..e28015d52 100644 --- a/targets/systems/mock/test/python_lib/test_compile_mock.py +++ b/targets/systems/mock/test/python_lib/test_compile_mock.py @@ -29,7 +29,7 @@ OutputType, CompileOptions, ) -from qss_compiler.exceptions import QSSCompilationFailure +from qss_compiler.exceptions import QSSUnsupportedQASM3 compiler_extra_args = ["--enable-circuits=false"] @@ -136,7 +136,7 @@ def test_compile_failing_str_to_qem( """Test that compiling an invalid OpenQASM3 string via the interface compile_str to a QEM payload will fail and result in an empty payload.""" - with pytest.raises(QSSCompilationFailure): + with pytest.raises(QSSUnsupportedQASM3): compile_str( example_unsupported_qasm3_str, input_type=InputType.QASM3, @@ -154,7 +154,7 @@ def test_compile_failing_file_to_qem( """Test that compiling an invalid file input via the interface compile_file to a QEM payload will fail and result in an empty payload.""" - with pytest.raises(QSSCompilationFailure): + with pytest.raises(QSSUnsupportedQASM3): compile_file( example_unsupported_qasm3_tmpfile, input_type=InputType.QASM3,