Skip to main content

A Discrete-Event Simulator in Python

Project description

Simulus - A discrete-event simulator in Python

Simulus is an open-source process-oriented discrete-event simulator in Python. In the near future, simulus will also support parallel and distributed simulation, and real-time simulation.

Installation

Run the following to install:

pip install simulus

Usage

Simulus works in two ways. One way is through events. You can schedule events and process them. We call it direct event scheduling. The other way is through processes. You can create processes and have them run and interact. We call it process scheduling. Of course, there's a third way, by combining them and having them both.

The following a hello-world example, which simply schedules a function invocation in the simulated future:

import simulus

def print_message(sim, params):
    print("Hello world at time "+str(sim.now))

sim = simulus.simulator()
sim.sched(print_message, until=10)
sim.run()

The following is an example that uses processes. In this example, a homework process is created and scheduled to run at time 10. Then, five students, each represented also as a process, will spend time working on the homework. The homework process waits until all the student processes finish before it ends.

import simulus

from random import seed, expovariate, gauss
seed(12345)

def student(sim, params):
    student_id = params.get("student_id")
    print("student %d starts to work at %g" % 
          (student_id, sim.now))
    sim.sleep(gauss(30, 5)) # work on part one
    sim.sleep(expovariate(1/10.)) # take some rest
    sim.sleep(gauss(60, 10)) # work on part two
    print("student %d finishes working at %g" % 
          (student_id, sim.now))

def homework(sim, params):
    print("homework assigned at "+str(sim.now))
    # five students working on the homework each starts at a random 
    # time (exponentially distributed with mean of 10)
    students = []
    for i in range(5):
        s = sim.process(student, expovariate(1/10.), student_id=i)
        students.append(s)
    # wait for all student processes to complete
    sim.wait(students)
    print("last student finishes homework at "+str(sim.now))

sim = simulus.simulator()
sim.process(homework, 10) 
sim.run()

Simulus also provides advanced features to make common modeling tasks easier. For example, simulus provides resources and facilities, so that multiple processes can access multi-server queues, and perform producer-consumer synchronization over bounded buffers, among other capabilities. Simulus also supports conditional and timed waits on multiple resources and facilities.

Changelog

(unreleased)

New

  • Redesigned trappables; the processes, events, semaphores, traps, and resources now work with a more intuitive interface design. [Jason Liu]

  • Added initial implementation of resource and qstats. [Jason Liu]

1.0.4 (2019-07-04)

New

  • Finished trappables and timed waits implementation and accompanying documents (1.0.4). [Jason Liu]

  • Updated documents for using trappables and timed wait; and a bug fix. [Jason Liu]

  • Added support for conditional wait (wait on multiple trappables and timed wait). [Jason Liu]

1.0.1 (2019-07-04)

New

  • Pip ready; simulus has been published on pypi (1.0.1, 1.0.2, 1.0.3). [Jason Liu]

0.0.3 (2019-07-04)

New

  • Updated docs and added examples of using trappables; also some minor changes to interface (0.0.3). [Jason Liu]

  • Adding trapping mechanisms for inter-process communication. [Jason Liu]

0.0.2 (2019-07-04)

New

  • Added some examples using processes for user document. [Jason Liu]

  • Added useful functions for direct event scheduling (including resched, cancel, peek, step, and show_calendar). [Jason Liu]

  • Added phold example (to test processes). [Jason Liu]

Changes

  • Restructured examples directory (0.0.2). [Jason Liu]

  • Minor incremental updates. [Jason Liu]

  • Minor updates on a few interface functions including the sleep function. [Jason Liu]

Fix

  • Fixed process scheduling issue. [Jason Liu]

0.0.1 (2019-07-04)

New

  • First implementation of simulus, with support of events, processes, semaphores, and simulators; and also the jupyter notebook establishing the simple use cases. [Jason Liu]

  • This project got started in the evening on June 14, 2019 with a simple idea of creating an easy-to-use python simulator to replace our somewhat dilapitated Simian simulator and also outdoing the esoteric SimPy simulator. [Jason Liu]

Changes

  • Some minor updates (0.0.1). [Jason Liu]

  • Updated the jupyter notebooks. [Jason Liu]

  • Updated README.md (mindless update). [Jason Liu]

  • Updated README.md. [Jason Liu]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simulus, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size simulus-1.0.5-py3-none-any.whl (26.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size simulus-1.0.5.tar.gz (52.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page