Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error category QSSUnsupportedQASM3 #292

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/API/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class ErrorCategory {
QSSLinkInvalidPatchTypeError,
QSSControlSystemResourcesExceeded,
QSSTargetUnsupportedOperation,
QSSUnsupportedQASM3,
UncategorizedError,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/API/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
3 changes: 3 additions & 0 deletions lib/API/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
6 changes: 6 additions & 0 deletions python_lib/qss_compiler/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions python_lib/qss_compiler/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
1 change: 1 addition & 0 deletions python_lib/qss_compiler/lib_enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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``.
6 changes: 3 additions & 3 deletions targets/systems/mock/test/python_lib/test_compile_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
OutputType,
CompileOptions,
)
from qss_compiler.exceptions import QSSCompilationFailure
from qss_compiler.exceptions import QSSUnsupportedQASM3

compiler_extra_args = ["--enable-circuits=false"]

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading