-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add event serialization testing #9573
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9573 +/- ##
==========================================
+ Coverage 91.71% 91.74% +0.02%
==========================================
Files 429 426 -3
Lines 26672 26589 -83
==========================================
- Hits 24463 24393 -70
+ Misses 2209 2196 -13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #9573 will degrade performances by 10.59%Comparing Summary
Benchmarks breakdown
|
261b703
to
bdac9c6
Compare
9281d76
to
7089a3b
Compare
7089a3b
to
9c6ec15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some suggestions and questions
start_time = source.get("start_time") | ||
if start_time and isinstance(start_time, str): | ||
start_time = datetime.fromisoformat(start_time) | ||
end_time = source.get("end_time") | ||
if end_time and isinstance(end_time, str): | ||
end_time = datetime.fromisoformat(end_time) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this not happen? Seems like we mostly do:
def convert_iso8601_to_datetime(
timestamp: datetime | str,
) -> datetime:
if isinstance(timestamp, datetime):
return timestamp
return datetime.fromisoformat(timestamp)
for step in realization["fm_steps"].values(): | ||
if "start_time" in step and isinstance(step["start_time"], str): | ||
step["start_time"] = datetime.fromisoformat(step["start_time"]) | ||
if "end_time" in step and isinstance(step["end_time"], str): | ||
step["end_time"] = datetime.fromisoformat(step["end_time"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here, should perhaps do it on the sender side?
match event_type: | ||
case FullSnapshotEvent.__name__: | ||
snapshot = EnsembleSnapshot.from_nested_dict(json_dict["snapshot"]) | ||
json_dict["snapshot"] = snapshot | ||
return FullSnapshotEvent(**json_dict) | ||
case SnapshotUpdateEvent.__name__: | ||
snapshot = EnsembleSnapshot.from_nested_dict(json_dict["snapshot"]) | ||
json_dict["snapshot"] = snapshot | ||
return SnapshotUpdateEvent(**json_dict) | ||
case RunModelDataEvent.__name__ | RunModelUpdateEndEvent.__name__: | ||
if "run_id" in json_dict and isinstance(json_dict["run_id"], str): | ||
json_dict["run_id"] = UUID(json_dict["run_id"]) | ||
if json_dict.get("data"): | ||
json_dict["data"] = DataSection(**json_dict["data"]) | ||
return EVENT_MAPPING[event_type](**json_dict) | ||
case _: | ||
if event_type in EVENT_MAPPING: | ||
if "run_id" in json_dict and isinstance(json_dict["run_id"], str): | ||
json_dict["run_id"] = UUID(json_dict["run_id"]) | ||
return EVENT_MAPPING[event_type](**json_dict) | ||
else: | ||
raise TypeError(f"Unknown status event type {event_type}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this could also be done by pydantic directly?
for example:
class EventWrapper(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
event: Annotated[StatusEvents, Field(discriminator='event_type')]
event_dict.update( | ||
{ | ||
"snapshot": event.snapshot.to_dict(), | ||
"event_type": event.__class__.__name__, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to add this directly to the events?
event_type: Literal['FullSnapshotEvent'] = 'FullSnapshotEvent'
the pro is it is more explicit, but on the flip side it is more verbose and has to be kept in sync for all events 🤔
raise TypeError(f"Unknown status event type {event_type}") | ||
|
||
|
||
def status_event_to_json(event: StatusEvents) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my PR I did:
await websocket.send_json(event)
so did not need a custom function, is that needed? It just takes StatusEvents
:
StatusEvents = Union[
FullSnapshotEvent,
SnapshotUpdateEvent,
EndEvent,
AnalysisStatusEvent,
AnalysisTimeEvent,
AnalysisReportEvent,
RunModelErrorEvent,
RunModelStatusEvent,
RunModelTimeEvent,
RunModelUpdateBeginEvent,
RunModelDataEvent,
RunModelUpdateEndEvent,
]
Issue
Resolves #9517
Approach
Add serialization roundtrip for all events generated by EverestRunModel
git rebase -i main --exec 'pytest tests/ert/unit_tests -n logical -m "not integration_test"'
)When applicable