Skip to content

Commit

Permalink
Update examples to use us-west-2 (#49)
Browse files Browse the repository at this point in the history
Now that Coiled supports `us-west-2`, we can use that!

This also adds a script to build software environments in parallel in multiple regions. By creating envs in multiple regions up front, the first person won't have to wait for an image build when they spin up a cluster in one of the demos.

Also added `jupyterlab-system-monitor` for fun.
  • Loading branch information
gjoseph92 authored May 5, 2021
1 parent 14be509 commit d1e15ca
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 58 deletions.
10 changes: 4 additions & 6 deletions examples/cluster.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
"source": [
"# Running on a cluster\n",
"\n",
"We'll use a Dask cluster in the cloud—in this case, using [Coiled](https://coiled.io/)—to use many machines to process the data in parallel. We can also run in a data center near* where the data is stored for better performance.\n",
"We'll use a Dask cluster in the cloud—in this case, using [Coiled](https://coiled.io/)—to use many machines to process the data in parallel. We can also run in the data center where the data is stored for better performance.\n",
"\n",
"If you use Coiled (which is both easy to use, and currently free!), you can set `software=\"gjoseph92/stackstac\"` to get a software environment where the latest version of `stackstac` is already installed.\n",
"\n",
"_*these Sentinel-2 COGs are in AWS's `us-west-2`; Coiled currently only offers `us-west-1`. But it's close enough._"
"If you use Coiled (which is both easy to use, and currently free!), you can set `software=\"gjoseph92/stackstac\"` to get a software environment where the latest version of `stackstac` is already installed."
]
},
{
Expand Down Expand Up @@ -66,7 +64,7 @@
"cluster = coiled.Cluster(\n",
" name=\"stackstac\",\n",
" software=\"gjoseph92/stackstac\",\n",
" backend_options={\"region\": \"us-west-1\"},\n",
" backend_options={\"region\": \"us-west-2\"},\n",
")\n",
"client = distributed.Client(cluster)\n",
"client"
Expand Down Expand Up @@ -1740,4 +1738,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
2 changes: 1 addition & 1 deletion examples/show.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
" software=\"gjoseph92/stackstac\",\n",
" n_workers=22,\n",
" scheduler_cpu=2,\n",
" backend_options={\"region\": \"us-west-1\"},\n",
" backend_options={\"region\": \"us-west-2\"},\n",
")\n",
"client = distributed.Client(cluster)\n",
"client"
Expand Down
93 changes: 82 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ipython = {version = "^7.20.0", optional = true}
ipywidgets = {version = "^7.6.3", optional = true}
jupyter-sphinx = {version = "^0.3.2", optional = true}
jupyterlab-geojson = {version = "^3.1.2", optional = true}
jupyterlab-system-monitor = {version = "^0.8.0", optional = true}
matplotlib = {version = "^3.4.1", optional = true}
mercantile = {version = "^1.1.6", optional = true}
nbsphinx = {version = "^0.8.2", optional = true}
Expand All @@ -43,6 +44,7 @@ xarray = "^0.17.0"

[tool.poetry.dev-dependencies]
Pympler = "^0.9"
aiotools = "^1.2.1"
awkward = {version = "^1.1.2", allow-prereleases = true}
black = "^21.4b2"
debugpy = "^1.2.1"
Expand All @@ -67,6 +69,7 @@ binder = [
"ipyleaflet",
"ipywidets",
"jupyterlab-geojson",
"jupyterlab-system-monitor",
"matplotlib",
"planetary-computer",
"pystac-client",
Expand Down
101 changes: 101 additions & 0 deletions scripts/coiled-envs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""
Make Coiled software environments for stackstac in multiple regions,
and upload all notebook files into a Coiled notebook (aka Job).
"""

import asyncio
import io
import subprocess
from pathlib import Path
import sys
from typing import List

import aiotools
import coiled


async def create_software_environment_quiet(
cloud: coiled.Cloud[coiled.core.Async], **kwargs
) -> None:
log = io.StringIO()
try:
await cloud.create_software_environment(log_output=log, **kwargs)
except Exception:
print(
f"Error creating software environment with {kwargs}:\n{log.getvalue()}",
file=sys.stderr,
)
raise

print(f"Built environment for {kwargs.get('backend_options')}")


async def make_coiled_stuff(
deps: List[str],
regions: List[str],
name: str,
) -> None:
examples = Path(__file__).parent.parent / "examples"
docs = Path(__file__).parent.parent / "docs"
notebook_paths = list(examples.glob("*.ipynb")) + list(docs.glob("*.ipynb"))
notebooks = list(map(str, notebook_paths))
print(f"Notebooks: {notebooks}")

async with coiled.Cloud(asynchronous=True) as cloud:
name_software = name + "-notebook"
async with aiotools.TaskGroup(name="envs") as tg:
# Build all the software environments in parallel in multiple regions
tg.create_task(
create_software_environment_quiet(
cloud,
name=name_software,
container="coiled/notebook:latest",
pip=deps,
)
)

for region in regions:
tg.create_task(
create_software_environment_quiet(
cloud,
name=name,
pip=deps,
backend_options={"region": region},
)
)

# Create job configuration for notebook
await cloud.create_job_configuration(
name=name,
software=name_software,
cpu=2,
gpu=0,
memory="8 GiB",
command=["/bin/bash", "start.sh", "jupyter", "lab"],
files=notebooks,
ports=[8888],
description="Example notebooks from the stackstac documentation",
)
print(f"Created notebook {name}")


if __name__ == "__main__":
proc = subprocess.run(
"poetry export --without-hashes -E binder -E viz",
shell=True,
check=True,
capture_output=True,
text=True,
)
deps = proc.stdout.splitlines()

# TODO single-source the version! this is annoying
version = subprocess.run(
"poetry version -s", shell=True, check=True, capture_output=True, text=True
).stdout.strip()
print(f"Version: {version}")
deps += [f"stackstac[binder,viz]=={version}"]

asyncio.run(
make_coiled_stuff(deps, regions=["us-west-2", "eu-central-1"], name="stackstac")
)
33 changes: 0 additions & 33 deletions scripts/coiled-notebook.py

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/make-coiled-env.sh

This file was deleted.

0 comments on commit d1e15ca

Please sign in to comment.