Skip to main content

Library to serialise objects arising from scientific and Machine Learning libraries, including NetKet.

Project description

NQXPack

A library to save and load objects coming from Scientific Machine Learning libraries, with a special attention to Neural Quantum States from NetKet.

Goals:

  • Simple format, possible to hand-edit and inspect manually;
  • Compatibility among Python version;
  • Allows to load Neural Networks with a single load command;

Usage

Install with

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

or (but seriously, stop using pip and start using uv)

pip install git+https://github.com/NeuralQXLab/nqxpack.git

With flax.linen

Save a dictionary containing the model and the parameters.

import nqxpack
import jax
from flax import linen as nn

model = nn.Sequential(
    nn.Dense(features=2),
    nn.gelu,
    nn.Dense(features=1),
    jax.numpy.squeeze,
)

variables = model.init(jax.random.key(1), jax.numpy.ones((2,4)))

nqxpack.save({'model':model, 'variables':variables}, "mymodel.nk")

loaded_dict = nqxpack.load("mymodel.nk")
loaded_model, loaded_variables = loaded_dict['model'], loaded_dict['variables']

With NetKet

import nqxpack
import netket as nk

hi = nk.hilbert.Spin(0.5, 10)
operator = nk.operator.spin.sigmax(nqs_state.hilbert, 1)

nqs_state = nk.vqs.MCState(nk.sampler.MetropolisLocal(hi), nk.models.RBM(alpha=4))
# print expectation value:
nqs_state.expect(operator)

nqxpack.save(nqs_state, "nqs_state.nk")
nqs_state_loaded = nqxpack.load("nqs_state.nk")

nqs_state_loaded.expect(operator)

The format

The format is a single zip file. You can decompress it yourself and look into it.

Feedback required

If you use this library, please let us know of any issue you might find.

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

nqxpack-0.1.2.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

nqxpack-0.1.2-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file nqxpack-0.1.2.tar.gz.

File metadata

  • Download URL: nqxpack-0.1.2.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nqxpack-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3612d85b7a93a5cc4494168c53528021bcfc64a6745201f2813d1d91fa16e895
MD5 580d8c4aa5a789f8a385721c04ce196e
BLAKE2b-256 44f4fea7bf747b86f4b527bce3d0e845099a6f8827e82dfca7aedab36b800040

See more details on using hashes here.

Provenance

The following attestation bundles were made for nqxpack-0.1.2.tar.gz:

Publisher: publish.yml on NeuralQXLab/nqxpack

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

File details

Details for the file nqxpack-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nqxpack-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nqxpack-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 053309f48e581d972b8709c69042e29638fc1f596431e9ba2b310e50530833b9
MD5 ab24d2a6daa440ef709b04e51aef19da
BLAKE2b-256 c7f9390de89c01044ecffebbf2bd21fd303d58bfc9b1da3c68a2bd4cd7994b36

See more details on using hashes here.

Provenance

The following attestation bundles were made for nqxpack-0.1.2-py3-none-any.whl:

Publisher: publish.yml on NeuralQXLab/nqxpack

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