Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dynabench

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynabench

Benchmark dataset for learning dynamical systems from data

  • 0.3.1
  • PyPI
  • Socket score

Maintainers
1

DynaBench

PyPI version License: MIT All Tests Docs

The DynaBench package started as a benchmark dataset for learning dynamical systems from low-resolution data. It has since evolved into a full-fledged package for generating synthetic data, training models, and evaluating them on various tasks concerning partial differential equations. The package is designed to be easy to use and flexible, allowing for easy extension and modification of the existing models, data generation algorithms and physical equations.

Take a look at the documentation for more details on the package and how to use it.

⚡️ Getting Started

To get started with the package, you can install it via pip:

pip install dynabench

Downloading data

The DynaBench package contains dozens of different equations that can be used to generate synthetic data. The easiest way to get started, however, is to use one of the original benchmark equations. These can be downloaded using the following command:

from dynabench.dataset import download_equation

download_equation(equation='advection', structure='cloud', resolution='low')

The original benchmark dataset consists of simulations of the following equations:

EquationComponentsTime OrderSpatial Order
Advection111
Burgers'212
Gas Dynamics412
Kuramoto-Sivashinsky114
Reaction-Diffusion212
Wave122

Loading data

To easily load the data the dynabench package provides the DynabenchIterator iterator:


from dynabench.dataset import DynabenchIterator

advection_iterator = DynabenchIterator(equation='advection', 
                                        structure='cloud', 
                                        resolution='low',
                                        lookback=4,
                                        rollout=16)

This will iterate through all downloaded simulation of the advection dataset with observation points scattered (cloud) and low resolution. Each sample will be a tuple containing a snapshot of the simulation at the past 4 time steps, the future 16 time steps as target as well as the coordinates of the observation points:

for sample in advection_iterator:
    x, y, points = sample

    # x is the input data with shape (lookback, n_points, n_features)
    # y is the target data with shape (rollout, n_points, n_features)
    # points are the observation points with shape (n_points, dim)
    # for the advection equation n_features=1 and dim=2

⚙️ Usage

More advanced use cases include generating data for different equations, training models, and evaluating them. The package provides a simple interface for all these tasks.

Example: Generating data for Cahn-Hilliard equation

The DynaBench package provides a simple interface for generating synthetic data for various physical systems. For example data for the Cahn-Hilliard equation can be generated by running:

from dynabench.equation import CahnHilliardEquation
from dynabench.initial import RandomUniform
from dynabench.grid import Grid
from dynabench.solver import PyPDESolver



# Create an instance of the CahnHilliardEquation class with default parameters
pde_equation = CahnHilliardEquation()

# Create an instance of grid with default parameters
grid = Grid(grid_limits=((0, 64), (0, 64)), grid_size=(64, 64))

# generate an initial condition as a sum of 5 gaussians
intitial = RandomUniform()


# Solve the Cahn-Hilliard equation with the initial condition
solver = PyPDESolver(equation=pde_equation, grid=grid, initial_generator=intitial, parameters={'method': "RK23"})
solver.solve(t_span=[0, 100], dt_eval=1)

Example: Training NeuralPDE

The DynaBench package provides several models that can be used to forecast the physical system. For example, to train the NeuralPDE model on the advection equation, you can use the following code snippet:

from dynabench.dataset import DynabenchIterator
from torch.utils.data import DataLoader
from dynabench.model import NeuralPDE

import torch.optim as optim
import torch.nn as nn

advection_train_iterator = DynabenchIterator(split="train",
                                             equation='burgers',
                                             structure='grid',
                                             resolution='low',
                                             lookback=1,
                                             rollout=4)

train_loader = DataLoader(advection_train_iterator, batch_size=32, shuffle=True)

model = NeuralPDE(input_dim=2, hidden_channels=64, hidden_layers=3,
                  solver={'method': 'euler', 'options': {'step_size': 0.1}},
                  use_adjoint=False)

