Skip to content

Commit 208af74

Browse files
committed
fix: skip the jax-only cluster simulator and tutorial when jax is absent
CI's Python 3.13 leg deliberately runs the lean no-optional-deps path without jax; the new cluster simulator imports jax for its jitted multi-plane PointSolver, failing that leg (and the cluster tutorial with it via the auto-simulate subprocess). Both now use the established importlib find_spec / sys.exit(0) guard — the same idiom as the two jax-only chapter 3 tutorials — exiting cleanly with an explanatory message when jax is missing, verified both with jax removed (clean skip) and present (full run). Notebooks regenerated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BxKfSZisjnEn91LRGkN4SU
1 parent 50c9a1d commit 208af74

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

notebooks/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.ipynb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@
132132
"cell_type": "code",
133133
"metadata": {},
134134
"source": [
135+
"\n",
136+
"import importlib.util\n",
137+
"import sys\n",
138+
"\n",
139+
"if importlib.util.find_spec(\"jax\") is None:\n",
140+
" print(\n",
141+
" \"Skipping this tutorial: it requires the `jax` package (used to \"\n",
142+
" \"accelerate the multi-plane point-source solves), which is not \"\n",
143+
" \"installed (install with `pip install autolens[optional]`).\"\n",
144+
" )\n",
145+
" sys.exit(0)\n",
135146
"\n",
136147
"from autolens import jax_wrapper # Sets JAX environment before other imports\n",
137148
"\n",

notebooks/simulator/cluster.ipynb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@
9595
"cell_type": "code",
9696
"metadata": {},
9797
"source": [
98+
"\n",
99+
"import importlib.util\n",
100+
"import sys\n",
101+
"\n",
102+
"if importlib.util.find_spec(\"jax\") is None:\n",
103+
" print(\n",
104+
" \"Skipping this simulator: it requires the `jax` package, which is not \"\n",
105+
" \"installed (install with `pip install autolens[optional]`).\"\n",
106+
" )\n",
107+
" sys.exit(0)\n",
98108
"\n",
99109
"from autolens import jax_wrapper # Sets JAX environment before other imports\n",
100110
"\n",

scripts/chapter_4_scaling_up_lensing/tutorial_5_cluster_scale.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@
8585
redshift for every source.
8686
"""
8787

88+
import importlib.util
89+
import sys
90+
91+
if importlib.util.find_spec("jax") is None:
92+
print(
93+
"Skipping this tutorial: it requires the `jax` package (used to "
94+
"accelerate the multi-plane point-source solves), which is not "
95+
"installed (install with `pip install autolens[optional]`)."
96+
)
97+
sys.exit(0)
98+
8899
from autolens import jax_wrapper # Sets JAX environment before other imports
89100

90101
# from autolens import setup_notebook; setup_notebook()

scripts/simulator/cluster.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
If any code in this script is unclear, refer to the `autolens_workspace/*/cluster/simulator.ipynb` notebook.
4949
"""
5050

51+
import importlib.util
52+
import sys
53+
54+
if importlib.util.find_spec("jax") is None:
55+
print(
56+
"Skipping this simulator: it requires the `jax` package, which is not "
57+
"installed (install with `pip install autolens[optional]`)."
58+
)
59+
sys.exit(0)
60+
5161
from autolens import jax_wrapper # Sets JAX environment before other imports
5262

5363
# from autolens import setup_notebook; setup_notebook()

0 commit comments

Comments
 (0)