Skip to main content

Solving partial differential equations using spectral methods and neural networks.

Project description

SpecNN4PDE

SpecNN4PDE is a personal research library for solving partial differential equations with spectral methods and neural networks. The project is under active development, and its API may change between releases.

Modules

  • spectral: Jacobi and Hermite polynomials, quadrature rules, differentiation matrices, mapped methods, and related spectral utilities.
  • linalg: Numerical linear algebra and Runge--Kutta utilities.
  • myplot: Matplotlib configuration, colormaps, colorbars, and plotting helpers.
  • utils: Package and system information, file conversion, timing, and file helpers.
  • nn: Random Feature Method neural networks and reproducibility helpers.
  • optim: Scalar Auxiliary Variable based optimizers and variants.
  • npde: Automatic differentiation, collocation points, and regular or complex computational domains.
  • torch_special: PyTorch implementations of selected special functions.
  • torch_linalg: PyTorch linear algebra utilities.

Installation

Install the core NumPy/SciPy functionality from PyPI:

python -m pip install specnn4pde

The nn, optim, npde, torch_special, and torch_linalg modules require PyTorch. For a standard installation, use:

python -m pip install "specnn4pde[torch]"

For CUDA installations, install PyTorch with the command recommended by the official PyTorch installation guide, then install SpecNN4PDE.

Quick start

Generate a Legendre--Gauss quadrature rule and verify that its weights integrate the constant function:

from specnn4pde.spectral import Jacobi_Gauss

D, x, w = Jacobi_Gauss(alpha=0, beta=0, N=8)
print(w.sum())  # approximately 2

Configure a Matplotlib axis:

import matplotlib.pyplot as plt

from specnn4pde.myplot import ax_config

fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1], label="example")
ax_config(ax, xlabel="$x$", ylabel="$u(x)$")
plt.show()

Development

Use a separate clone and virtual environment on each operating system. Synchronize source code through Git rather than sharing .venv, __pycache__, or the same live Git working tree through a cloud drive.

Windows

py -m venv .venv
.\.venv\Scripts\python -m pip install -U pip
.\.venv\Scripts\python -m pip install -e ".[dev]"
.\.venv\Scripts\python -m pytest

macOS

python3 -m venv .venv
.venv/bin/python -m pip install -U pip
.venv/bin/python -m pip install -e ".[dev]"
.venv/bin/python -m pytest

Add the torch extra when working on the PyTorch modules:

python -m pip install -e ".[dev,torch]"

Building and publishing

The package version has a single source of truth in specnn4pde/_version.py. The release tool can update it, run tests and package checks, summarize all Git changes, create a commit and annotated tag, push them, and upload the distributions. It always pauses before changing the version and requires a second, version-specific confirmation before any Git or remote operation.

Preview a patch release without modifying files, pushing, or uploading:

# Windows: for example, preview 0.2.6 -> 0.2.7
distribute.bat --release patch --dry-run
# macOS
./distribute.sh --release patch --dry-run

Run the release after reviewing the preview:

# Windows
distribute.bat --release patch
# macOS
./distribute.sh --release patch

Use minor for 0.2.6 -> 0.3.0 or major for 0.2.6 -> 1.0.0. Before releasing, synchronize the branch yourself with git pull --ff-only; the release tool deliberately does not pull or merge. The release commit includes every current change (git add -A), so read the displayed git status carefully. If local checks fail or you cancel before the Git step, the tool restores the original version file and leaves your other edits untouched. If pushing or uploading fails after the release commit begins, it leaves the Git state intact so the failed operation can be diagnosed or retried safely.

You can still build and validate distributions without changing the version, performing Git operations, or uploading:

# Windows
distribute.bat
# macOS
./distribute.sh

The platform launchers both call tools/release.py. --upload remains available for uploading the current version without creating a commit or tag, which is useful for retrying a failed upload:

# Windows: publish to TestPyPI first
distribute.bat --upload --repository testpypi

# Publish to PyPI
distribute.bat --upload
# macOS: publish to TestPyPI first
./distribute.sh --upload --repository testpypi

# Publish to PyPI
./distribute.sh --upload

For ordinary, non-release code updates, continue to use the normal git add, git commit, and git push workflow; a version bump is only needed when publishing a new package release.

License

SpecNN4PDE is distributed under the MIT License.

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

specnn4pde-0.2.7.tar.gz (95.4 kB view details)

Uploaded Source

Built Distribution

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

specnn4pde-0.2.7-py3-none-any.whl (93.6 kB view details)

Uploaded Python 3

File details

Details for the file specnn4pde-0.2.7.tar.gz.

File metadata

  • Download URL: specnn4pde-0.2.7.tar.gz
  • Upload date:
  • Size: 95.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for specnn4pde-0.2.7.tar.gz
Algorithm Hash digest
SHA256 72e429a60f570fb89c9002a8183821b32cc16792869051fd12099ea0883fa251
MD5 3fb3b153e5493f203b576bd19f1b1870
BLAKE2b-256 130162cf967fe99b03cfbe5e181dc97d435ba2348fe4d5a7491de856b5cceb70

See more details on using hashes here.

File details

Details for the file specnn4pde-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: specnn4pde-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 93.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for specnn4pde-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 48d8e409b786ee53bb88dfdc6bc22ced2442f4149155f5f55fa54ca44541a0f2
MD5 3d75682d8d5a5be8a1084972381d963c
BLAKE2b-256 0dd3003de34f506d71e18bc25c7645ec7ae734daee0161e91aecf88f7cb256c5

See more details on using hashes here.

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