-
Notifications
You must be signed in to change notification settings - Fork 110
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
Some adaptations to workflows #9994
base: main
Are you sure you want to change the base?
Some adaptations to workflows #9994
Conversation
e38fc26
to
16d8860
Compare
CodSpeed Performance ReportMerging #9994 will improve performances by 13.37%Comparing Summary
Benchmarks breakdown
|
a1fc9a1
to
ab916da
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, I have some minor questions.
src/ert/cli/workflow.py
Outdated
runner = WorkflowRunner( | ||
workflow=workflow, | ||
storage=storage, | ||
ert_config=ert_config, |
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.
I guess we should remove this as it is not available in run models, where most of these are run from?
if is_using_wf_args_fixture | ||
else [*workflow_args, *fixture_args] | ||
) | ||
if not positional_args and not use_kwargs: |
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.
This we could keep this as it used to be? I dont think kwargs were really supported before, they just ended up being workflow_args
in a list?
src/ert/workflow_runner.py
Outdated
@@ -107,14 +107,16 @@ class WorkflowRunner: | |||
def __init__( | |||
self, | |||
workflow: Workflow, | |||
config_file: str | None = None, |
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.
Also commented in semeio, could potentially give reports dir, we do something similar for the update report, that has a folder it writes to.
src/ert/workflow_runner.py
Outdated
storage: Storage | None = None, | ||
ensemble: Ensemble | None = None, | ||
ert_config: ErtConfig | None = None, | ||
) -> None: | ||
self.__workflow = workflow | ||
self.storage = storage | ||
self.ensemble = ensemble | ||
self.ert_config = ert_config | ||
self.ert_config = ert_config # Should eventually be removed |
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.
Remove now?
a60c42c
to
6e47da3
Compare
src/ert/config/ert_script.py
Outdated
func_args: MappingProxyType[str, inspect.Parameter], | ||
fixtures: dict[str, Fixtures], | ||
func_args: dict[str, inspect.Parameter], | ||
fixtures: dict[WorkflowFixtures, Any], |
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.
I am not entirely getting this. If fixtures is a dict, where the keys can only be any of the WorkflowFixtures enum values; shouldnt WorkflowFixtures be a dataclass and we would use fixtures: WorkflowFixtures
instead of fixtures: dict[WorkflowFixtures, Any]
?
Why is the fixture value Any
?
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.
Hmm it could be set as a dataclass I think, but eventually the fixtures are passed in as arguments, and we also give them in a very "partial" way. We can do this in dataclasses by omitting stuff etc etc, but there we would have lots of default'ed None
values. In some cases we want an error if a workflow requests an argument that is not a fixture, nor a provided kwarg. If we had a dataclass, we would have to know whether the None
in the fixture means an explicit None
from outside, or a truly "missing" argument.
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.
What if we have it as a TypedDict and mark the types with NotRequired?
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.
That is probably better, testing...
fixtures: dict[str, Fixtures], | ||
func_args: dict[str, inspect.Parameter], | ||
fixtures: dict[WorkflowFixtures, Any], | ||
kwargs: dict[str, Any], | ||
) -> list[Any]: | ||
arguments = [] | ||
errors = [] | ||
for val in func_args: |
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.
What is val
here? Is it the required argument?
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.
Yep it is required, and we mark it as an error if val
is not in the fixtures, or explicit kwargs the run
fn is invoked with. So func_args
here is the arguments of the run
function of the workflow, and here we are creating the arguments to call the run
function with, by inserting the values for corresponding fixtures
. So the whole purpose of the fixtures is to substitute here.
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.
Ahhh, okay! That makes sense! Very good 👍
src/ert/run_models/base_run_model.py
Outdated
self.run_workflows( | ||
HookRuntime.POST_SIMULATION, | ||
fixtures={ | ||
WorkflowFixtures.storage: self._storage, | ||
WorkflowFixtures.ensemble: ensemble, | ||
WorkflowFixtures.reports_dir: self.reports_dir( | ||
ensemble_name=ensemble.name | ||
), | ||
WorkflowFixtures.random_seed: self.random_seed, | ||
WorkflowFixtures.run_paths: self.run_paths, | ||
}, | ||
) |
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.
Is this and the the self.run_workflows above it the same, except for the ensemble maybe changing? Maybe we can move most of it into the run_workflows method?
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.
I think it makes most sense to keep the fixtures as an arg to run_workflows
, since it is invoked from other places than BaseRunModel
at different points/hooks in the ERT execution, and it makes it clear at the callsites which fixtures are given to the workflows.
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.
Okay, good!
87c7ada
to
0aeee68
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.
Very good :) See some minor questions 🔍
src/ert/config/workflow_fixtures.py
Outdated
from ert.storage import Ensemble, Storage | ||
|
||
|
||
class WorkflowFixtures(TypedDict): |
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.
I think you can omit marking all keys with NotRequired if you change class WorkflowFixtures(TypedDict)
to class WorkflowFixtures(TypedDict, total=False)
https://peps.python.org/pep-0589/#totality
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.
Done
src/ert/gui/tools/plugins/plugin.py
Outdated
func_args = inspect.signature(script.getArguments).parameters | ||
arguments = script.insert_fixtures(func_args, fixtures) | ||
arguments = script.insert_fixtures(dict(func_args), fixtures, {}) | ||
|
||
# Part of deprecation |
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.
leftover comment
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.
^the part of deprecation
line
src/ert/workflow_runner.py
Outdated
if TYPE_CHECKING: | ||
from ert.storage import Ensemble, Storage | ||
pass |
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.
Lets remove this type_checking :)
["1", "2", "3"], | ||
fixture_mock, | ||
) | ||
|
||
|
||
def test_plugin_with_default_arguments(capsys): | ||
def test_plugin_with_fixtures_and_enough_arguments_positional(): |
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.
I think test_plugin_with_fixtures_and_enough_positional_arguments
would read a tad better
) | ||
|
||
|
||
def test_plugin_with_default_arguments(capsys): |
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.
Is this test using capsys?
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.
Removed it in separate commit
Co-authored-by: Jonathan Karlsen <[email protected]>
Co-authored-by: Jonathan Karlsen <[email protected]>
Co-authored-by: Jonathan Karlsen <[email protected]>
0aeee68
to
9d1a66e
Compare
There seems to be a GUI test hanging now 🤔 |
Issue
Resolves equinor/semeio#685
Add support for defaulted kwargs from workflows