Skip to content

Commit

Permalink
Default workflow_executor to lattice-default executor
Browse files Browse the repository at this point in the history
This should eliminate the need to set workflow_executor explicitly in
many cases.
  • Loading branch information
cjao committed Nov 25, 2024
1 parent 05bf94d commit 89ab6c3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions covalent/_shared_files/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 2 additions & 9 deletions covalent/_workflow/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion covalent/_workflow/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 3 additions & 2 deletions tests/covalent_tests/workflow/electron_metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/covalent_tests/workflow/lattice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 89ab6c3

Please sign in to comment.