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
loadcommand;
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. Note that you cannot serialise jax arrays for the time-being but it could easily be added (I'd need to think about how to handle sharding...)
import nqxpack
import jax
from flax import linen as nn
import numpy as np
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)))
variables_np = jax.tree.map(np.asarray, variables)
# for the moment cannot serialise jax arrays.
# Could easily be implemented
nqxpack.save({'model':model, 'variables':jax.tree.map(np.asarray, variables)}, "mymodel.nk")
loaded_dict = nqxpack.load("mymodel.nk")
loaded_model, loaded_variables = loaded_dict['model'], loaded_dict['variables']
With flax.nnx (WIP, not working yet)
import nqxpack
import jax
from flax import nnx
import numpy as np
rngs = nnx.Rngs(0)
model = nnx.Sequential(
nnx.Linear(1, 4, rngs=rngs), # data
nnx.Linear(4, 2, rngs=rngs), # data
)
graphdef, variables = nnx.split(model)
variables_np = jax.tree.map(np.asarray, variables.to_pure_dict())
# for the moment cannot serialise jax arrays.
# Could easily be implemented
nqxpack.save({'graphdef':graphdef, 'variables':variables_np}, "mymodel.nk")
loaded_dict = nqxpack.load("mymodel.nk")
loaded_graphdef, loaded_variables = loaded_dict['model'], loaded_dict['variables']
loaded_model = nnx.merge(loaded_graphdef, loaded_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.
Metadata
Release files for nqxpack 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nqxpack-0.1.16.tar.gz | 1.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nqxpack-0.1.16-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.7 MB
Release files / nqxpack-0.1.16.tar.gz
| Download URL | nqxpack-0.1.16.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2daa438299889f8c6ce7fdc74d144b559aa9ab2a3019fac1f49489bfd41d84de
|
|
BLAKE2b-256 checksum How to use checksums |
cf18d04b523e945169926ccff780e08fdc2c95f93176a9075b1c61948667581d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.
Transparency logRelease files / nqxpack-0.1.16-py3-none-any.whl
| Download URL | nqxpack-0.1.16-py3-none-any.whl |
|---|---|
| Size | 39.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4872ece8c84d78130eeb8b7c2baa2ff2823f2344d1185194bdc977132be9f5b8
|
|
BLAKE2b-256 checksum How to use checksums |
7e263cb3a0bebdefa8994b631c54e1af98093b0783ed73268d7549629142b9e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 18, 2026.
Transparency log