Skip to content
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

Merged

Conversation

yngve-sk
Copy link
Contributor

@yngve-sk yngve-sk commented Feb 6, 2025

Issue
Resolves equinor/semeio#685
Resolves #9389

Add support for defaulted kwargs from workflows

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 2 times, most recently from e38fc26 to 16d8860 Compare February 6, 2025 11:11
Copy link

codspeed-hq bot commented Feb 6, 2025

CodSpeed Performance Report

Merging #9994 will not alter performance

Comparing yngve-sk:25.02.05.internal-workflows-pass-some-stuff (6d042ec) with main (20dff0f)

Summary

✅ 25 untouched benchmarks

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 3 times, most recently from a1fc9a1 to ab916da Compare February 6, 2025 13:40
Copy link
Collaborator

@oyvindeide oyvindeide left a 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.

@@ -107,14 +107,16 @@ class WorkflowRunner:
def __init__(
self,
workflow: Workflow,
config_file: str | None = None,
Copy link
Collaborator

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.

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 8 times, most recently from a60c42c to 6e47da3 Compare February 11, 2025 08:55
@jonathan-eq jonathan-eq self-requested a review February 11, 2025 09:13
@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 3 times, most recently from 87c7ada to 0aeee68 Compare February 11, 2025 13:11
Copy link
Contributor

@jonathan-eq jonathan-eq left a 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 🔍

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from 0aeee68 to 9d1a66e Compare February 11, 2025 14:20
@jonathan-eq
Copy link
Contributor

There seems to be a GUI test hanging now 🤔

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 2 times, most recently from f094ca8 to 1e668d0 Compare February 12, 2025 11:20
@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from 1e668d0 to 563aa3f Compare February 12, 2025 13:22
@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from 563aa3f to aeccdd7 Compare February 12, 2025 13:32
@jonathan-eq
Copy link
Contributor

Will this resolve #9389?

@yngve-sk
Copy link
Contributor Author

Will this resolve #9389?

I think so yes, as it will no longer need the ertconfig

@jonathan-eq jonathan-eq added the release-notes:bug-fix Automatically categorise as bug fix in release notes label Feb 13, 2025
@jonathan-eq
Copy link
Contributor

Looks good to me, @oyvindeide should have a look at it too 🚀

Copy link
Collaborator

@oyvindeide oyvindeide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but can we drop kwargs support in this PR and still fix the bug? Then feel free to suggest it in a different PR, but think that requires some additional tests.

Comment on lines 74 to 98
@deprecated("Use fixtures to the run function instead")
def ert(self) -> ErtConfig | None:
logger.info(f"Accessing EnKFMain from workflow: {self.__class__.__name__}")
return self._ert

@property
def ensemble(self) -> Ensemble | None:
warnings.warn(
"The ensemble property is deprecated, use the fixture to the run function instead",
DeprecationWarning,
stacklevel=1,
)
logger.info(f"Accessing ensemble from workflow: {self.__class__.__name__}")
return self._ensemble

@property
def storage(self) -> Storage | None:
warnings.warn(
"The storage property is deprecated, use the fixture to the run function instead",
DeprecationWarning,
stacklevel=1,
)
logger.info(f"Accessing storage from workflow: {self.__class__.__name__}")
return self._storage

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These deprecations should stay, but can raise an error.

@@ -181,13 +182,20 @@ def __init__(
self.start_iteration = start_iteration
self.restart = False

def reports_dir(self, ensemble_name: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use log_path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see, this was just replicating old behavior, but log_path is the update_log_path, but workflows are not necessarily related to the update? Or is the update_log_path now just the "output" for non-storage, but permanent files pertaining to an ERT run?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the latter, it is just the output path for things related to that experiment.

Comment on lines 121 to 123
use_kwargs = {
k: (kwargs or {}).get(k, default_value)
for k, default_value in ({**kwargs_defaults, **kwargs}).items()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure kwarg support is worth the extra complication, can we do without it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in another PR unless it is needed to fix the bug, think we might need some additional tests for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. I will use workflow_args and move the defaulting to not be in the function signature of ahmanalysis, as for the test that modifies/overrides alpha for the update settings I will edit it in the ert config before doing .run_ertscript.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, yes, can remove the defaulting in the AHMAnalysis job

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from aeccdd7 to 6ad5a19 Compare February 14, 2025 11:40
@@ -71,36 +68,36 @@ def stderrdata(self) -> str:
self._stderrdata = self._stderrdata.decode()
return self._stderrdata

def isCancelled(self) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why moved?

@@ -114,7 +111,7 @@ def initializeAndRun(
self,
argument_types: list[type[Any]],
argument_values: list[str],
fixtures: dict[str, Any] | None = None,
fixtures: WorkflowFixtures | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing problem. Is this hit by tests? In case it is actually incompatible.

"""
Returns a list of arguments. Either from GUI or from arbitrary code.
If the user for example cancels in the GUI a CancelPluginException is raised.
"""
script = self.__loadPlugin()
fixtures["parent"] = self.__parent_window
func_args = inspect.signature(script.getArguments).parameters
arguments = script.insert_fixtures(func_args, fixtures)
arguments = script.insert_fixtures(dict(func_args), fixtures, {})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like more than a typing problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah removing, empty placeholder for kwargs

"storage": self.storage,
"random_seed": self.config.random_seed,
"reports_dir": str(
self.storage.path.parent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_path here too

"storage": self.storage,
"random_seed": ert_config.random_seed,
"reports_dir": str(
self.storage.path.parent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_path

"ensemble": ensemble,
"reports_dir": (
storage.path.parent
/ "reports"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log_path

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch 3 times, most recently from b849ab8 to ab80df4 Compare February 14, 2025 14:53
Copy link
Collaborator

@oyvindeide oyvindeide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just some minor comments.

@@ -213,13 +216,15 @@ def api(self) -> BaseRunModelAPI:
cancel=self.cancel,
)

def reports_dir(self, experiment_name: str) -> str:
return str(self._log_path / experiment_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that this does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so, assuming there is always a log_path in every BaseRunModel as it comes from the ERT config, or is otherwise explicitly passed in.

@@ -21,4 +21,4 @@ def test_executing_workflow(storage):
rc = ErtConfig.from_file(config_file)
args = Namespace(name="test_wf")
execute_workflow(rc, storage, args.name)
assert os.path.isfile(".ert_runpath_list")
assert os.path.isfile("test_workflow_output.csv")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest parameterizing this test if it is fast so both workflows are run.

logger.info(f"Accessing EnKFMain from workflow: {self.__class__.__name__}")
return self._ert
raise KeyError("Attribute 'ert' is deprecated, use fixtures instead.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but this should be an AttributeError

@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from ab80df4 to 3e43f4e Compare February 17, 2025 12:06
@yngve-sk yngve-sk force-pushed the 25.02.05.internal-workflows-pass-some-stuff branch from 3e43f4e to 6d042ec Compare February 19, 2025 07:56
Copy link
Contributor

@jonathan-eq jonathan-eq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good

@yngve-sk yngve-sk merged commit 5a86d20 into equinor:main Feb 19, 2025
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:bug-fix Automatically categorise as bug fix in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AHMAnalysis not working after ErtConfig change Investigate failure of ExportRunpathJob
3 participants