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.1.tar.gz (27.8 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.1-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nqxpack-0.1.1.tar.gz
  • Upload date:
  • Size: 27.8 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.1.tar.gz
Algorithm Hash digest
SHA256 f1dc55a4826acaa84bade0cf77ff1696a39cac0d1891de3aac162e421452c873
MD5 5ee9d8bae500912900ef56c50035fb1c
BLAKE2b-256 89cc14d48a96fc3d7ad91965ef0a0999f2a76110aa3486a2804f8db73cb49232

See more details on using hashes here.

Provenance

The following attestation bundles were made for nqxpack-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: nqxpack-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9bba3ad9a88bb53a3459e1f3d8d73948d1fb44bcafb49e285e7648e74d2f4bec
MD5 ba94afdc997a92b34549e26e41c9d9d2
BLAKE2b-256 0a444cd957c9efe69b803eaa993ff950d786f22840cb5dfdfc7f7d224797666f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nqxpack-0.1.1-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