Skip to content

Evaluation errors

mdo_framework.core.errors

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

EvaluationError

Bases: ValueError

An evaluation point failed; the run may continue with other points.

It subclasses ValueError because GEMSEO's parallel execution re-raises only ValueError subclasses.

Attributes:

Name Type Description
code str

Stable machine-readable code of the error class.

retryable bool

Whether evaluating the same point again may succeed.

message

What went wrong, without the tool prefix.

tool

Name of the tool that failed, if any.

Source code in src/mdo_framework/core/errors.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class EvaluationError(ValueError):
    """An evaluation point failed; the run may continue with other points.

    It subclasses ``ValueError`` because GEMSEO's parallel execution re-raises
    only ``ValueError`` subclasses.

    Attributes:
        code: Stable machine-readable code of the error class.
        retryable: Whether evaluating the same point again may succeed.
        message: What went wrong, without the tool prefix.
        tool: Name of the tool that failed, if any.
    """

    code: ClassVar[str] = "EVALUATION_FAILED"
    retryable: ClassVar[bool] = False

    def __init__(self, message: str, *, tool: str | None = None) -> None:
        """Build the error.

        Args:
            message: What went wrong.
            tool: Name of the tool that failed, prefixed to the message.
        """
        self.message = message
        self.tool = tool
        super().__init__(f"Tool '{tool}': {message}" if tool else message)

    def to_payload(self) -> dict[str, Any]:
        """Serialize the error for a service response.

        Returns:
            The ``code``, ``message``, ``tool`` and ``retryable`` of the error;
            ``evaluation_error_from_payload`` rebuilds the error from it.
        """
        return {
            "code": self.code,
            "message": self.message,
            "tool": self.tool,
            "retryable": self.retryable,
        }

__init__(message, *, tool=None)

Build the error.

Parameters:

Name Type Description Default
message str

What went wrong.

required
tool str | None

Name of the tool that failed, prefixed to the message.

None
Source code in src/mdo_framework/core/errors.py
27
28
29
30
31
32
33
34
35
36
def __init__(self, message: str, *, tool: str | None = None) -> None:
    """Build the error.

    Args:
        message: What went wrong.
        tool: Name of the tool that failed, prefixed to the message.
    """
    self.message = message
    self.tool = tool
    super().__init__(f"Tool '{tool}': {message}" if tool else message)

to_payload()

Serialize the error for a service response.

Returns:

Type Description
dict[str, Any]

The code, message, tool and retryable of the error;

dict[str, Any]

evaluation_error_from_payload rebuilds the error from it.

Source code in src/mdo_framework/core/errors.py
38
39
40
41
42
43
44
45
46
47
48
49
50
def to_payload(self) -> dict[str, Any]:
    """Serialize the error for a service response.

    Returns:
        The ``code``, ``message``, ``tool`` and ``retryable`` of the error;
        ``evaluation_error_from_payload`` rebuilds the error from it.
    """
    return {
        "code": self.code,
        "message": self.message,
        "tool": self.tool,
        "retryable": self.retryable,
    }

InfeasiblePointError

Bases: ToolError

A tool declares that it cannot compute this point, e.g. a failed mesh.

Tools raise it themselves to report a point outside their domain of validity, which is a point failure rather than a tool crash.

Source code in src/mdo_framework/core/errors.py
71
72
73
74
75
76
77
78
class InfeasiblePointError(ToolError):
    """A tool declares that it cannot compute this point, e.g. a failed mesh.

    Tools raise it themselves to report a point outside their domain of
    validity, which is a point failure rather than a tool crash.
    """

    code: ClassVar[str] = "POINT_INFEASIBLE"

MDANotConvergedError

Bases: EvaluationError

The coupled tools did not reach a fixed point within the MDA limits.

Source code in src/mdo_framework/core/errors.py
81
82
83
84
class MDANotConvergedError(EvaluationError):
    """The coupled tools did not reach a fixed point within the MDA limits."""

    code: ClassVar[str] = "MDA_NOT_CONVERGED"

ToolError

Bases: EvaluationError

A tool could not produce valid outputs for a point.

Source code in src/mdo_framework/core/errors.py
53
54
55
56
class ToolError(EvaluationError):
    """A tool could not produce valid outputs for a point."""

    code: ClassVar[str] = "TOOL_FAILED"

ToolExecutionError

Bases: ToolError

The tool function raised an exception.

Source code in src/mdo_framework/core/errors.py
59
60
61
62
class ToolExecutionError(ToolError):
    """The tool function raised an exception."""

    code: ClassVar[str] = "TOOL_FAILED"

ToolOutputError

Bases: ToolError

The tool returned outputs that break the output contract.

Source code in src/mdo_framework/core/errors.py
65
66
67
68
class ToolOutputError(ToolError):
    """The tool returned outputs that break the output contract."""

    code: ClassVar[str] = "OUTPUT_INVALID"

evaluation_error_from_payload(payload)

Rebuild the error a service serialized with EvaluationError.to_payload.

Parameters:

Name Type Description Default
payload Any

The decoded detail of a service error response.

required

Returns:

Type Description
EvaluationError | None

The error with the same class, message and tool, or None if the

EvaluationError | None

payload is not a serialized evaluation error: unknown code, wrong

EvaluationError | None

field types, or a retryable flag that does not match the class.

Source code in src/mdo_framework/core/errors.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def evaluation_error_from_payload(payload: Any) -> EvaluationError | None:
    """Rebuild the error a service serialized with ``EvaluationError.to_payload``.

    Args:
        payload: The decoded ``detail`` of a service error response.

    Returns:
        The error with the same class, message and tool, or ``None`` if the
        payload is not a serialized evaluation error: unknown ``code``, wrong
        field types, or a ``retryable`` flag that does not match the class.
    """
    if not isinstance(payload, Mapping):
        return None
    code = payload.get("code")
    message = payload.get("message")
    tool = payload.get("tool")
    retryable = payload.get("retryable")
    if not isinstance(code, str) or not isinstance(message, str):
        return None
    error_class = _ERRORS_BY_CODE.get(code)
    if error_class is None or retryable is not error_class.retryable:
        return None
    if tool is not None and not isinstance(tool, str):
        return None
    return error_class(message, tool=tool)