-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor implementation after review suggestions
- Loading branch information
Showing
7 changed files
with
82 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,49 @@ | ||
from dataclasses import dataclass | ||
from collections.abc import Mapping | ||
from typing import Any, Literal | ||
|
||
from pydantic import BaseModel, ConfigDict, field_serializer, field_validator | ||
|
||
from .snapshot import EnsembleSnapshot | ||
|
||
|
||
@dataclass | ||
class _UpdateEvent: | ||
class _UpdateEvent(BaseModel): | ||
model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid") | ||
iteration_label: str | ||
total_iterations: int | ||
progress: float | ||
realization_count: int | ||
status_count: dict[str, int] | ||
iteration: int | ||
snapshot: EnsembleSnapshot | None = None | ||
|
||
@field_serializer("snapshot") | ||
def serialize_snapshot( | ||
self, value: EnsembleSnapshot | None | ||
) -> dict[str, Any] | None: | ||
if value is None: | ||
return None | ||
return value.to_dict() | ||
|
||
@field_validator("snapshot", mode="before") | ||
@classmethod | ||
def validate_snapshot( | ||
cls, value: EnsembleSnapshot | Mapping[Any, Any] | ||
) -> EnsembleSnapshot: | ||
if isinstance(value, EnsembleSnapshot): | ||
return value | ||
return EnsembleSnapshot.from_nested_dict(value) | ||
|
||
|
||
@dataclass | ||
class FullSnapshotEvent(_UpdateEvent): | ||
snapshot: EnsembleSnapshot | None = None | ||
event_type: Literal["FullSnapshotEvent"] = "FullSnapshotEvent" | ||
|
||
|
||
@dataclass | ||
class SnapshotUpdateEvent(_UpdateEvent): | ||
snapshot: EnsembleSnapshot | None = None | ||
event_type: Literal["SnapshotUpdateEvent"] = "SnapshotUpdateEvent" | ||
|
||
|
||
@dataclass | ||
class EndEvent: | ||
class EndEvent(BaseModel): | ||
model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid") | ||
event_type: Literal["EndEvent"] = "EndEvent" | ||
failed: bool | ||
msg: str | None = None | ||
msg: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.