Skip to content

Commit

Permalink
use for schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
MattToast committed Mar 21, 2024
1 parent 372e152 commit d697da9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 48 deletions.
3 changes: 1 addition & 2 deletions smartsim/_core/launcher/dragon/dragonLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import smartsim._core.utils.helpers as _helpers
from smartsim._core.schemas.dragonRequests import request_serializer
from smartsim._core.schemas.dragonResponses import response_serializer
from smartsim._core.schemas.types import NonEmptyStr

from ....error import LauncherError
from ....log import get_logger
Expand Down Expand Up @@ -371,7 +370,7 @@ def _get_managed_step_update(self, step_ids: t.List[str]) -> t.List[StepInfo]:
msg += response.error_message
raise LauncherError(msg)

status, ret_codes = response.statuses[NonEmptyStr(step_id)]
status, ret_codes = response.statuses[step_id]
if ret_codes:
grp_ret_code = min(ret_codes)
if any(ret_codes):
Expand Down
21 changes: 10 additions & 11 deletions smartsim/_core/schemas/dragonRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

import typing as t

from pydantic import BaseModel, PositiveInt
from pydantic import BaseModel, PositiveInt, Field

import smartsim._core.schemas.utils as _utils
from smartsim._core.schemas.types import NonEmptyStr

# Black and Pylint disagree about where to put the `...`
# pylint: disable=multiple-statements
Expand All @@ -42,16 +41,16 @@ class DragonRequest(BaseModel): ...


class DragonRunRequestView(DragonRequest):
exe: NonEmptyStr
exe_args: t.List[NonEmptyStr] = []
path: NonEmptyStr
exe: t.Annotated[str, Field(min_length=1)]
exe_args: t.List[t.Annotated[str, Field(min_length=1)]] = []
path: t.Annotated[str, Field(min_length=1)]
nodes: PositiveInt = 1
tasks: PositiveInt = 1
tasks_per_node: PositiveInt = 1
output_file: t.Optional[NonEmptyStr] = None
error_file: t.Optional[NonEmptyStr] = None
output_file: t.Optional[t.Annotated[str, Field(min_length=1)]] = None
error_file: t.Optional[t.Annotated[str, Field(min_length=1)]] = None
env: t.Dict[str, t.Optional[str]] = {}
name: t.Optional[NonEmptyStr]
name: t.Optional[t.Annotated[str, Field(min_length=1)]] = None
pmi_enabled: bool = True


Expand All @@ -65,12 +64,12 @@ def __str__(self) -> str:

@request_serializer.register("update_status")
class DragonUpdateStatusRequest(DragonRequest):
step_ids: t.List[NonEmptyStr]
step_ids: t.List[t.Annotated[str, Field(min_length=1)]]


@request_serializer.register("stop")
class DragonStopRequest(DragonRequest):
step_id: NonEmptyStr
step_id: t.Annotated[str, Field(min_length=1)]


@request_serializer.register("handshake")
Expand All @@ -79,7 +78,7 @@ class DragonHandshakeRequest(DragonRequest): ...

@request_serializer.register("bootstrap")
class DragonBootstrapRequest(DragonRequest):
address: NonEmptyStr
address: t.Annotated[str, Field(min_length=1)]


@request_serializer.register("shutdown")
Expand Down
10 changes: 6 additions & 4 deletions smartsim/_core/schemas/dragonResponses.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

import typing as t

from pydantic import BaseModel
from pydantic import BaseModel, Field

import smartsim._core.schemas.utils as _utils
from smartsim._core.schemas.types import NonEmptyStr

# Black and Pylint disagree about where to put the `...`
# pylint: disable=multiple-statements
Expand All @@ -44,13 +43,16 @@ class DragonResponse(BaseModel):

@response_serializer.register("run")
class DragonRunResponse(DragonResponse):
step_id: NonEmptyStr
step_id: t.Annotated[str, Field(min_length=1)]


@response_serializer.register("status_update")
class DragonUpdateStatusResponse(DragonResponse):
# status is a dict: {step_id: (is_alive, returncode)}
statuses: t.Mapping[NonEmptyStr, t.Tuple[NonEmptyStr, t.Optional[t.List[int]]]] = {}
statuses: t.Mapping[
t.Annotated[str, Field(min_length=1)],
t.Tuple[t.Annotated[str, Field(min_length=1)], t.Optional[t.List[int]]],
] = {}


@response_serializer.register("stop")
Expand Down
31 changes: 0 additions & 31 deletions smartsim/_core/schemas/types.py

This file was deleted.

0 comments on commit d697da9

Please sign in to comment.