Skip to content

Commit 4ad100c

Browse files
committed
Create a single set of example scripts that can run on any executor by specifying external config.
1 parent 41aac1b commit 4ad100c

File tree

7 files changed

+96
-0
lines changed

7 files changed

+96
-0
lines changed

examples/add-asarray.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import cubed.array_api as xp
2+
3+
if __name__ == "__main__":
4+
a = xp.asarray(
5+
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],
6+
chunks=(2, 2),
7+
)
8+
b = xp.asarray(
9+
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],
10+
chunks=(2, 2),
11+
)
12+
c = xp.add(a, b)
13+
res = c.compute()
14+
print(res)

examples/add-random.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
import cubed
4+
import cubed.array_api as xp
5+
import cubed.random
6+
from cubed.extensions.history import HistoryCallback
7+
from cubed.extensions.rich import RichProgressBar
8+
from cubed.extensions.timeline import TimelineVisualizationCallback
9+
10+
# suppress harmless connection pool warnings
11+
logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)
12+
13+
if __name__ == "__main__":
14+
# 200MB chunks
15+
a = cubed.random.random((50000, 50000), chunks=(5000, 5000))
16+
b = cubed.random.random((50000, 50000), chunks=(5000, 5000))
17+
c = xp.add(a, b)
18+
19+
progress = RichProgressBar()
20+
hist = HistoryCallback()
21+
timeline_viz = TimelineVisualizationCallback()
22+
# use store=None to write to temporary zarr
23+
cubed.to_zarr(
24+
c,
25+
store=None,
26+
callbacks=[progress, hist, timeline_viz],
27+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spec:
2+
work_dir: "s3://cubed-$USER-temp"
3+
allowed_mem: "2GB"
4+
executor_name: "lithops"
5+
executor_options:
6+
runtime: "cubed-runtime-dev"
7+
runtime_memory: 2000

examples/lithops/gcf/cubed.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spec:
2+
work_dir: "gs://cubed-$USER-temp"
3+
allowed_mem: "2GB"
4+
executor_name: "lithops"
5+
executor_options:
6+
runtime: "cubed-runtime-dev"
7+
runtime_memory: 2048

examples/matmul-random.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import logging
2+
3+
import cubed
4+
import cubed.array_api as xp
5+
import cubed.random
6+
from cubed.extensions.history import HistoryCallback
7+
from cubed.extensions.rich import RichProgressBar
8+
from cubed.extensions.timeline import TimelineVisualizationCallback
9+
10+
# suppress harmless connection pool warnings
11+
logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)
12+
13+
if __name__ == "__main__":
14+
# 200MB chunks
15+
a = cubed.random.random((50000, 50000), chunks=(5000, 5000))
16+
b = cubed.random.random((50000, 50000), chunks=(5000, 5000))
17+
c = xp.astype(a, xp.float32)
18+
d = xp.astype(b, xp.float32)
19+
e = xp.matmul(c, d)
20+
21+
progress = RichProgressBar()
22+
hist = HistoryCallback()
23+
timeline_viz = TimelineVisualizationCallback()
24+
# use store=None to write to temporary zarr
25+
cubed.to_zarr(
26+
e,
27+
store=None,
28+
callbacks=[progress, hist, timeline_viz],
29+
)

examples/modal/aws/cubed.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spec:
2+
work_dir: "s3://cubed-$USER-temp"
3+
allowed_mem: "2GB"
4+
executor_name: "modal"
5+
executor_options:
6+
cloud: "aws"

examples/modal/gcp/cubed.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spec:
2+
work_dir: "gs://cubed-$USER-temp"
3+
allowed_mem: "2GB"
4+
executor_name: "modal"
5+
executor_options:
6+
cloud: "gcp"

0 commit comments

Comments
 (0)