|
157 | 157 | }, |
158 | 158 | { |
159 | 159 | "cell_type": "code", |
160 | | - "execution_count": null, |
| 160 | + "execution_count": 1, |
161 | 161 | "metadata": {}, |
162 | 162 | "outputs": [], |
163 | 163 | "source": [ |
|
178 | 178 | "cell_type": "markdown", |
179 | 179 | "metadata": {}, |
180 | 180 | "source": [ |
181 | | - "In this section, we'll demonstrate the basic usage of CAX with pre-implemented cellular automata. We'll instantiate Conway's Game of Life and visualize a glider pattern, showing how easily you can get started with existing models in the library." |
| 181 | + "In this section, we'll demonstrate the basic usage of CAX with pre-implemented cellular automata. We'll instantiate Conway's Game of Life and visualize a glider pattern, showing how easily you can get started with existing systems in the library." |
182 | 182 | ] |
183 | 183 | }, |
184 | 184 | { |
|
215 | 215 | "cell_type": "markdown", |
216 | 216 | "metadata": {}, |
217 | 217 | "source": [ |
218 | | - "### Model" |
| 218 | + "### System" |
219 | 219 | ] |
220 | 220 | }, |
221 | 221 | { |
|
231 | 231 | "metadata": {}, |
232 | 232 | "outputs": [], |
233 | 233 | "source": [ |
234 | | - "from cax.models.life import Life\n", |
| 234 | + "from cax.systems.life import Life\n", |
235 | 235 | "\n", |
236 | 236 | "ca = Life(rngs=rngs)" |
237 | 237 | ] |
238 | 238 | }, |
| 239 | + { |
| 240 | + "cell_type": "code", |
| 241 | + "execution_count": null, |
| 242 | + "metadata": {}, |
| 243 | + "outputs": [], |
| 244 | + "source": [ |
| 245 | + "ca.update.update_birth_survival_from_string(\"B3/S23\")" |
| 246 | + ] |
| 247 | + }, |
239 | 248 | { |
240 | 249 | "cell_type": "markdown", |
241 | 250 | "metadata": {}, |
|
247 | 256 | "cell_type": "markdown", |
248 | 257 | "metadata": {}, |
249 | 258 | "source": [ |
250 | | - "Then, we define a function to sample an initial state, which is essential for running a model." |
| 259 | + "Then, we define a function to sample an initial state, which is essential for running a system." |
251 | 260 | ] |
252 | 261 | }, |
253 | 262 | { |
|
282 | 291 | "cell_type": "markdown", |
283 | 292 | "metadata": {}, |
284 | 293 | "source": [ |
285 | | - "Given an initial state and the model, we can simulate for `num_steps`." |
| 294 | + "Given an initial state and the system, we can simulate for `num_steps`." |
286 | 295 | ] |
287 | 296 | }, |
288 | 297 | { |
|
308 | 317 | "source": [ |
309 | 318 | "Finally, we can visualize the trajectory of states.\n", |
310 | 319 | "\n", |
311 | | - "All models should include a `render` method to convert a state into an RGB frame. For the Game of Life, a ready-to-use `render` method is provided, allowing you to easily generate a frame with a simple call: `frame = ca.render(state)`.\n", |
| 320 | + "All systems should include a `render` method to convert a state into an RGB frame. For the Game of Life, a ready-to-use `render` method is provided, allowing you to easily generate a frame with a simple call: `frame = ca.render(state)`.\n", |
312 | 321 | "\n", |
313 | 322 | "Enjoy! 👾" |
314 | 323 | ] |
|
349 | 358 | "cell_type": "markdown", |
350 | 359 | "metadata": {}, |
351 | 360 | "source": [ |
352 | | - "While visualizing the trajectory of states can produce captivating simulations, we often also want to track additional metrics to better understand how the model evolves over time.\n", |
| 361 | + "While visualizing the trajectory of states can produce captivating simulations, we often also want to track additional metrics to better understand how the system evolves over time.\n", |
353 | 362 | "\n", |
354 | | - "By default, the metrics function in CAX returns the states encountered during the model’s rollout. However, this behavior is highly customizable. In this section, we’ll explore how to create a tailored metrics function to log custom metrics suited to your needs.\n", |
| 363 | + "By default, the metrics function in CAX returns the states encountered during the system’s rollout. However, this behavior is highly customizable. In this section, we’ll explore how to create a tailored metrics function to log custom metrics suited to your needs.\n", |
355 | 364 | "\n", |
356 | 365 | "A metrics function must accept the next state, the current state, the perception, and the input as its parameters. For the Game of Life, however, the input parameter is not utilized, and can safely be ignored." |
357 | 366 | ] |
|
388 | 397 | "ca = Life(rngs=rngs, metrics_fn=custom_metrics_fn)" |
389 | 398 | ] |
390 | 399 | }, |
| 400 | + { |
| 401 | + "cell_type": "code", |
| 402 | + "execution_count": null, |
| 403 | + "metadata": {}, |
| 404 | + "outputs": [], |
| 405 | + "source": [ |
| 406 | + "ca.update.update_birth_survival_from_string(\"B3/S23\")" |
| 407 | + ] |
| 408 | + }, |
391 | 409 | { |
392 | 410 | "cell_type": "markdown", |
393 | 411 | "metadata": {}, |
|
410 | 428 | "cell_type": "markdown", |
411 | 429 | "metadata": {}, |
412 | 430 | "source": [ |
413 | | - "Let's run the model:" |
| 431 | + "Let's run the system:" |
414 | 432 | ] |
415 | 433 | }, |
416 | 434 | { |
|
510 | 528 | "cell_type": "markdown", |
511 | 529 | "metadata": {}, |
512 | 530 | "source": [ |
513 | | - "When using `nnx.Module`s with rngs in the state, we need to use `nnx.split_rngs` to properly vectorize over rngs state across parallel operations. For Conway's Game of Life specifically, the model doesn't use randomness during execution, so we could use `nnx.vmap` directly. However, we'll demonstrate the more general approach with `nnx.split_rngs` below, which works for any model that maintains rngs state." |
| 531 | + "When using `nnx.Module`s with rngs in the state, we need to use `nnx.split_rngs` to properly vectorize over rngs state across parallel operations. For Conway's Game of Life specifically, the system doesn't use randomness during execution, so we could use `nnx.vmap` directly. However, we'll demonstrate the more general approach with `nnx.split_rngs` below, which works for any systems that maintain rngs state." |
514 | 532 | ] |
515 | 533 | }, |
516 | 534 | { |
|
614 | 632 | "cell_type": "markdown", |
615 | 633 | "metadata": {}, |
616 | 634 | "source": [ |
617 | | - "CAX provides a set of perceive models. In this notebook, we will use a simple convolution perceive module." |
| 635 | + "CAX provides a set of perceive modules. In this notebook, we will use a simple convolution perceive module." |
618 | 636 | ] |
619 | 637 | }, |
620 | 638 | { |
|
643 | 661 | "cell_type": "markdown", |
644 | 662 | "metadata": {}, |
645 | 663 | "source": [ |
646 | | - "CAX provides a set of update models. In this notebook, we will use a residual MLP update module." |
| 664 | + "CAX provides a set of update modules. In this notebook, we will use a residual MLP update module." |
647 | 665 | ] |
648 | 666 | }, |
649 | 667 | { |
|
685 | 703 | "metadata": {}, |
686 | 704 | "outputs": [], |
687 | 705 | "source": [ |
688 | | - "from cax.core.ca import CA\n", |
689 | | - "from cax.utils.render import clip_and_uint8, rgba_to_rgb\n", |
| 706 | + "from cax.core import CA\n", |
| 707 | + "from cax.utils import clip_and_uint8, rgba_to_rgb\n", |
690 | 708 | "\n", |
691 | 709 | "\n", |
692 | 710 | "class MyCustomCA(CA):\n", |
|
856 | 874 | "name": "python", |
857 | 875 | "nbconvert_exporter": "python", |
858 | 876 | "pygments_lexer": "ipython3", |
859 | | - "version": "3.12.8" |
| 877 | + "version": "3.13.3" |
860 | 878 | } |
861 | 879 | }, |
862 | 880 | "nbformat": 4, |
|
0 commit comments