Installing NetKet is very easy, but it has several complex and optional dependencies. In general, we suggest to create a virtual-environment for every project you work on.
python>= 3.9 and can optionally benefit from a recent MPI install.
GPUs are supported on linux.
Before attempting the installation, you should update
pip to a recent version (
>=20.3) to avoid getting a broken install.
To install the basic version with no optional dependencies, run the following commands:
pip install --upgrade pip
pip install --upgrade netket
To query the installed
netket version you can run the following command in your shell.
If all went well, you should have at least version 3.3 installed.
We recommend to always start a new project with the latest available version.
python -c "import netket; print(netket.__version__)"
If you experience an installation error under
pip, please make sure you have upgraded pip first and that you are not inside of a conda environment. If the install succeeds but you can’t load
netket, you most likely need to update the dependencies.
To get help, please open an issue pasting the output of
python -m netket.tools.info.
If you want to run NetKet on a GPU, you must install a GPU-compatible
jaxlib, which is only supported on Linux and requires
We advise you to look at the instructions on jax repository because they change from time to time.
At the time of writing, installing a GPU version of jaxlib is as simple as running the following command, assuming you have very recent versions of
pip install --upgrade pip
pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html
Where the jaxlib version must correspond to the version of the existing CUDA installation you want to use. Refer to jax documentation to learn more about matching cuda versions with python wheels.
NetKet (due to Jax) only uses 1 or 2 CPU cores or 1 GPU by default at once unless you work on huge systems with mastodontic neural-networks. If you want to use all your CPU cores, multiple GPUs, or run your code among many computers you’ll need to use MPI. If you want to use MPI, make sure mpi is installed and can be used. To know if MPI is installed, try running the following command.
If the command fails, you need to install MPI using your favourite package manager.
In general, for the love of yourself and in order to keep you sanity, we recommend not to use
conda together with MPI.
On Mac, we recommend to use homebrew:
brew install openmpi
On Linux, you can install it using your package manager:
sudo dnf install mpich
sudo apt-get install mpich
You can install the dependencies necessary to run with MPI with the following command:
pip install --upgrade
pip install --upgrade "netket[mpi]"
Subsequently, NetKet will exploit MPI-level parallelism for the Monte-Carlo sampling. See this block to understand how NetKet behaves under MPI.
Conda is a great package manager as long as it works. But when it does not, it’s a pain.
To install NetKet using conda, simply run
conda install -c conda-forge netket
This will also install the conda MPI compilers and the MPI-related dependencies. This often creates problems if you also have a system MPI. Moreover, you should never use conda’s MPI on a supercomputing cluster.
In general, we advise against using conda or conda environments to install NetKet unless someone is pointing a gun at you. If you don’t want to die from that bullet, but would rather loose your mental sanity fighting conda, do expect weird setup errors.
Netket is a numerical framework written in Python to simulate many-body quantum systems using variational methods. In general, netket allows the user to parametrize quantum states using arbitrary functions, be it simple mean-field Ansätze, Jastrow, MPS Ansätze or convolutional neural networks. Those states can be sampled efficiently in order to estimate observables or other quantities. Stochastic optimisation of the energy or a time-evolution are implemented on top of those samplers.
Netket tries to follow the functional programming paradigm, and is built around jax. While it is possible to run the examples without knowledge of [jax], we strongly recommend getting familiar with it if you wish to extend netket.
This documentation is divided into several modules, each explaining in-depth how a sub-module of netket works. You can select a module from the list on the left, or you can read the following example which contains links to all relevant parts of the documentation.
NetKet v3 API is centered around flax, a JAX-based library providing components to define and use neural network models.
If you want to define more complex custom models, you should read Flax documentation on how to define a Linen module.
If you wish, you can also use haiku.
netket.optimizer is a re-export of some optimizers from optax together with some additional objects.
netket.jax there are a few functions, notably
jax.vjp adapted to work with arbitrary real or complex functions, and/or with MPI.