Skip to main content

spinn - Simple Physics Informed Neural Networks

Makes PINNs easy (with jax), see examples...

Usage

Subclass spinn and define terms: the loss terms of the problem, with the equation (PDE residual) first and the conditions after it. propx returns the network outputs and their derivatives at given points: [x, k, i, j, ...] is output k at the points x, differentiated with respect to inputs i, j, ...

import jax
import jax.numpy as jnp
from spinn import spinn, hcube, left, right, bottom, mlgraph


class heat(spinn):
    """dF/dt = a d2F/dx2, F = 0 at x = 0 and x = 1, F = sin(pi x) at t = 0"""

    @jax.jit
    def terms(self, w, x, a, f0, bx):
        self.w = jnp.asarray(w)
        left, right, bottom = bx
        dFt, dFxx = self.propx([[x, 0, 1], [x, 0, 0, 0]])
        Fl, Fr, Fb = self.propx([[left, 0], [right, 0], [bottom, 0]])
        return (self.mse(dFt - a*dFxx),             # equation
                self.mse(Fl) + self.mse(Fr),        # boundary conditions
                self.mse(Fb, f0))                   # initial condition


x = hcube((1., 0.5), n=21)                  # grid of points (x, t)
bx = left(x), right(x), bottom(x)
f0 = jnp.sin(jnp.pi*bx[2][:, 0])

P = heat(mlgraph((2, 16, 16, 1)), initx=x)  # 2 inputs, 2 hidden layers
res = P.train(x, 0.2, f0, bx)
F = P(x)                                    # solution at the points

train minimizes the weighted sum of the terms with scipy's L-BFGS-B. The weights are balanced automatically (balance='curv' by default, see spinn.balance for the other rules, e.g. balance='curvsens'), or given explicitly as balance=[1., 10., 10.]. The final weights are returned in res.lmbd and the unweighted terms in res.terms.

Activations of the hidden layers are set with f: a name from jax.nn or jax.numpy (f='tanh', f='sin', f='gelu'; softplus by default), a function, or one per layer. Networks are saved with P.dump(fname) and restored with heat.load(fname); see help(spinn) for details.

More problems (beams, Laplace and heat equations) are in examples/.

Metadata

Release files for spinn 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spinn 0.3.0
File Size Uploaded Provenance Actions
spinn-0.3.0.tar.gz 18.4 kB With provenance Details for spinn-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spinn 0.3.0
File Interpreter ABI Platform Actions
spinn-0.3.0-py3-none-any.whl Python 3 none any Details for spinn-0.3.0-py3-none-any.whl

Total release size: 36.7 kB

Release files / spinn-0.3.0.tar.gz

Download URL spinn-0.3.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4d6e01cf6199e00bd014a261eb40a6ae707bae756becb2fd29e6180d7a5d6ded
BLAKE2b-256 checksum
How to use checksums
d0a8f2a25215de56ba300c607b06844f10431f65b57e5dcdc20105b62d845663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Release files / spinn-0.3.0-py3-none-any.whl

Download URL spinn-0.3.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6050a7b8e548ff3fe012a72fce6fb91ef94a264727b91285714f579be1c827a9
BLAKE2b-256 checksum
How to use checksums
d364275a20d4087161e8f9ac4a60e8d7765067ca9ed6db687a394aa1d7e8df22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for spinn 0.3.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spinn-0.3.0.tar.gz

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 Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page