Skip to main content

Automatic simulation system powered by neural networks

Project description

asim — Neural Network Simulation & Optimal Control for Physical Systems

asim is a Python library for modeling, simulating, and optimizing physical systems using neural networks. It is designed for industrial process control — such as boilers, cooling systems, and heat exchangers — where data-driven state-space models replace first-principles equations.

Installation

pip install asim

What is asim

Train a neural network on historical sensor data, export it to ONNX, then run closed-loop simulation or gradient-based optimal control — all within a unified API.

  • Data-driven state-space modeling — learns system dynamics from tabular time-series data with explicit separation of controllable inputs (Vu), state variables (Vx), and time-varying parameters (Vc)
  • Automatic normalization — columns sharing a physical unit (union=) are scaled together; scalers are baked into the ONNX export
  • ONNX simulation — autoregressive rollout via onnxruntime; supports multi-group systems with cross-group wiring
  • Optimal controlOffPolicyOptimizer translates the ONNX graph into CasADi symbolic math and solves step-by-step MPC problems with IPOPT
  • Monotonicity checkingExplainer verifies gradient sign constraints to catch physically implausible model behavior

Using asim

import matplotlib.pyplot as plt
import pandas as pd
from asim import Vt, Vu, Vx
from asim.dataset import PhysicalDataManage
from asim.explainer import Explainer
from asim.model import PhysicalFieldModel
from asim.optimizer import OffPolicyOptimizer
from asim.simulator import PhysicalSimulator
from asim.tool import DummyDatasets

# 1. Define data and structure
df = DummyDatasets.boiler_minimum(size=10000)  # pd.read_csv("demo.csv")
cols = [
    Vt(label="ts"),
    Vu(group="boiler", label="heat_power1", minmax=(1.0, None), union="kw"),
    Vu(group="boiler", label="heat_power2", minmax=(None, 90), union="kw"),
    Vx(group="boiler", label="heat_temp", union="kj"),
]
dm = PhysicalDataManage(df, columns=cols, batch_size=64, seq_size=5)

# 2A. Select the model, define the parameters, train and save
fm = PhysicalFieldModel(dm, lr=0.002)
fm.fit(epochs=50)
fm.export("demo.sim.onnx")

# 2B. Check model
explainer = Explainer(dm, fm)
explainer.checkGrad()

# 2C. Use a simulator to simulate the operation
sim = PhysicalSimulator("demo.sim.onnx", dm=dm)
sim_df = df[0:1440].copy()
sim_df.index = pd.to_datetime(sim_df["ts"], unit="s", utc=True).dt.tz_convert("Etc/GMT-8")
sim_df = sim.steps(sim_df, x0={"heat_temp": sim_df["heat_temp"].iloc[0]})
sim.plots(sim_df)
plt.show()

# 3A. Build the optimizer
lTerm = lambda x, u, p: (x - p) ** 2 + 0.5 * (u[0] ** 2 + u[1] ** 2)
mTerm = lambda x, u, p: (x - p) ** 2
opt = OffPolicyOptimizer("demo.sim.onnx", dm=dm, lTerm=lTerm, mTerm=mTerm)
opt.fit(epochs=100)
opt.export("demo.opt.onnx")

# 3B. Use the optimizer
opt_df = opt.steps(df[0:360].copy(), interval=1)
opt.plots(opt_df)
plt.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

asim-26.3.3-cp313-cp313-win_amd64.whl (410.6 kB view details)

Uploaded CPython 3.13Windows x86-64

asim-26.3.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

asim-26.3.3-cp312-cp312-win_amd64.whl (412.9 kB view details)

Uploaded CPython 3.12Windows x86-64

asim-26.3.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

File details

Details for the file asim-26.3.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: asim-26.3.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 410.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asim-26.3.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7e310c737ec1eb3f5d91a88abdbec5ee6170e7e021dc4c9ffa756d5ed0e0161d
MD5 958e915945c9974cee9c8a214ffcbb6d
BLAKE2b-256 a00f5428f208e5faf34dfbad2fc9fd4eae6b3e7482faf2751ef86a8418dbe394

See more details on using hashes here.

File details

Details for the file asim-26.3.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for asim-26.3.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 1a3b352c5f58b0a57e05310c7534f1135f2668bfd29e41b147b65579f0631a5c
MD5 b3fbc2816f3a5a6bccb1f648ab282fb8
BLAKE2b-256 75674c90f1beeb5897df81ad3a71b796f15e2c3cb2a36f8d810ca41ad383c63e

See more details on using hashes here.

File details

Details for the file asim-26.3.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: asim-26.3.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 412.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asim-26.3.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 266fe8832aa49e8bdcb373dcfdc94b08b61306e38fedf0f178694b0ca1163aa8
MD5 0a0720dbc3ec44d5382a4971d9780be2
BLAKE2b-256 3f34051c04b041d56083f5d81d4102ef37d1458b50b38c7ea0ca78e34d727de1

See more details on using hashes here.

File details

Details for the file asim-26.3.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for asim-26.3.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5277026c34feb04b70b980c85f73357cdffb7924d46d88106eded185341dc75c
MD5 734a8a2b9f2f9ee1e2e5579f9ce93410
BLAKE2b-256 580fc00bd2c4d97e9743ee2db4c68ea5dd84925305e0b3cd1f255e789b8470b3

See more details on using hashes here.

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