optimizer = optim.Adam(model.parameters(), lr=1e-3)
criterion = nn.MSELoss()

for epoch in range(10):
    model.train()
    for i, (x, y, p) in enumerate(train_loader):
        x, y = x[:,0].float(), y.float() # only use the first channel and convert to float32
        optimizer.zero_grad()
        y_pred = model(x, range(0, 5))
        y_pred = y_pred.transpose(0, 1)
        loss = criterion(y_pred, y)
        loss.backward()
        optimizer.step()
        print(f"Epoch: {epoch}, Batch: {i}, Loss: {loss.item()}")

📈 Benchmark Results

The original six equations have been used to evaluate the performance of various models on the task of forecasting the physical system. For this 900 spatial points have been used. The results are shown below:

  • 1-step MSE
modelAdvectionBurgersGas DynamicsKuramoto-SivashinskyReaction-DiffusionWave
CNN5.30848e-050.01109880.004203680.0006698370.000369180.00143387
FeaSt0.0001303510.01161550.01620.01178670.0004888480.00523298
GAT0.009601130.04399860.0374830.06670570.009152080.0151498
GCN0.0263970.138990.08426110.4365630.1646780.0382004
GraphPDE0.0001370980.01073910.01947550.007198220.0001421140.00207144
KernelNN6.31157e-050.01061460.0133540.006686980.0001870190.00542925
NeuralPDE8.24453e-070.01123730.003734160.0005369580.0003031760.00169871
Persistence0.08120810.03676880.1869850.1422430.1471240.113805
Point Transformer4.41633e-050.01030980.007248990.004897110.0001412480.00238447
PointGNN2.82496e-050.008825280.009016490.006730360.0001360590.00138772
ResNet2.15721e-060.01480520.003212350.0004901040.0001567520.00145884
  • 16-step rollout MSE:
modelAdvectionBurgersGas DynamicsKuramoto-SivashinskyReaction-DiffusionWave
CNN0.001613310.5545540.9953821.260110.01834830.561433
FeaSt1.482880.5611970.8195943.744480.1301491.61066
GAT41364.10.8333531.214365.689253.855062.38418
GCN3.51453e+1313.08767.206331.70612e+241.75955e+077.89253
GraphPDE1.079530.7298790.9692082.10440.08002351.02586
KernelNN0.8974310.727160.8540152.003340.06352781.57885
NeuralPDE0.0002703080.6597890.4434981.055640.02241550.247704
Persistence2.393930.6792611.4571.897520.2756782.61281
Point Transformer0.6170250.5038650.6428792.097460.05643991.27343
PointGNN0.6606651.043420.7592572.820630.05822931.30743
ResNet8.64621e-051.863520.4802841.06970.007046120.299457

📃 Citing

If you use DynaBench for your research, please cite:

@inproceedings{dulny2023dynabench,
    author = {Dulny, Andrzej and Hotho, Andreas and Krause, Anna},
    title = {DynaBench: A Benchmark Dataset for Learning Dynamical Systems from Low-Resolution Data},
    year = {2023},
    isbn = {978-3-031-43411-2},
    publisher = {Springer-Verlag},
    address = {Berlin, Heidelberg},
    doi = {10.1007/978-3-031-43412-9_26},
    booktitle = {Machine Learning and Knowledge Discovery in Databases: Research Track: European Conference, ECML PKDD 2023, Turin, Italy, September 18–22, 2023, Proceedings, Part I},
    pages = {438–455},
    numpages = {18},
    keywords = {neuralPDE, dynamical systems, benchmark, dataset},
    location = {Turin, Italy}
}

📚 More resources

  • The documentation for the package can be found here.
  • The original benchmark paper can be found here.

License

The content of this project itself, including the data and pretrained models, is licensed under the Creative Commons Attribution-ShareAlike 4.0 International Public License (CC BY-SA 4.0). The underlying source code used to generate the data and train the models is licensed under the MIT license.

References

[1]

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc