Metadata-Version: 2.4
Name: specnn4pde
Version: 0.2.7
Summary: Solving partial differential equations using spectral methods and neural networks.
Author-email: MXWeng <2431141461@qq.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/mxweng/specnn4pde
Project-URL: Repository, https://github.com/mxweng/specnn4pde
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: GPUtil
Requires-Dist: IPython
Requires-Dist: matplotlib
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: Pillow
Requires-Dist: psutil
Requires-Dist: PyPDF2>=3.0.0
Requires-Dist: scipy
Requires-Dist: sympy
Provides-Extra: torch
Requires-Dist: torch; extra == "torch"
Provides-Extra: dev
Requires-Dist: build; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# 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:

```bash
python -m pip install specnn4pde
```

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

```bash
python -m pip install "specnn4pde[torch]"
```

For CUDA installations, install PyTorch with the command recommended by the [official PyTorch installation guide](https://pytorch.org/get-started/locally/), then install SpecNN4PDE.

## Quick start

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

```python
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:

```python
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

```powershell
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

```bash
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:

```bash
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:

```powershell
# Windows: for example, preview 0.2.6 -> 0.2.7
distribute.bat --release patch --dry-run
```

```bash
# macOS
./distribute.sh --release patch --dry-run
```

Run the release after reviewing the preview:

```powershell
# Windows
distribute.bat --release patch
```

```bash
# 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:

```powershell
# Windows
distribute.bat
```

```bash
# 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:

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

# Publish to PyPI
distribute.bat --upload
```

```bash
# 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.
