GitHub

@@ -15,15 +15,15 @@ kernelspec:

15151616

This lecture provides a short introduction to [Google JAX](https://github.com/jax-ml/jax).

171718-

JAX is a high-performance scientific computing library that provides

18+

JAX is a high-performance scientific computing library that provides

191920-

* a NumPy-like interface that can automatically parallize across CPUs and GPUs,

20+

* a [NumPy](https://en.wikipedia.org/wiki/NumPy)-like interface that can automatically parallelize across CPUs and GPUs,

2121

* a just-in-time compiler for accelerating a large range of numerical

2222

operations, and

23-

* automatic differentiation.

23+

* [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation).

242425-

Increasingly, JAX also maintains and provides more specialized scientific

26-

computing routines, such as those originally found in SciPy.

25+

Increasingly, JAX also maintains and provides [more specialized scientific

26+

computing routines](https://docs.jax.dev/en/latest/jax.scipy.html), such as those originally found in [SciPy](https://en.wikipedia.org/wiki/SciPy).

27272828

In addition to what's in Anaconda, this lecture will need the following libraries:

2929

@@ -36,7 +36,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie

3636

```{admonition} GPU

3737

:class: warning

383839-

This lecture is accelerated via [hardware](status:machine-details) that has access to a GPU and target JAX for GPU programming.

39+

This lecture is accelerated via [hardware](status:machine-details) that has access to a GPU and targets JAX for GPU programming.

40404141

Free GPUs are available on Google Colab.

4242

To use this option, please click on the play icon top right, select Colab, and set the runtime environment to include a GPU.

@@ -50,7 +50,7 @@ If you would like to install JAX running on the `cpu` only you can use `pip inst

5050

One of the attractive features of JAX is that, whenever possible, its array

5151

processing operations conform to the NumPy API.

525253-

This means that, in many cases, we can use JAX is as a drop-in NumPy replacement.

53+

This means that, in many cases, we can use JAX as a drop-in NumPy replacement.

54545555

Let's look at the similarities and differences between JAX and NumPy.

5656

@@ -199,7 +199,7 @@ a, a_new

199199

```

200200201201

The designers of JAX chose to make arrays immutable because JAX uses a

202-

*functional programming style*.

202+

[functional programming](https://en.wikipedia.org/wiki/Functional_programming) style.

203203204204

This design choice has important implications, which we explore next!

205205

@@ -241,19 +241,19 @@ In other words, JAX assumes a functional programming style.

241241242242

The major implication is that JAX functions should be pure.

243243244-

**Pure functions** have the following characteristics:

244+

[Pure functions](https://en.wikipedia.org/wiki/Pure_function) have the following characteristics:

245245246246

1. *Deterministic*

247247

2. *No side effects*

248248249-

**Deterministic** means

249+

[Deterministic](https://en.wikipedia.org/wiki/Deterministic_algorithm) means

250250251251

* Same input $\implies$ same output

252252

* Outputs do not depend on global state

253253254254

In particular, pure functions will always return the same result if invoked with the same inputs.

255255256-

**No side effects** means that the function

256+

[No side effects](https://en.wikipedia.org/wiki/Side_effect_(computer_science)) means that the function

257257258258

* Won't change global state

259259

* Won't modify data passed to the function (immutable data)

@@ -307,7 +307,7 @@ At first you might find the syntax rather verbose.

307307

But you will soon realize that the syntax and semantics are necessary in order

308308

to maintain the functional programming style we just discussed.

309309310-

Moreover, full control of random state

310+

Moreover, full control of random state is

311311

essential for parallel programming, such as when we want to run independent experiments along multiple threads.

312312313313

@@ -793,8 +793,8 @@ We defer further exploration of automatic differentiation with JAX until {doc}`j

793793

:label: jax_intro_ex2

794794

```

795795796-

In the Exercise section of {doc}`our lecture on Numba <numba>`, we used Monte

797-

Carlo to price a European call option.

796+

In the Exercise section of {doc}`our lecture on Numba <numba>`, we {ref}`used Monte

797+

Carlo to price a European call option <numba_ex4>`.

798798799799

The code was accelerated by Numba-based multithreading.

800800

Read the original on github.com ↗