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.4.1-cp313-cp313-win_amd64.whl (410.9 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

asim-26.4.1-cp313-cp313-macosx_11_0_arm64.whl (474.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

asim-26.4.1-cp312-cp312-win_amd64.whl (413.1 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

asim-26.4.1-cp312-cp312-macosx_11_0_arm64.whl (478.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: asim-26.4.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 410.9 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.4.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6a50057bb62cb06f683a5c48164104fb2468adb7a38a51c8d045875da068b689
MD5 10a868895cc43c1561c9540788efbad4
BLAKE2b-256 b16d16b223e9e3db056567f3221072e76e3a6b34cbf7703b60a0cfa2708e2e51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.4.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3dc0a7fa7516e6f4f78757998687bb4828e1a0428dde55799aff609140a6c9b1
MD5 4cb056474ee3f35c765891f1d297be83
BLAKE2b-256 a2de9d07462816063b664528860aa3dedfad5d80535e5eb7d866e1fbc6f2da2a

See more details on using hashes here.

File details

Details for the file asim-26.4.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asim-26.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12428ebc7ec941ec22ae19cfdd6784d35a9895a7c77fb1fa9001cbcffe743e63
MD5 00b9e02e54348ce6a42f9e8c9813f9fe
BLAKE2b-256 65da8cf3874af1ad5fe2699c5f1cb9140e11e16f7a11853fd40f0ce754c81d83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asim-26.4.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 413.1 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.4.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 32555005f59c3c9634af3009db34eccc6c1543e7bc765652c73dbbd1aae8898f
MD5 24238303a5216d9901a6171e3d0df80b
BLAKE2b-256 4021ead1e4dce81dcc2d5a2ea10f5dc7a203dad248b882afde066002be50b1ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cca8c47dd043ad44157272e38331e5633bc99ab2be1961d59adf4802a276f1f5
MD5 975be933604e092b2c6b3181342390cb
BLAKE2b-256 8b352cb017f6ddee3eb4773a46b3203e899e5257f5e4557041866355f4d5c97a

See more details on using hashes here.

File details

Details for the file asim-26.4.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asim-26.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3af4dffb2aefb99c0370d2525e75795f148865e24359a793723000c36baad372
MD5 70520375bf4e667bae4b4de47c026874
BLAKE2b-256 60f0c1b1d297384e124439a721e9fa714c5265f06790641f784cd2a2b3dbaacd

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