Skip to content

Commit

Permalink
add base error, change MissingProtocolUnitError -> MissingUnitResultE…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
jthorton committed Dec 12, 2024
1 parent d27d0a0 commit 7552c7d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gufe/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Defining processes for performing estimates of free energy differences"""

from .errors import (
MissingProtocolUnitError,
MissingUnitResultError,
ProtocolAnalysisError,
ProtocolExecutionError,
ProtocolSetupError,
Expand Down
18 changes: 10 additions & 8 deletions gufe/protocols/errors.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/gufe

class BaseGufeError(Exception):
"""The base gufe error that other errors should subclass."""

# Protocol Errors
class ProtocolValidationError(Exception):
class ProtocolValidationError(BaseGufeError):
"""Error when the protocol setup or settings can not be validated."""


class ProtocolSetupError(Exception):
class ProtocolSetupError(BaseGufeError):
"""Error when executing the setup unit of the protocol."""


class ProtocolExecutionError(Exception):
class ProtocolExecutionError(BaseGufeError):
"""Error when executing the production unit of the protocol."""


class ProtocolAnalysisError(Exception):
class ProtocolAnalysisError(BaseGufeError):
"""Error when trying to perform some analyses after the protocol has been executed."""


# Protocol Results Errors
class MissingProtocolUnitError(Exception):
"""Error when a ProtocolDAGResult is missing a protocol unit."""
class MissingUnitResultError(BaseGufeError):
"""Error when a ProtocolDAGResult is missing a unit result."""


class ProtocolUnitFailureError(Exception):
"""Error when a ProtocolDAGResult contains an failed protocol unit."""
class ProtocolUnitFailureError(BaseGufeError):
"""Error when a ProtocolDAGResult contains a failed protocol unit."""
12 changes: 6 additions & 6 deletions gufe/protocols/protocoldag.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import networkx as nx

from ..tokenization import GufeKey, GufeTokenizable
from .errors import MissingProtocolUnitError, ProtocolUnitFailureError
from .errors import MissingUnitResultError, ProtocolUnitFailureError
from .protocolunit import Context, ProtocolUnit, ProtocolUnitFailure, ProtocolUnitResult


Expand Down Expand Up @@ -212,15 +212,15 @@ def unit_to_result(self, protocol_unit: ProtocolUnit) -> ProtocolUnitResult:
Raises
------
MissingProtocolUnitError:
MissingUnitResultError:
if there are no results for that protocol unit
ProtocolUnitFailureError:
if all units failed
"""
try:
units = self._unit_result_mapping[protocol_unit]
except KeyError:
raise MissingProtocolUnitError(f"No such `protocol_unit`:{protocol_unit} present")
raise MissingUnitResultError(f"No such `protocol_unit`:{protocol_unit} present")
else:
for u in units:
if u.ok():
Expand All @@ -238,19 +238,19 @@ def unit_to_all_results(self, protocol_unit: ProtocolUnit) -> list[ProtocolUnitR
Raises
------
MissingProtocolUnitError
MissingUnitResultError
if no results present for a given unit
"""
try:
return self._unit_result_mapping[protocol_unit]
except KeyError:
raise MissingProtocolUnitError(f"No such `protocol_unit`:{protocol_unit} present")
raise MissingUnitResultError(f"No such `protocol_unit`:{protocol_unit} present")

def result_to_unit(self, protocol_unit_result: ProtocolUnitResult) -> ProtocolUnit:
try:
return self._result_unit_mapping[protocol_unit_result]
except KeyError:
raise MissingProtocolUnitError(f"No such `protocol_unit_result`:{protocol_unit_result} present")
raise MissingUnitResultError(f"No such `protocol_unit_result`:{protocol_unit_result} present")

def ok(self) -> bool:
# ensure that for every protocol unit, there is an OK result object
Expand Down
8 changes: 4 additions & 4 deletions gufe/tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ProtocolUnit,
ProtocolUnitFailure,
ProtocolUnitResult,
MissingProtocolUnitError,
MissingUnitResultError,
ProtocolUnitFailureError
)
from gufe.protocols.protocoldag import execute_DAG
Expand Down Expand Up @@ -723,11 +723,11 @@ def test_foreign_objects(self, units, successes):
transformation_key=None,
)

with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit`:NoDepUnit\(None\) present"):
with pytest.raises(MissingUnitResultError, match="No such `protocol_unit`:NoDepUnit\(None\) present"):
dagresult.unit_to_result(units[2])
with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit`:NoDepUnit\(None\) present"):
with pytest.raises(MissingUnitResultError, match="No such `protocol_unit`:NoDepUnit\(None\) present"):
dagresult.unit_to_all_results(units[2])
with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit_result`:ProtocolUnitResult\(None\) present"):
with pytest.raises(MissingUnitResultError, match="No such `protocol_unit_result`:ProtocolUnitResult\(None\) present"):
dagresult.result_to_unit(successes[2])


Expand Down

0 comments on commit 7552c7d

Please sign in to comment.