Skip to main content

Symbolic operator DSL for NetKet discrete JAX operators

Project description

PyPI License Documentation Status codecov

nkDSL

nkDSL is a standalone symbolic operator DSL which provides a compact, declarative way to define discrete operators in NetKet and compile them into executable JAX-backed operator kernels.

[!NOTE] nkDSL is currently in beta. The core DSL and compiler workflow are ready for broader testing, while some advanced APIs may still evolve before a fully stable release.

What it does

With nkDSL, you describe an operator in terms of

  • where to iterate, such as sites, pairs, or user-defined index sets,
  • when a branch is active, through symbolic predicates,
  • how to rewrite a configuration, through update programs,
  • what matrix element to assign to each emitted branch.

The result is a symbolic operator that can be compiled into a NetKet-compatible executable operator.

Example: 1D transverse-field Ising model

The example below builds $H = -J \sum_{\langle i,j \rangle} \sigma_i^z \sigma_j^z - h \sum_i \sigma_i^x$ for a periodic chain. The diagonal Ising interaction is emitted with an identity update, while the transverse-field term flips one spin at a time.

import netket as nk
from nkdsl import SymbolicDiscreteJaxOperator, site, write

L = 8

hilbert = nk.hilbert.Spin(s=0.5, N=L)
graph = nk.graph.Chain(length=L, pbc=True)

ising = (
    SymbolicDiscreteJaxOperator(hilbert, "ising_tfim", hermitian=True)
    .for_each(("i", "j"), over=graph.edges())
    .emit(
        matrix_element=-1.0 * site("i").value * site("j").value,
    )
    .for_each_site("i")
    .emit(
        write("i", -site("i").value),
        matrix_element=-0.5,
    )
    .compile()
)

# now, `ising` is a NetKet DiscreteJaxOperator subclass, and can be used in NetKet

Installation

Install directly from PyPI:

python -m pip install --upgrade pip
python -m pip install nkdsl

Status

nkdsl is currently a small, focused package for the recent DSL operator work developed in neuraLQX. Right now the goal is clarity and usability rather than a broad, frozen API surface.

License

This project is licensed under Apache License 2.0. See LICENSE for the full text.

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

nkdsl-0.1.2.tar.gz (134.6 kB view details)

Uploaded Source

Built Distribution

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

nkdsl-0.1.2-py3-none-any.whl (180.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nkdsl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 991413d76c4a3d543c31babf84065e54a508eabdadca906c5c54dfbc856d30b1
MD5 bbdbd3e6aae1e84ffc66bd3d08085efd
BLAKE2b-256 00ef0d451eeea095f48ed51acd8553827ec394c08c33319fccf4476d6d014970

See more details on using hashes here.

Provenance

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

Publisher: publish.yaml on waleed-sh/nkDSL

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

File details

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

File metadata

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

File hashes

Hashes for nkdsl-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 323732456820459f8e274d9d40fac8eb3d27a71aa29473ba640fee20965ddecd
MD5 cfc5cbbe4d76d9e79fb06ad1bcc162a5
BLAKE2b-256 b77815fb986e3c2c00996ab3b974369bc41c356eade33dccc59fdf1bfab652a6

See more details on using hashes here.

Provenance

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

Publisher: publish.yaml on waleed-sh/nkDSL

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