fmi-tools / dtasm

Digital Twin Assembly - A portable and sandboxed package format for executable simulation modules based on WebAssembly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Digital Twin Assembly

Digital Twin Assembly (dtasm) is a binary interface (ABI) for executable numerical simulators compiled into WebAssembly modules. Such simulators implement methods for dynamically stepping forward in discrete time steps, where in each step, the simulator takes values for its declared input variables, performs the time step calculation, and emits values for its declared output variables at the end of the time step. dtasm is based on WebAssembly, WASI and FlatBuffers. See here for a specification of the ABI. An in-depth description of dtasm with a discussion of advantages and drawbacks has been presented at the Modelica 2021 conference.

Contents

This repository contains various implementations of dtasm runtimes and modules for demonstration purposes. It is not meant as a finished product or reference implementation of the dtasm interface, but rather as a starting point for compiling and running numerical simulators as WebAssembly modules.

The main components of this repository are:

  • dtasmtime - A Rust library implementing a runtime for dtasm modules based on Wasmtime. An example command-line program using this library for loading and executing dtasm modules can be found in runtime/examples/dtasmtime_rs.
  • dtasmtime-c-api - C API for dtasmtime, allowing the library to be called from C/C++, as well as other languages with C interop capabilities. An example command-line program in C that uses this library can be found in runtime/examples/dtasmtime_c.
  • dpend_cpp - Exemplary dtasm module implementing a double pendulum simulator (based on example code by M. Wheatland.
  • dpend_rs - Same double pendulum simulator written in Rust.
  • add_rs - Simple test module adding (or concatenating, anding) two inputs of each type.

Prerequisites

  • Linux or Windows OS on x86_64 or aarch64 platform
  • Rust, cargo and wasm32-wasi target for the active Rust toolchain (if using rustup, this can be installed by running rustup target add wasm32-wasi)
  • C/C++ compiler (e.g. gcc/g++)
  • GNU make
  • cmake
  • WASI SDK 12 installed into the default location at /opt/wasi-sdk

Build

Clone the repo including submodules (git clone --recurse-submodules ...). A top-level Makefile is provided for convenience to build the components. Running

make deps

will first build the FlatBuffers compiler flatc, then create all needed FlatBuffer stubs and buffers required by the components. Running

make

builds dtasmtime, the Rust command-line example and the Rust double pendulum module. You can execute the module by running make run-rs afterwards.

The same can be done for the C/C++ API and double pendulum simulator by running make cpp followed by make run-c.

License

This project is released under the MIT License.

About

Digital Twin Assembly - A portable and sandboxed package format for executable simulation modules based on WebAssembly

License:MIT License


Languages

Language:Rust 76.8%Language:C++ 8.3%Language:C 7.5%Language:Makefile 3.4%Language:Jupyter Notebook 2.5%Language:CMake 1.5%