semvec/pypi-packages huggingface dataset:
asim 26.2.3
Automatic simulation system powered by neural networks
Requires Python: >=3.12
Keywords: simulation

# Automatic simulation system powered by neural networks

## Installation

```bash
pip install asim
```

## What is asim

- Physical field modeling with automatic constraint enforcement
- Flexible data grouping and normalization
- Built-in support for recurrent architectures
- Export/import of trained models

## Using asim

```python
import matplotlib.pyplot as plt
import pandas as pd
from asim import Vt, Vu, Vx
from asim.dataset import PhysicalDataManage
from asim.tool import DummyDatasets
from asim.model import PhysicalFieldModel
from asim.optimizer import OffPolicyOptimizer
from asim.simulator import PhysicalSimulator

# 1. Define data and structure
df = DummyDatasets.boiler_minimum(size=2000)  # pd.read_csv("demo.csv")
cols = [
    Vt(label="ts"),
    Vx(group="boiler", label="heat_temp", minmax=(0.0, None), union="kj"),
    Vu(group="boiler", label="heat_power1", minmax=(0.0, None), union="kw"),
    Vu(group="boiler", label="heat_power2", minmax=(0.0, None), union="kw"),
]
dm = PhysicalDataManage(df, columns=cols, batch_size=64)

# 2A. Select the model, define the parameters, train and save
fm = PhysicalFieldModel(dm, lr=0.003)
fm.fit(epochs=50)
fm.export("demo.sim.onnx")

# 2B. 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())
opt.plots(opt_df)
plt.show()
```