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

Uploaded CPython 3.13Windows x86-64

asim-26.3.2-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.2-cp312-cp312-win_amd64.whl (412.9 kB view details)

Uploaded CPython 3.12Windows x86-64

asim-26.3.2-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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: asim-26.3.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2e3623471995f92e3142fb18b94b8feec9abe9b87455e9b5bb502ed22a218c1f
MD5 003aa132f1c23a12ce57cc9f837eb28b
BLAKE2b-256 a3f41a832ffe80d7c5bac7328d0561064948ebfb700e4aec5754fa5485a71b5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.3.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 ae65964da27f3d57da0264aaa7881cf39e966f9453811b17e82077c6bb3d6e1d
MD5 56ac4e685a0c49a5be412fc689e8220b
BLAKE2b-256 f1fd2df561b2cfedd90048b8ddf94ccccd3eb9bf04896eb394fb73d31d586461

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asim-26.3.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 acd6d441eee29f817ea7cdecfb62d23a061311844098b6426c11a2b01dd98894
MD5 72ace503092add5f273590d3cc537f59
BLAKE2b-256 97841ad11a61451ccb90fc37d6b6651edd7b45cce0b8871ef985642aaf4aea95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.3.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6cfcad8d094256a1f892cae5a6fa422bf6954c0e12346abc79f4b8e5fd0f166a
MD5 4781a89217598e875fa8d0522edc9a19
BLAKE2b-256 f7927c1d1b2fccb12ad9e3af4945eeca3d2176763c3fcebf8eca6f3dc020bd00

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