Skip to content

Commit

Permalink
Merge pull request #341 from latchbio/ayush/hannah-sm-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushkamat authored Nov 13, 2023
2 parents f012328 + 17d0cb0 commit 20e5fae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
18 changes: 2 additions & 16 deletions latch_cli/snakemake/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,11 @@ def generate_snakemake_entrypoint(
from latch.types.file import LatchFile
from latch_cli.utils import get_parameter_json_value, urljoins, check_exists_and_rename
from latch_cli.snakemake.serialize_utils import update_mapping
sys.stdout.reconfigure(line_buffering=True)
sys.stderr.reconfigure(line_buffering=True)
def update_mapping(local: Path, remote: str, mapping: Dict[str, str]):
if local.is_file():
mapping[str(local)] = remote
return
for p in local.iterdir():
update_mapping(p, urljoins(remote, p.name), mapping)
def si_unit(num, base: float = 1000.0):
for unit in (" ", "k", "M", "G", "T", "P", "E", "Z"):
Expand Down Expand Up @@ -459,6 +452,7 @@ def generate_jit_register_code(
)
from latch_cli.utils import get_parameter_json_value, check_exists_and_rename
import latch_cli.snakemake
from latch_cli.snakemake.serialize_utils import update_mapping
from latch_cli.utils import urljoins
from latch import small_task
Expand All @@ -474,14 +468,6 @@ def generate_jit_register_code(
sys.stdout.reconfigure(line_buffering=True)
sys.stderr.reconfigure(line_buffering=True)
def update_mapping(local: Path, remote: str, mapping: Dict[str, str]):
if local.is_file():
mapping[str(local)] = remote
return
for p in local.iterdir():
update_mapping(p, urljoins(remote, p.name), mapping)
def si_unit(num, base: float = 1000.0):
for unit in (" ", "k", "M", "G", "T", "P", "E", "Z"):
Expand Down
20 changes: 17 additions & 3 deletions latch_cli/snakemake/serialize_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from pathlib import Path
from typing import Dict, Union

from flytekit import LaunchPlan
Expand All @@ -18,6 +19,8 @@
from flytekit.models.core.workflow import TaskNodeOverrides
from typing_extensions import TypeAlias

from latch_cli.utils import urljoins

FlyteLocalEntity: TypeAlias = Union[
PythonTask,
Node,
Expand Down Expand Up @@ -213,6 +216,17 @@ def get_serializable_workflow(
return admin_wf


def best_effort_display_name(x: str):
expr = re.compile(r"_+")
return expr.sub(" ", x).title().strip()
def update_mapping(cur: Path, stem: Path, remote: str, mapping: Dict[str, str]):
if cur.is_file():
mapping[str(stem)] = remote
return

for p in cur.iterdir():
update_mapping(p, stem / p.name, urljoins(remote, p.name), mapping)


underscores = re.compile(r"_+")


def best_effort_display_name(x: str) -> str:
return underscores.sub(" ", x).title().strip()
19 changes: 16 additions & 3 deletions latch_cli/snakemake/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,13 @@ def get_fn_code(
code_block += reindent(
rf"""
print(f"Moving {param} to {{{param}_dst_p}}")
update_mapping({param}_p, {param}_dst_p, {param}.remote_path, local_to_remote_path_mapping)
check_exists_and_rename(
{param}_p,
{param}_dst_p
)
update_mapping({param}_dst_p, {param}.remote_path, local_to_remote_path_mapping)
""",
1,
)
Expand Down Expand Up @@ -1261,11 +1261,12 @@ def get_fn_code(
}

if remote_output_url is None:
remote_path = Path("/Snakemake Outputs") / self.wf.name
remote_path = Path("/Snakemake Outputs") / self.wf.name / self.job.name
else:
remote_path = Path(urlparse(remote_output_url).path)

log_files = self.job.log if self.job.log is not None else []
output_files = self.job.output if self.job.output is not None else []

code_block += reindent(
rf"""
Expand Down Expand Up @@ -1344,6 +1345,18 @@ def get_fn_code(
lp.upload(local, remote)
print(" Done")
print("Uploading outputs:")
for x in {repr(output_files)}:
local = Path(x)
remote = f"latch://{remote_path}/{{str(local).removeprefix('/')}}"
print(f" {{file_name_and_size(local)}} -> {{remote}}")
if not local.exists():
print(" Does not exist")
continue
lp.upload(local, remote)
print(" Done")
benchmark_file = {repr(self.job.benchmark)}
if benchmark_file is not None:
print("\nUploading benchmark:")
Expand Down

0 comments on commit 20e5fae

Please sign in to comment.