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.6.1-cp314-cp314-win_amd64.whl (477.6 kB view details)

Uploaded CPython 3.14Windows x86-64

asim-26.6.1-cp314-cp314-win32.whl (413.5 kB view details)

Uploaded CPython 3.14Windows x86

asim-26.6.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

asim-26.6.1-cp314-cp314-macosx_11_0_arm64.whl (548.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

asim-26.6.1-cp313-cp313-win_amd64.whl (466.4 kB view details)

Uploaded CPython 3.13Windows x86-64

asim-26.6.1-cp313-cp313-win32.whl (403.5 kB view details)

Uploaded CPython 3.13Windows x86

asim-26.6.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

asim-26.6.1-cp313-cp313-macosx_11_0_arm64.whl (543.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

asim-26.6.1-cp312-cp312-win_amd64.whl (468.5 kB view details)

Uploaded CPython 3.12Windows x86-64

asim-26.6.1-cp312-cp312-win32.whl (405.8 kB view details)

Uploaded CPython 3.12Windows x86

asim-26.6.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

asim-26.6.1-cp312-cp312-macosx_11_0_arm64.whl (547.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file asim-26.6.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: asim-26.6.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 477.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asim-26.6.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 271b0b87cdf16b4e387586f5ed5ccf41fb9a78c689486324137c731284a12455
MD5 78b623fa796fb4d358427e4d4fea57c7
BLAKE2b-256 2e52a52e527c674d6c70ad2260d94f63da9310659d679f1fea656b84c2842672

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp314-cp314-win32.whl.

File metadata

  • Download URL: asim-26.6.1-cp314-cp314-win32.whl
  • Upload date:
  • Size: 413.5 kB
  • Tags: CPython 3.14, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asim-26.6.1-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 a2c5336531b7ff342823b55cc05c3115b9f5125e46b5915bc5e600f8a6eee7bc
MD5 edb40fe8b8e8a1c79f166b9aa8a941d1
BLAKE2b-256 a85bdf9ee47357647f46244793ba83937c50e4dfad017ef8d830c7a1ce94e08f

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asim-26.6.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 109e4747d32427526a2e5d804c8695cbcc435e0587c62fe60bac24c804da7f83
MD5 7e02a4f3df52ec128d999455bf4d3c36
BLAKE2b-256 869ca8d130fa0b10edc1a2a32ef3dc9ed6bf93a323857fd2f9a7a257a2b4359f

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asim-26.6.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9c630d7a2b4d4cb0ef288542959670cf120b3aa86f1537b845bd031c4b1c92d
MD5 09fd77c2623601d44a4ceec611933f48
BLAKE2b-256 43c10d7aab827d2b815ce69ce5e53eefe069dc58f2569024cc1796e2b47d02ed

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for asim-26.6.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 31203823bd15feadba22af4dc609d750a9d288ff9b485b02b4aed72944f1c7a2
MD5 6e253c12380be46a92bf8e1e82cce26e
BLAKE2b-256 3505d59049ec4ba550014ba3f80eae7e258c396b40b7f871ce2e3dc318dcf271

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp313-cp313-win32.whl.

File metadata

  • Download URL: asim-26.6.1-cp313-cp313-win32.whl
  • Upload date:
  • Size: 403.5 kB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asim-26.6.1-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 88e261474ce007ff54f7ccab36f2b88dc94dd92e24509ad83d0289dd0fdb2568
MD5 7fd5a1d461bce9570686bbd455aae4c1
BLAKE2b-256 c30f32024a7ede04d58dd27886753d54e0707d4323d1333649436229c47a6dff

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asim-26.6.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 64c325467ac2b1c83391afbde99d208040225586c341213d20230d43b32fde31
MD5 8df7b923cda2a333d3750156cdf31655
BLAKE2b-256 55e4a9899227417181e1dcab97c991d4a2327bd038690b4c4d804f2954d69ad0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.6.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23e719eff89b9261a9f7e59ede600fc48c6da6717c321344a1673a3a7f0a701f
MD5 a0e780568ee6d396364e32e274f539ea
BLAKE2b-256 5d55a07c1191db75a2912b7cf355460fc66b253f76ede873c406a11bb9e44b0d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for asim-26.6.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6586e65fc2be492a013e2c8e5e88a6ead0dbfc301f8037759ab949d068f3a81a
MD5 8c45b045920ce13bb044bc8998d02958
BLAKE2b-256 4b3690d2d2418d4d211c10e25229e98d54e232ca065e07a989423ecdf2c1e714

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp312-cp312-win32.whl.

File metadata

  • Download URL: asim-26.6.1-cp312-cp312-win32.whl
  • Upload date:
  • Size: 405.8 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asim-26.6.1-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 3614558e6c49b7f54194df734fd548c1121603cbac4ed0a11e8ab9c0af63cbe0
MD5 50f676152a1051ac28f5473a0cc49d8a
BLAKE2b-256 c6f760d12e90c9bdeaf1a1ff1a7766c8ad4f6745e02968f8561865aabbdaf32c

See more details on using hashes here.

File details

Details for the file asim-26.6.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for asim-26.6.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 417dbe54f8adc012f2a5cc0899184c599fd816c367d05fda3ea1bb6ff8ef5dca
MD5 982432351ea67c12903a73b62919856b
BLAKE2b-256 276f3bc871189d395271862a3180a4ad9b4e6f01fa470c4d4c9c0af1e469af1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asim-26.6.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 add48159ee8ea63e4118f52823ca867e10656c350580a85bb8bfbef8ec8ebd67
MD5 4ca7679bab1e44c864bccaf482158c92
BLAKE2b-256 beb94d8af257952583c2b1025a9cf1f4a72b96fcdc967dd0b788c635ebd0c869

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