Skip to content

Commit

Permalink
Remove unused lattice attributes
Browse files Browse the repository at this point in the history
- named_args
- named_kwargs
- cova_imports
- lattice_imports
  • Loading branch information
cjao committed May 29, 2024
1 parent f9326fa commit e4044c7
Show file tree
Hide file tree
Showing 22 changed files with 19 additions and 784 deletions.
33 changes: 1 addition & 32 deletions covalent/_results_manager/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import re
from datetime import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Set, Union
from typing import TYPE_CHECKING, Any, Dict, List, Union

from .._shared_files import logger
from .._shared_files.config import get_config
Expand Down Expand Up @@ -516,34 +516,3 @@ def _convert_to_electron_result(self) -> Any:
"""

return self._result


def _filter_cova_decorators(function_string: str, cova_imports: Set[str]) -> str:
"""
Given a string representing a function, comment out any Covalent-related decorators.
Args
function_string: A string representation of a workflow function.
Returns:
The function string with Covalent-related decorators commented out.
"""

has_cova_decorator = False
in_decorator = 0
function_lines = function_string.split("\n")
for i in range(len(function_lines)):
line = function_lines[i].strip()
if in_decorator > 0:
function_lines[i] = f"# {function_lines[i]}"
in_decorator += line.count("(")
in_decorator -= line.count(")")
elif line.startswith("@"):
decorator_name = line.split("@")[1].split(".")[0].split("(")[0]
if decorator_name in cova_imports:
function_lines[i] = f"# {function_lines[i]}"
has_cova_decorator = True
in_decorator += line.count("(")
in_decorator -= line.count(")")

return "\n".join(function_lines) if has_cova_decorator else function_string
43 changes: 0 additions & 43 deletions covalent/_serialize/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
"workflow_function_string": AssetType.TEXT,
"doc": AssetType.TEXT,
"inputs": AssetType.TRANSPORTABLE,
"named_args": AssetType.TRANSPORTABLE,
"named_kwargs": AssetType.TRANSPORTABLE,
"cova_imports": AssetType.JSONABLE,
"lattice_imports": AssetType.TEXT,
"hooks": AssetType.JSONABLE,
}

Expand Down Expand Up @@ -112,33 +108,6 @@ def _serialize_lattice_assets(lat, storage_path: str) -> LatticeAssets:
lat.inputs, ASSET_TYPES["inputs"], storage_path, ASSET_FILENAME_MAP["inputs"]
)

# Deprecate
named_args_asset = save_asset(
lat.named_args,
ASSET_TYPES["named_args"],
storage_path,
ASSET_FILENAME_MAP["named_args"],
)
named_kwargs_asset = save_asset(
lat.named_kwargs,
ASSET_TYPES["named_kwargs"],
storage_path,
ASSET_FILENAME_MAP["named_kwargs"],
)
cova_imports_asset = save_asset(
lat.cova_imports,
ASSET_TYPES["cova_imports"],
storage_path,
ASSET_FILENAME_MAP["cova_imports"],
)
lattice_imports_asset = save_asset(
lat.lattice_imports,
ASSET_TYPES["lattice_imports"],
storage_path,
ASSET_FILENAME_MAP["lattice_imports"],
)

# NOTE: these are actually JSONable
hooks_asset = save_asset(
lat.metadata["hooks"],
ASSET_TYPES["hooks"],
Expand All @@ -151,10 +120,6 @@ def _serialize_lattice_assets(lat, storage_path: str) -> LatticeAssets:
workflow_function_string=workflow_func_str_asset,
doc=docstring_asset,
inputs=inputs_asset,
named_args=named_args_asset,
named_kwargs=named_kwargs_asset,
cova_imports=cova_imports_asset,
lattice_imports=lattice_imports_asset,
hooks=hooks_asset,
)

Expand All @@ -166,20 +131,12 @@ def _deserialize_lattice_assets(assets: LatticeAssets) -> dict:
)
doc = load_asset(assets.doc, ASSET_TYPES["doc"])
inputs = load_asset(assets.inputs, ASSET_TYPES["inputs"])
named_args = load_asset(assets.named_args, ASSET_TYPES["named_args"])
named_kwargs = load_asset(assets.named_kwargs, ASSET_TYPES["named_kwargs"])
cova_imports = load_asset(assets.cova_imports, ASSET_TYPES["cova_imports"])
lattice_imports = load_asset(assets.lattice_imports, ASSET_TYPES["lattice_imports"])
hooks = load_asset(assets.hooks, ASSET_TYPES["hooks"])
return {
"workflow_function": workflow_function,
"workflow_function_string": workflow_function_string,
"__doc__": doc,
"inputs": inputs,
"named_args": named_args,
"named_kwargs": named_kwargs,
"cova_imports": cova_imports,
"lattice_imports": lattice_imports,
"metadata": {
"hooks": hooks,
},
Expand Down
14 changes: 6 additions & 8 deletions covalent/_shared_files/schemas/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
"workflow_function_string",
"__doc__",
"inputs",
"named_args",
"named_kwargs",
"cova_imports",
"lattice_imports",
# user dependent assets
"hooks",
}
Expand Down Expand Up @@ -83,10 +79,12 @@ class LatticeAssets(BaseModel):
workflow_function_string: AssetSchema
doc: AssetSchema # __doc__
inputs: AssetSchema
named_args: AssetSchema
named_kwargs: AssetSchema
cova_imports: AssetSchema
lattice_imports: AssetSchema

# Deprecated
named_args: AssetSchema = AssetSchema(size=0)
named_kwargs: AssetSchema = AssetSchema(size=0)
cova_imports: AssetSchema = AssetSchema(size=0)
lattice_imports: AssetSchema = AssetSchema(size=0)

# lattice.metadata
hooks: AssetSchema
Expand Down
12 changes: 1 addition & 11 deletions covalent/_workflow/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from ..executor import BaseExecutor
from ..triggers import BaseTrigger

from .._shared_files.utils import get_imports, get_serialized_function_str
from .._shared_files.utils import get_serialized_function_str

consumable_constraints = []

Expand Down Expand Up @@ -81,10 +81,7 @@ def __init__(
self.__doc__ = self.workflow_function.__doc__
self.post_processing = False
self.inputs = None
self.named_args = None
self.named_kwargs = None
self.electron_outputs = {}
self.lattice_imports, self.cova_imports = get_imports(self.workflow_function)

self.workflow_function = TransportableObject.make_transportable(self.workflow_function)

Expand All @@ -105,8 +102,6 @@ def serialize_to_json(self) -> str:
attributes["transport_graph"] = self.transport_graph.serialize_to_json()

attributes["inputs"] = self.inputs.to_dict()
attributes["named_args"] = self.named_args.to_dict()
attributes["named_kwargs"] = self.named_kwargs.to_dict()

attributes["electron_outputs"] = {}
for node_name, output in self.electron_outputs.items():
Expand All @@ -121,8 +116,6 @@ def deserialize_from_json(json_data: str) -> None:
for node_name, object_dict in attributes["electron_outputs"].items():
attributes["electron_outputs"][node_name] = TransportableObject.from_dict(object_dict)

attributes["named_kwargs"] = TransportableObject.from_dict(attributes["named_kwargs"])
attributes["named_args"] = TransportableObject.from_dict(attributes["named_args"])
attributes["inputs"] = TransportableObject.from_dict(attributes["inputs"])

if attributes["transport_graph"]:
Expand Down Expand Up @@ -209,9 +202,6 @@ def build_graph(self, *args, **kwargs) -> None:
new_kwargs = dict(named_kwargs.items())

self.inputs = TransportableObject({"args": args, "kwargs": kwargs})
self.named_args = TransportableObject(named_args)
self.named_kwargs = TransportableObject(named_kwargs)
self.lattice_imports, self.cova_imports = get_imports(workflow_function)

# Set any lattice metadata not explicitly set by the user
constraint_names = {"executor", "workflow_executor", "hooks"}
Expand Down
14 changes: 1 addition & 13 deletions covalent_dispatcher/_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,7 @@
from rich.console import Console

from .groups import db, deploy
from .service import (
cluster,
config,
logs,
migrate_legacy_result_object,
print_header,
purge,
restart,
start,
status,
stop,
)
from .service import cluster, config, logs, print_header, purge, restart, start, status, stop


# Main entrypoint
Expand Down Expand Up @@ -73,7 +62,6 @@ def cli(ctx: click.Context, version: bool) -> None:
cli.add_command(cluster)
cli.add_command(db)
cli.add_command(config)
cli.add_command(migrate_legacy_result_object)
cli.add_command(deploy)

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit e4044c7

Please sign in to comment.