solitonlab
A fast, correct engine for nonlinear field theory with guaranteed topological bookkeeping.
solitonlab simulates relativistic scalar field models (sine-Gordon, φ⁴, Klein-Gordon)
and tracks their topological invariants — 1D winding numbers and 2D vortex charges —
as integer quantities conserved to machine precision. It gets right the parts that ad-hoc
simulation code usually gets wrong:
- Winding-aware differential operators. A phase field on a ring is periodic only
modulo 2π. The naïve periodic Laplacian produces a spurious spike at the seam;
winding_laplacian_1dhandles it exactly, so a kink can wrap the ring and stay a soliton. - Topological charge conserved to ~1e-16. Winding/vortex charges are computed as wrapped lattice sums that are exact for smooth fields and robust to noise.
- Symplectic time stepping with a CFL guard. Leapfrog integration keeps energy bounded
over long runs (no artificial dispersion), and a supplied
dtabove the stability limit raises rather than silently blowing up. - Relativistic soliton diagnostics. Charge-weighted kink tracking, width/dispersion measurement, and a constant-proper-acceleration (Rindler) invariant for driven kinks.
Use cases
What it's good for today
- Teaching topological defects. Show students a kink wrap a ring, a winding number stay pinned to an integer, or a vortex/antivortex pair annihilate — with numerics that actually conserve the charge instead of drifting.
- Research prototyping. Explore sine-Gordon, φ⁴, and Klein-Gordon dynamics with the bookkeeping already correct, so you can focus on the physics rather than debugging your Laplacian at the periodic seam.
- A trusted reference/baseline. Validate your own PDE solver against a library whose charge conservation and energy behaviour are pinned by tests, to catch seam bugs and numerical dispersion in your code.
- Relativistic soliton kinematics. Drive a kink with a bias field and measure its Rindler (constant-proper-acceleration) motion and Lorentz contraction directly.
- 2D vortex counting. Detect and sign topological defects in any phase / order-parameter
field with
vortex_charge_2dandfind_vortices_2d.
Where it can go (natural extensions, not yet built in)
- Josephson junctions & fluxon dynamics — the long junction is driven sine-Gordon.
- Superfluid / superconductor vortices — 2D order-parameter defect tracking.
- Kibble–Zurek quench studies — defect formation rates under a controlled ramp.
- Domain walls in magnetism / ferroelectrics — φ⁴ kink dynamics under forcing.
- Labeled ML datasets — generate fields with known topological charge for training and benchmarking defect-detection models.
If you build one of these on top of solitonlab, a PR adding it as an example is very welcome.
Install
pip install -e . # from source
pip install -e ".[dev]" # with pytest + matplotlib
Quick start
import numpy as np
from solitonlab import Lattice1D, SineGordon, Simulator, winding_number_1d
lat = Lattice1D(n=1024, length=2*np.pi*8, bc="winding") # a ring
model = SineGordon(lat, m=1.0)
phi0 = model.kink(center=lat.length/2, velocity=0.6) # a moving winding kink
phit0 = model.kink_velocity_field(phi0, 0.6)
res = Simulator(model, phi0, phit0).run(steps=6000, record_every=60)
print(winding_number_1d(phi0), "->", winding_number_1d(res.field)) # 1 -> 1 (protected)
Command line
solitonlab kink --velocity 0.6 --steps 4000 # soliton on a ring; reports invariants
solitonlab vortices # detect a +1/-1 vortex pair in 2D
What's inside
| Module | Purpose |
|---|---|
lattice |
Lattice1D / Lattice2D with explicit boundary conditions |
operators |
Laplacians/gradients incl. the winding-aware ring Laplacian |
models |
SineGordon, Phi4, KleinGordon (+ exact soliton constructors) |
integrators |
Simulator — leapfrog with CFL safety and energy tracking |
topology |
winding_number_1d, vortex_charge_2d, find_vortices_2d |
diagnostics |
kink_center, kink_width, proper_acceleration, energy |
Tests
pytest
The suite verifies the properties that make the library trustworthy: charge conservation, non-dispersing solitons, bounded energy, correct seam handling, and relativistic kink motion.
Contributing
Contributions are welcome. Every change ships with a test that pins the invariant it preserves — see CONTRIBUTING.md. By participating you agree to the Code of Conduct.
Roadmap
Planned directions for future releases (feedback and PRs welcome):
- Spectral (FFT-based) operators as a high-accuracy alternative to finite differences.
- A
GinzburgLandau/ complex-field model for superfluid- and superconductor-style vortices. - 2D vortex dynamics (motion, pair annihilation) and a worked example.
- Time-dependent forcing and Kibble–Zurek quench helpers.
- Optional
numba/vectorised fast paths for large lattices.
Citing
If solitonlab is useful in your work, please cite it — see CITATION.cff
or use "Cite this repository" on GitHub.
License
MIT © Koby Fowler — see LICENSE.
Metadata
Release files for solitonlab 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| solitonlab-0.1.0.tar.gz | 18.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| solitonlab-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.7 kB
Release files / solitonlab-0.1.0.tar.gz
| Download URL | solitonlab-0.1.0.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f30301a83d2f463c469acccb34cecb7d0724202af3650dc506abcc41959eefe6
|
|
BLAKE2b-256 checksum How to use checksums |
1c4450a8bf5369fafa178fc598b74dd8eeb434a75f4baafba7b072abdbd1471c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / solitonlab-0.1.0-py3-none-any.whl
| Download URL | solitonlab-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
29807ce81062c7bbc7a150e479de506d6f46b5b18eb6de0ae8f74c20dac599cb
|
|
BLAKE2b-256 checksum How to use checksums |
47ccdb883b49ee7c93dcfb38939bbd0e02e1fe836d16551509feb1cbe07ec67e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|