Skip to content

Commit

Permalink
🚚 Rename .stage() to .cache(), add .save(upload=None) (#369)
Browse files Browse the repository at this point in the history
* 🚚 Rename stage to download

* ✨ Add a upload() method to Artifact

* 🚚 Rename download to cache

* ♻️ Replace new method with flag in save()

* ♻️ Fix
  • Loading branch information
falexwolf authored Apr 16, 2024
1 parent 7a5c62f commit 9eb51b0
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1915,33 +1915,28 @@ def load(
Load as an `AnnData`:
>>> ln.Artifact("s3://lamindb-ci/lndb-storage/pbmc68k.h5ad").save()
>>> artifact = ln.Artifact.filter(key="lndb-storage/pbmc68k.h5ad").one()
>>> artifact.load()
AnnData object with n_obs Γ— n_vars = 70 Γ— 765
Fall back to :meth:`~lamindb.Artifact.stage` if no in-memory representation is configured:
Fall back to :meth:`~lamindb.Artifact.cache` if no in-memory representation is configured:
>>> ln.Artifact(ln.core.datasets.file_jpg_paradisi05(), description="paradisi05").save()
>>> artifact = ln.Artifact.filter(description="paradisi05").one()
>>> artifact.load()
PosixPath('/home/runner/work/lamindb/lamindb/docs/guide/mydata/.lamindb/jb7BY5UJoQVGMUOKiLcn.jpg')
"""
pass

def stage(self, is_run_input: bool | None = None) -> Path:
"""Update cache from cloud storage if outdated.
def cache(self, is_run_input: bool | None = None) -> Path:
"""Download cloud artifact to local cache.
Follows synching logic: only caches an artifact if it's outdated in the local cache.
Returns a path to a locally cached on-disk object (say, a `.jpg` file).
Examples:
Sync file from cloud and return the local path of the cache:
>>> ln.settings.storage = "s3://lamindb-ci"
>>> ln.Artifact("s3://lamindb-ci/lndb-storage/pbmc68k.h5ad").save()
>>> artifact = ln.Artifact.filter(key="lndb-storage/pbmc68k.h5ad").one()
>>> artifact.stage()
>>> artifact.cache()
PosixPath('/home/runner/work/Caches/lamindb/lamindb-ci/lndb-storage/pbmc68k.h5ad')
"""
pass
Expand Down Expand Up @@ -1969,9 +1964,13 @@ def delete(
"""
pass

def save(self, *args, **kwargs) -> None:
def save(self, upload: bool | None = None, **kwargs) -> None:
"""Save to database & storage.
Args:
upload: Trigger upload to cloud storage in instances with hybrid
storage mode.
Examples:
>>> artifact = ln.Artifact("./myfile.csv", description="myfile")
>>> artifact.save()
Expand Down Expand Up @@ -2158,7 +2157,7 @@ def mapped(
virtually concatenating `AnnData` arrays.
If your `AnnData` collection is in the cloud, move them into a local
cache first via :meth:`~lamindb.Collection.stage`.
cache first via :meth:`~lamindb.Collection.cache`.
`__getitem__` of the `MappedCollection` object takes a single integer index
and returns a dictionary with the observation data sample for this index from
Expand Down Expand Up @@ -2199,10 +2198,12 @@ def mapped(
"""
pass

def stage(self, is_run_input: bool | None = None) -> list[UPath]:
"""Update cache from cloud storage if outdated.
def cache(self, is_run_input: bool | None = None) -> list[UPath]:
"""Download cloud artifacts in collection to local cache.
Follows synching logic: only caches outdated artifacts.
Returns paths to locally cached on-disk objects in the collection.
Returns paths to locally cached on-disk artifacts.
Args:
is_run_input: Whether to track this collection as run input.
Expand Down

0 comments on commit 9eb51b0

Please sign in to comment.