Skip to main content

A PyTorch implementation of SPILSNet (Spatiotemporal Physics-derived Internal Latent Space Network)

Project description

SPILSNet-Torch

PyPI version Tests License: AGPL

A high-performance PyTorch implementation of SPILSNet (Spatiotemporal Physics-derived Internal Latent Space Network).

SPILSNet is designed for modeling complex dynamical systems where preserving physical structure (like spatial relationships and temporal consistency) is critical. It combines convolutional encoders for spatial feature extraction with a Gated Recurrent Unit (GRU) core to capture temporal evolution, while maintaining a learned skip-connection architecture to preserve high-frequency details.

Features

  • Unified Non-Pickle Serialization: Industry-standard safetensors format for weights and metadata (config, scalers), ensuring cross-platform safety and performance.
  • Physics-derived Temporal Dynamics: GRU-based core for robust state-space modeling.
  • Flexible Scaling: Built-in support for Scikit-learn scalers and custom transformers (e.g., CubeRoot).
  • Professional Engineering: Full type hinting, Google-style docstrings, and robust serialization.
  • Extensible Loss: Custom spils_loss including Laplacian smoothness terms for spatial consistency.

Installation

Install via pip:

pip install spilsnet-torch

For development:

git clone https://github.com/andinoboerst/spilsnet-torch.git
cd spilsnet-torch
pip install -e ".[dev]"

Quick Start

import numpy as np
import torch
from spilsnet import SPILSNet
from sklearn.preprocessing import StandardScaler

# 1. Configure the architecture
model_config = {
    "dimension": 2,                # 2D coordinates (x, y)
    "input_size": 102,             # 51 nodes * 2 dimensions
    "internal_state_size": 16,     # Size of physical internal states
    "encoder_structure": [
        {"out": 32, "k": 3, "s": 1, "p": 1},
        {"out": 16, "k": 3, "s": 1, "p": 1},
    ],
    "bottleneck_pool_size": 4,
    "latent_dim": 32,
    "gru_hidden_size": 64,
    "latent_encoder_mlp": [64, 64],
    "internal_input_mlp": [32],
    "internal_output_mlp": [32],
    "dropout_rate": 0.1,
}

# 2. Initialize the wrapper
model = SPILSNet(
    model_config=model_config,
    input_scaler_class=StandardScaler(),
    internal_in_scaler_class=StandardScaler(),
    internal_out_scaler_class=StandardScaler(),
    output_scaler_class=StandardScaler()
)

# 3. Fit the model
# X: [Sims, Steps, Input_Size], Y: [Sims, Steps, Output_Size], I: [Sims, Steps, Internal_Size]
X, Y, I = np.random.randn(10, 50, 102), np.random.randn(10, 50, 102), np.random.randn(10, 50, 16)
model.fit(X, Y, I)

# 4. Sequential Inference
model.initialize_memory_variables()
current_x = np.random.randn(102)
next_y = model.predict(current_x)

print(f"Predicted next state shape: {next_y.shape}")

Testing

Run the test suite using pytest:

pytest

To run with coverage:

pytest --cov=spilsnet

License

This project is licensed under the AGPL 3.0 License - see the LICENSE file for details.

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

spilsnet_torch-1.0.0.tar.gz (55.1 kB view details)

Uploaded Source

Built Distribution

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

spilsnet_torch-1.0.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file spilsnet_torch-1.0.0.tar.gz.

File metadata

  • Download URL: spilsnet_torch-1.0.0.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spilsnet_torch-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b3c44b77660a7fce048e712b6e657d19b0ffbf0f267acabb657ed594affb930d
MD5 5fc0358edc28766b77b9cdd7193da133
BLAKE2b-256 ed085539a1cc6628f08c6be7f9726255feec850f52533d1642d41bd47372cdc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spilsnet_torch-1.0.0.tar.gz:

Publisher: publish.yml on andinoboerst/spilsnet-torch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spilsnet_torch-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: spilsnet_torch-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spilsnet_torch-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 762e58b8f1ba97624df576433a715625508294a110b46ad80ffd4a28b455c315
MD5 8a54dc25e787450d16760e9f70b1191c
BLAKE2b-256 06f5f11636b1672a8de453e1769884098ee3e2f9e4867b1bf9cf4d0d8b1dc39a

See more details on using hashes here.

Provenance

The following attestation bundles were made for spilsnet_torch-1.0.0-py3-none-any.whl:

Publisher: publish.yml on andinoboerst/spilsnet-torch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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