Skip to content

Commit

Permalink
remove build_reply wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Jul 18, 2024
1 parent 0a81875 commit f1eff85
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
25 changes: 8 additions & 17 deletions smartsim/_core/mli/infrastructure/control/workermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ def build_failure_reply(status: "Status", message: str) -> ResponseBuilder:
)


def build_reply(
worker: MachineLearningWorkerBase, reply: InferenceReply
) -> ResponseBuilder:
"""Builds a response for a successful inference request
:param worker: A worker to process the reply with
:param reply: The internal representation of the reply"""
results = worker.prepare_outputs(reply)

return MessageHandler.build_response(
status=reply.status_enum,
message=reply.message,
result=results,
custom_attributes=None,
)


def exception_handler(
exc: Exception, reply_channel: t.Optional[CommChannelBase], failure_message: str
) -> None:
Expand Down Expand Up @@ -377,7 +361,14 @@ def _on_iteration(self) -> None:
else:
reply.status_enum = "complete"
reply.message = "Success"
response = build_reply(self._worker, reply)

results = self._worker.prepare_outputs(reply)
return MessageHandler.build_response(
status=reply.status_enum,
message=reply.message,
result=results,
custom_attributes=None,
)

timings.append(time.perf_counter() - interm) # timing
interm = time.perf_counter() # timing
Expand Down
30 changes: 1 addition & 29 deletions tests/dragon/test_reply_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@

dragon = pytest.importorskip("dragon")

from smartsim._core.mli.infrastructure.control.workermanager import (
build_failure_reply,
build_reply,
)
from smartsim._core.mli.infrastructure.control.workermanager import build_failure_reply
from smartsim._core.mli.infrastructure.worker.worker import InferenceReply

if t.TYPE_CHECKING:
Expand Down Expand Up @@ -64,28 +61,3 @@ def test_build_failure_reply_fails():

assert "Error assigning status to response" in ex.value.args[0]


@pytest.mark.parametrize(
"status, message",
[
pytest.param("complete", "Success", id="complete"),
],
)
def test_build_reply(status: "Status", message: str):
"Ensures replies can be built successfully"
reply = InferenceReply()
reply.status_enum = status
reply.message = message
response = build_reply(reply)
assert response.status == status
assert response.message == message


def test_build_reply_fails():
"Ensures ValueError is raised if a Status Enum is not used"
with pytest.raises(ValueError) as ex:
reply = InferenceReply()
reply.status_enum = "not a status enum"
response = build_reply(reply)

assert "Error assigning status to response" in ex.value.args[0]

0 comments on commit f1eff85

Please sign in to comment.