#simulation #discrete #event #stochastic #modeling

sim

Sim is a discrete event simulation package that facilitates Rust- and npm-based simulation products and projects

9 releases (breaking)

0.7.0 Apr 3, 2021
0.6.0 Mar 22, 2021
0.5.0 Mar 2, 2021
0.4.0 Feb 11, 2021
0.0.1 Apr 9, 2016

#2 in Simulation

Download history 1/week @ 2021-01-08 2/week @ 2021-01-15 72/week @ 2021-01-22 10/week @ 2021-01-29 20/week @ 2021-02-05 37/week @ 2021-02-12 18/week @ 2021-02-26 8/week @ 2021-03-05 34/week @ 2021-03-19 10/week @ 2021-03-26 25/week @ 2021-04-02 15/week @ 2021-04-09 35/week @ 2021-04-16 3/week @ 2021-04-23

58 downloads per month

MIT/Apache

150KB
3.5K SLoC

Sim

"Sim" or "SimRS" is a discrete event simulation package that facilitates
Rust- and npm-based simulation products and projects

Sim Website | Sim Demo | Sim Docs


stability-experimental GitHub Workflow Status Crates.io Crates.io npm npm docs.rs Codecov Crates.io

"Sim" or "SimRS" is a discrete event simulation package that facilitates Rust- and npm-based simulation products and projects.

This repository contains:

  1. Random variable framework, for easy specification of stochastic model behaviors.
  2. Pre-built atomic models, for quickly building out simulations of dynamic systems with common modular components.
  3. Output analysis framework, for analyzing simulation outputs statistically.
  4. Simulator engine, for managing and executing discrete event simulations.

Sim is compatible with a wide variety of compilation targets, including WebAssembly. Sim does not require nightly Rust.

Table of Contents

Background

Simulation is a powerful tool for analyzing and designing complex systems. However, most simulators have steep learning curves, are proprietary, and suffer from limited portability. Sim aspires to reduce the time required to build new simulation products, complete simulation projects, and learn simulation fundamentals. Sim is open source and, by virtue of compilation target flexibility, relatively portable.

Install

For use in Rust code bases, leverage the package as a cargo dependency

[dependencies]
sim = "0.7"

For use as a WebAssembly module in a JavaScript/TypeScript code base, leverage the package as a npm dependency

npm i sim-rs

Usage

Please refer to the documentation at https://docs.rs/sim

Also, the test simulations are a good reference for creating, running, and analyzing simulations with Sim.

Creating Simulations

Rust simulations are created by passing Models and Connectors to Simulation's post constructor.

WebAssembly simulations are defined in a declarative YAML or JSON format, and then ingested through WebSimulation's post_yaml or post_json constructors.

Both models and connectors are required to define the simulation. For descriptions of the pre-built models, see MODELS.md A simple three-model simulation could be defined as:

Nodes:

- type: "Generator"
  id: "generator-01"
  portsIn: {}
  portsOut:
    job: "job"
  messageInterdepartureTime:
    exp:
      lambda: 0.5
- type: "Processor"
  id: "processor-01"
  portsIn:
    job: "job"
  portsOut:
    processedJob: "processed"
  serviceTime:
    exp:
      lambda: 0.333333
  queueCapacity: 14
- type: "Storage"
  id: "storage-01"
  portsIn:
    store: "store"
    read: "read"
  portsOut:
    stored: "stored"

Connectors:

- id: "connector-01"
  sourceID: "generator-01"
  targetID: "processor-01"
  sourcePort: "job"
  targetPort: "job"
- id: "connector-02"
  sourceID: "processor-01"
  targetID: "storage-01"
  sourcePort: "processed"
  targetPort: "store"

Running Simulations

Simulations may be stepped with the step, step_n, and step_until methods. Input injection is possible with the inject_input method.

Analyzing Simulations

Analyzing simulations will typically involve some combination of listening to model metrics, collecting message transfers, and using output analysis tools. Analysis of IID samples and time series data are possible.

Contributing

Issues, feature requests, and pull requests are always welcome!

License

This project is licensed under either of Apache License, Version 2.0 or MIT License at your option.

Apache License, Version 2.0

MIT License

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in sim by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~11MB
~203K SLoC