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.1.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.1-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spilsnet_torch-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7f6ae9d3af609b8ff0128e2c8a437c03f3b3c797e793f491230f9a8c41747249
MD5 22ec0d09724525495f221e0bc888c848
BLAKE2b-256 cc5eb41079bd7d62229a6a9e2229999d3962e92d858394cd34218ca8dc42cfa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for spilsnet_torch-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: spilsnet_torch-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a5f62c5be30f351bb1bb6d87ee4a90ae817dd9e642eb56809825debfa0fcf91
MD5 69ec56f2d8302964cc9d9669c9ec2b80
BLAKE2b-256 40b4a4540e64878762aa902818c9e682fead074a2847c56eda1b325373faf3aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for spilsnet_torch-1.0.1-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