Skip to main content

Foundation models and utilities for NetKet

Project description

NetKet Foundation

NetKet Foundation is an extension for NetKet to train and evaluate foundation neural quantum states over families of Hamiltonians parameterized by couplings or disorder realizations.

The library builds on top of NetKet's concepts (samplers, operators, logging, drivers) and introduces foundational workflows where one model is optimized across many parameter points at once.

Installation

You can install netket-foundation with pip or uv using one of the two commands below. We strongly recomend against using conda.

uv add netket-foundation
pip install --upgrade nektet-foundation

With GPU support (Linux only):

uv add netket-foundation 'netket[cuda]'

Development version:

uv add git+https://github.com/NeuralQXLab/netket_foundation.git

For detailed installation instructions of NetKet, including GPU setup, we refer to its installation guide.

Getting Started

To get started with NetKet Foundation, we recommend you give a look at our tutorials, by running them on your computer or on Google Colaboratory. There are also several example scripts that you can download, run and edit that showcase some use-cases of NetKet Foundation, although they are not commented.

If you want to get in touch with us, feel free to open an issue or a discussion here on GitHub, or to join the MLQuantum slack group where several people involved with NetKet hang out. The link is on NetKet's website.

New concepts:

Compared to base NetKet, this package introduces:

  • ParameterSpace: a Hilbert-space-like class describing the space where hamiltonian parameters live.
  • FoundationalQuantumState: a variational state that samples physical configurations together with parameter replicas.
  • ParametrizedOperator: operators whose matrix elements are generated from per-sample parameters.

Minimal Usage

1) Define a foundational state over a parameter range

import jax.numpy as jnp
import netket as nk
import netket_foundation as nkf

from netket_foundation._src.model.vit import ViTFNQS

hi = nk.hilbert.Spin(0.5, 10)
ps = nkf.ParameterSpace(N=1, min=0.8, max=1.2)

model = ViTFNQS(
	num_layers=2,
	d_model=12,
	heads=4,
	L_eff=hi.size // 2,
	n_coups=ps.size,
	b=2,
	complex=False,
	disorder=False,
	transl_invariant=True,
	two_dimensional=False,
)

sampler = nk.sampler.MetropolisLocal(hi, n_chains=2048)
vstate = nkf.FoundationalQuantumState(sampler, model, ps, n_replicas=8, seed=1)

# Define the coupling used during training
vstate.parameter_array = jnp.linspace(0.8, 1.2, vstate.n_replicas).reshape(-1, 1)

2) Build a parameter-dependent operator

import netket_foundation as nkf

def create_operator(params):
	h = params[0]
	ha_x = sum(nkf.operator.sigmax(hi, i) for i in range(hi.size))
	ha_zz = sum(
		nkf.operator.sigmaz(hi, i) @ nkf.operator.sigmaz(hi, (i + 1) % hi.size)
		for i in range(hi.size)
	)
	return -h * ha_x - ha_zz

ham = nkf.operator.ParametrizedOperator(hi, ps, create_operator)

3) Optimize with foundational natural-gradient VMC

import optax
import netket_foundation as nkf

optimizer = optax.sgd(5e-3)
driver = nkf.VMC_SR(ham, optimizer, variational_state=vstate, diag_shift=1e-4)
driver.run(100)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netket_foundation-0.1.1.tar.gz (76.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netket_foundation-0.1.1-py3-none-any.whl (99.2 kB view details)

Uploaded Python 3

File details

Details for the file netket_foundation-0.1.1.tar.gz.

File metadata

  • Download URL: netket_foundation-0.1.1.tar.gz
  • Upload date:
  • Size: 76.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for netket_foundation-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7ff4ccc14e84369ab18ea85d4ce1ea42e7a20f65f1c76dc5fccf6771dbc7236
MD5 d8455da06256e71011e73be995fe5020
BLAKE2b-256 9ad8e415ce90cc169cc2a5e07fd92a1182804e5f866670a2d02f2d6563ec6c60

See more details on using hashes here.

Provenance

The following attestation bundles were made for netket_foundation-0.1.1.tar.gz:

Publisher: release.yml on NeuralQXLab/netket_foundation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file netket_foundation-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for netket_foundation-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 979d5ac61bca00f086db45b406095abcc2d7e15e295d601473ff43fc76d70f03
MD5 080945dedc485e0a0fe4830537e38e46
BLAKE2b-256 40fa00445c2a9c7dc4bd794302fca55c77c6ea8b5cd9f78b0fe125515c08d567

See more details on using hashes here.

Provenance

The following attestation bundles were made for netket_foundation-0.1.1-py3-none-any.whl:

Publisher: release.yml on NeuralQXLab/netket_foundation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page