From 89ab6c3c1cf56b415585a64cb1064fe3fdd18d4c Mon Sep 17 00:00:00 2001 From: Casey Jao Date: Mon, 25 Nov 2024 15:19:10 -0500 Subject: [PATCH] Default workflow_executor to lattice-default executor This should eliminate the need to set workflow_executor explicitly in many cases. --- CHANGELOG.md | 1 + covalent/_shared_files/defaults.py | 2 -- covalent/_workflow/electron.py | 11 ++--------- covalent/_workflow/lattice.py | 8 +++++++- .../covalent_tests/workflow/electron_metadata_test.py | 5 +++-- tests/covalent_tests/workflow/lattice_test.py | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 381550189..ace8c7dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added support for Python 3.11 - Removed official support for Python 3.8 +- workflow_executor now defaults to the lattice-default executor ## [0.235.1-rc.0] - 2024-06-10 diff --git a/covalent/_shared_files/defaults.py b/covalent/_shared_files/defaults.py index aef61086d..ca25073ab 100644 --- a/covalent/_shared_files/defaults.py +++ b/covalent/_shared_files/defaults.py @@ -201,5 +201,3 @@ class DefaultMetadataValues: executor: str = field(default_factory=get_default_executor) executor_data: Dict = field(default_factory=dict) hooks: Dict = field(default_factory=dict) - workflow_executor: str = field(default_factory=get_default_executor) - workflow_executor_data: Dict = field(default_factory=dict) diff --git a/covalent/_workflow/electron.py b/covalent/_workflow/electron.py index e6a6e4648..915d22f66 100644 --- a/covalent/_workflow/electron.py +++ b/covalent/_workflow/electron.py @@ -208,18 +208,11 @@ def func_for_op(arg_1: Union[Any, "Electron"], arg_2: Union[Any, "Electron"]) -> # enclosing lattice's workflow_executor. metadata = encode_metadata(DEFAULT_METADATA_VALUES.copy()) - executor = metadata["workflow_executor"] - executor_data = metadata["workflow_executor_data"] - op_electron = Electron(func_for_op, metadata=metadata) if active_lattice := active_lattice_manager.get_active_lattice(): - executor = active_lattice.metadata.get( - "workflow_executor", metadata["workflow_executor"] - ) - executor_data = active_lattice.metadata.get( - "workflow_executor_data", metadata["workflow_executor_data"] - ) + executor = active_lattice.metadata["workflow_executor"] + executor_data = active_lattice.metadata["workflow_executor_data"] op_electron.metadata["executor"] = executor op_electron.metadata["executor_data"] = executor_data diff --git a/covalent/_workflow/lattice.py b/covalent/_workflow/lattice.py index 146b837d9..c80f23b10 100644 --- a/covalent/_workflow/lattice.py +++ b/covalent/_workflow/lattice.py @@ -204,17 +204,23 @@ def build_graph(self, *args, **kwargs) -> None: self.inputs = TransportableObject({"args": args, "kwargs": kwargs}) # Set any lattice metadata not explicitly set by the user - constraint_names = {"executor", "workflow_executor", "hooks"} + constraint_names = {"executor", "hooks"} new_metadata = { name: DEFAULT_METADATA_VALUES[name] for name in constraint_names if self.metadata[name] is None } + new_metadata = encode_metadata(new_metadata) for k, v in new_metadata.items(): self.metadata[k] = v + # Copy lattice default executor to workflow_executor if the latter is not set + if self.metadata["workflow_executor"] is None: + self.metadata["workflow_executor"] = self.metadata["executor"] + self.metadata["workflow_executor_data"] = self.metadata["executor_data"] + # Check whether task packing is enabled self._task_packing = get_config("sdk.task_packing") == "true" diff --git a/tests/covalent_tests/workflow/electron_metadata_test.py b/tests/covalent_tests/workflow/electron_metadata_test.py index 8971f91a4..e26787f5a 100644 --- a/tests/covalent_tests/workflow/electron_metadata_test.py +++ b/tests/covalent_tests/workflow/electron_metadata_test.py @@ -17,7 +17,7 @@ """Unit tests to test whether electrons inherit lattice metadata correctly""" -from covalent._shared_files.defaults import get_default_executor, postprocess_prefix +from covalent._shared_files.defaults import postprocess_prefix from covalent._workflow.transport import _TransportGraph @@ -51,7 +51,8 @@ def hello_world(x): metadata = tg.get_node_value(node_id, "metadata") node_name = tg.get_node_value(node_id, "name") if node_name.startswith(postprocess_prefix): - assert metadata["executor"] == get_default_executor() + # workflow_executor defaults to lattice-default executor + assert metadata["executor"] == "awslambda" elif "parameter" not in node_name: assert metadata["executor"] == "electron_executor" assert metadata["hooks"]["deps"]["bash"] == electron_bash_dep.to_dict() diff --git a/tests/covalent_tests/workflow/lattice_test.py b/tests/covalent_tests/workflow/lattice_test.py index 1576f4178..6b9d5827d 100644 --- a/tests/covalent_tests/workflow/lattice_test.py +++ b/tests/covalent_tests/workflow/lattice_test.py @@ -69,7 +69,7 @@ def workflow_2(x): assert not workflow.metadata["workflow_executor"] workflow.build_graph(1) - assert workflow.metadata["workflow_executor"] == DEFAULT_METADATA_VALUES["workflow_executor"] + assert workflow.metadata["workflow_executor"] == workflow.metadata["executor"] workflow_2.build_graph(1) assert workflow_2.metadata["workflow_executor"] == "custom_postprocessor"