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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file specnn4pde-0.2.8.tar.gz.
File metadata
- Download URL: specnn4pde-0.2.8.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ad1d0f1c0adf77383b52dfc03f99c4e95b236daa491d5c410bbf930b73e190
|
|
| MD5 |
cdb081e01380d435622e4dc17e3d753a
|
|
| BLAKE2b-256 |
c86af67253f6f82b4e5bc8427b27e9797d3e2a144cab006e64b2160e3cf54dbb
|
File details
Details for the file specnn4pde-0.2.8-py3-none-any.whl.
File metadata
- Download URL: specnn4pde-0.2.8-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11318cca1261b9586f3bd3544145f214795050eb29d486a9da6c173b9e827479
|
|
| MD5 |
729fd451c1357c23954106050a3acead
|
|
| BLAKE2b-256 |
4a35eb1a557432dbbe25262a5145489889b39527e95ccd9ae85e24f35da80892
|