
(netket_optimizer_api)=
# netket.optimizer

```{eval-rst}
.. currentmodule:: netket.optimizer
```

This module provides some optimisers,
implementations of the [Quantum Geometric Tensor](QGT_and_SR) and preconditioners such
as SR.

## Optimizers

Optimizers in NetKet are simple wrappers of [optax](https://github.com/deepmind/optax)
optimizers. If you want to write a custom optimizer or use more advanced ones, we suggest
you have a look at optax documentation.

Check it out for up-to-date information on available optimisers.

:::{warning}
Even if optimisers in `netket.optimizer` are optax optimisers, they have slightly different
names (they are capitalised) and the argument names have been rearranged and renamed.
This was chosen in order not to break our API from previous versions

In general, we advise you to directly use optax, as it is much more powerful, provides more
optimisers, and it's extremely easy to use step-dependent schedulers.
:::

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   Adam
   AdaGrad
   Sgd
   Momentum
   RmsProp

```

## Preconditioners

This module also provides an implementation of the Stochastic Reconfiguration/Natural
gradient preconditioner.

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   SR
```

## Quantum Geometric Tensor

It also provides the following implementation of the quantum geometric tensor:

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   qgt.QGTAuto
   qgt.QGTOnTheFly
   qgt.QGTJacobianPyTree
   qgt.QGTJacobianDense
```

(dense-solvers)=
## Dense solvers

And the following dense solvers for Stochastic Reconfiguration:

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   solver.cholesky_with_fallback
   solver.cholesky
   solver.LU
   solver.pinv
   solver.pinv_smooth
   solver.solve
   solver.svd
```

### Solver combinators

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   solver.nan_fallback
```

(multi-gpu-solvers)=
### Multi-GPU solvers

And the following dense solvers parallelize among multiple GPUs by making use of [JAXMg](https://flatironinstitute.github.io/jaxmg/).
They are not really much faster than the ones above, but allow you to use ~100k samples because they keep the NTK sharded across the multiple GPUs.

:::{warning}
Those solvers require `jaxmg >= 1.4.1`, which is not installed with NetKet. Install it with
the CUDA version matching your jax (`pip install 'jaxmg[cuda12]'` or `pip install 'jaxmg[cuda13]'`),
which also installs NVIDIA's cuSOLVERMp library. Every jaxmg release pins a narrow range of jax
versions, so installing it may change the version of jax you use.

As JAXMg builds upon NVIDIA's cuSOLVERMp, it requires **one python process per GPU**: run
your script with `djaxrun` (or call {func}`jax.distributed.initialize` yourself) such that
every process sees a single GPU. Both single-node and multi-node setups are supported.
:::

```{eval-rst}
.. autosummary::
   :toctree: _generated/optim
   :nosignatures:

   solver.cholesky_distributed
   solver.pinv_smooth_distributed
```
