Skip to content

Commit d1e15ca

Browse files
authored
Update examples to use us-west-2 (#49)
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.
1 parent 14be509 commit d1e15ca

File tree

7 files changed

+191
-58
lines changed

7 files changed

+191
-58
lines changed

examples/cluster.ipynb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
"source": [
88
"# Running on a cluster\n",
99
"\n",
10-
"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",
10+
"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",
1111
"\n",
12-
"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",
13-
"\n",
14-
"_*these Sentinel-2 COGs are in AWS's `us-west-2`; Coiled currently only offers `us-west-1`. But it's close enough._"
12+
"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."
1513
]
1614
},
1715
{
@@ -66,7 +64,7 @@
6664
"cluster = coiled.Cluster(\n",
6765
" name=\"stackstac\",\n",
6866
" software=\"gjoseph92/stackstac\",\n",
69-
" backend_options={\"region\": \"us-west-1\"},\n",
67+
" backend_options={\"region\": \"us-west-2\"},\n",
7068
")\n",
7169
"client = distributed.Client(cluster)\n",
7270
"client"
@@ -1740,4 +1738,4 @@
17401738
},
17411739
"nbformat": 4,
17421740
"nbformat_minor": 5
1743-
}
1741+
}

examples/show.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
" software=\"gjoseph92/stackstac\",\n",
144144
" n_workers=22,\n",
145145
" scheduler_cpu=2,\n",
146-
" backend_options={\"region\": \"us-west-1\"},\n",
146+
" backend_options={\"region\": \"us-west-2\"},\n",
147147
")\n",
148148
"client = distributed.Client(cluster)\n",
149149
"client"

poetry.lock

Lines changed: 82 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ipython = {version = "^7.20.0", optional = true}
2525
ipywidgets = {version = "^7.6.3", optional = true}
2626
jupyter-sphinx = {version = "^0.3.2", optional = true}
2727
jupyterlab-geojson = {version = "^3.1.2", optional = true}
28+
jupyterlab-system-monitor = {version = "^0.8.0", optional = true}
2829
matplotlib = {version = "^3.4.1", optional = true}
2930
mercantile = {version = "^1.1.6", optional = true}
3031
nbsphinx = {version = "^0.8.2", optional = true}
@@ -43,6 +44,7 @@ xarray = "^0.17.0"
4344

4445
[tool.poetry.dev-dependencies]
4546
Pympler = "^0.9"
47+
aiotools = "^1.2.1"
4648
awkward = {version = "^1.1.2", allow-prereleases = true}
4749
black = "^21.4b2"
4850
debugpy = "^1.2.1"
@@ -67,6 +69,7 @@ binder = [
6769
"ipyleaflet",
6870
"ipywidets",
6971
"jupyterlab-geojson",
72+
"jupyterlab-system-monitor",
7073
"matplotlib",
7174
"planetary-computer",
7275
"pystac-client",

scripts/coiled-envs.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Make Coiled software environments for stackstac in multiple regions,
3+
and upload all notebook files into a Coiled notebook (aka Job).
4+
"""
5+
6+
import asyncio
7+
import io
8+
import subprocess
9+
from pathlib import Path
10+
import sys
11+
from typing import List
12+
13+
import aiotools
14+
import coiled
15+
16+
17+
async def create_software_environment_quiet(
18+
cloud: coiled.Cloud[coiled.core.Async], **kwargs
19+
) -> None:
20+
log = io.StringIO()
21+
try:
22+
await cloud.create_software_environment(log_output=log, **kwargs)
23+
except Exception:
24+
print(
25+
f"Error creating software environment with {kwargs}:\n{log.getvalue()}",
26+
file=sys.stderr,
27+
)
28+
raise
29+
30+
print(f"Built environment for {kwargs.get('backend_options')}")
31+
32+
33+
async def make_coiled_stuff(
34+
deps: List[str],
35+
regions: List[str],
36+
name: str,
37+
) -> None:
38+
examples = Path(__file__).parent.parent / "examples"
39+
docs = Path(__file__).parent.parent / "docs"
40+
notebook_paths = list(examples.glob("*.ipynb")) + list(docs.glob("*.ipynb"))
41+
notebooks = list(map(str, notebook_paths))
42+
print(f"Notebooks: {notebooks}")
43+
44+
async with coiled.Cloud(asynchronous=True) as cloud:
45+
name_software = name + "-notebook"
46+
async with aiotools.TaskGroup(name="envs") as tg:
47+
# Build all the software environments in parallel in multiple regions
48+
tg.create_task(
49+
create_software_environment_quiet(
50+
cloud,
51+
name=name_software,
52+
container="coiled/notebook:latest",
53+
pip=deps,
54+
)
55+
)
56+
57+
for region in regions:
58+
tg.create_task(
59+
create_software_environment_quiet(
60+
cloud,
61+
name=name,
62+
pip=deps,
63+
backend_options={"region": region},
64+
)
65+
)
66+
67+
# Create job configuration for notebook
68+
await cloud.create_job_configuration(
69+
name=name,
70+
software=name_software,
71+
cpu=2,
72+
gpu=0,
73+
memory="8 GiB",
74+
command=["/bin/bash", "start.sh", "jupyter", "lab"],
75+
files=notebooks,
76+
ports=[8888],
77+
description="Example notebooks from the stackstac documentation",
78+
)
79+
print(f"Created notebook {name}")
80+
81+
82+
if __name__ == "__main__":
83+
proc = subprocess.run(
84+
"poetry export --without-hashes -E binder -E viz",
85+
shell=True,
86+
check=True,
87+
capture_output=True,
88+
text=True,
89+
)
90+
deps = proc.stdout.splitlines()
91+
92+
# TODO single-source the version! this is annoying
93+
version = subprocess.run(
94+
"poetry version -s", shell=True, check=True, capture_output=True, text=True
95+
).stdout.strip()
96+
print(f"Version: {version}")
97+
deps += [f"stackstac[binder,viz]=={version}"]
98+
99+
asyncio.run(
100+
make_coiled_stuff(deps, regions=["us-west-2", "eu-central-1"], name="stackstac")
101+
)

scripts/coiled-notebook.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

scripts/make-coiled-env.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)