Boosting Simulation Performance with Python Eran Friedman How to - - PowerPoint PPT Presentation

boosting simulation performance with python
SMART_READER_LITE
LIVE PREVIEW

Boosting Simulation Performance with Python Eran Friedman How to - - PowerPoint PPT Presentation

Boosting Simulation Performance with Python Eran Friedman How to use Discrete-Event Simulation to run your system faster than real-time? Background About Me Eran Friedman Team lead @ Fabric Nowadays developing the Ground Robot


slide-1
SLIDE 1

Boosting Simulation Performance with Python

Eran Friedman

slide-2
SLIDE 2

How to use Discrete-Event Simulation to run your system faster than real-time?

slide-3
SLIDE 3

Background

slide-4
SLIDE 4

About Me

  • Eran Friedman
  • Team lead @ Fabric
  • Nowadays developing

the Ground Robot

slide-5
SLIDE 5

Outline

  • Simulations - why?
  • How to use DES?
  • How to use SimPy?
  • What are the challenges?
  • How to distribute?
slide-6
SLIDE 6

Simulation

“An approximate imitation of the

  • peration of a process or system ...”
  • Wikipedia
slide-7
SLIDE 7

Simulation

Orders Stock Motion

. . .

Backend

slide-8
SLIDE 8

Simulation

Orders Stock Motion

. . .

Backend

slide-9
SLIDE 9

Importance of Simulations

COVID-19

slide-10
SLIDE 10

Importance of Simulations

Automated regression tests

slide-11
SLIDE 11

Importance of Simulations

Analyze performance & compare algorithms

slide-12
SLIDE 12

Importance of Simulations

Run in the cloud

slide-13
SLIDE 13

Importance of Simulations

Verify warehouse layout

slide-14
SLIDE 14

Importance of Simulations

Inject failures & improve robustness

slide-15
SLIDE 15

Importance of Simulations

Simulate a large facility

slide-16
SLIDE 16

Discrete-Event Simulation (DES)

  • Operations are modeled as sequence of events
  • Simulation jumps to the next event
  • Simulation maintains its own clock
  • Example: 2 m/s, 10 time-ticks/second

t=0 x=0cm t=0.1 x=20cm t=0.2 x=40cm

slide-17
SLIDE 17

Discrete-Event Simulation (DES)

  • Operations are modeled as sequence of events
  • Simulation jumps to the next event
  • Simulation maintains its own clock
  • Example: 2 m/s, 10 time-ticks/second

t=0 x=0cm t=0.1 x=20cm t=0.2 x=40cm

slide-18
SLIDE 18

Discrete-Event Simulation (DES)

  • Operations are modeled as sequence of events
  • Simulation jumps to the next event
  • Simulation maintains its own clock
  • Example: 2 m/s, 10 time-ticks/second

t=0 x=0cm t=0.1 x=20cm t=0.2 x=40cm

slide-19
SLIDE 19

SimPy Library

  • Discrete-event simulation (DES) framework
  • Created in 2002
  • MIT license
  • Pure Python
  • No dependencies
slide-20
SLIDE 20

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue

slide-21
SLIDE 21

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r1 t=0 r0 t=0

slide-22
SLIDE 22

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r0 t=0 r1 t=0 Executing -

slide-23
SLIDE 23

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r0 t=0 r1 t=0 Executing - r0 t=0.1

slide-24
SLIDE 24

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r1 t=0 Executing - r0 t=0.1

slide-25
SLIDE 25

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r0 t=0.1 Executing - r1 t=0

slide-26
SLIDE 26

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r0 t=0.1 Executing - r1 t=0 r1 t=0.1

slide-27
SLIDE 27

SimPy Overview

Environment t = 0 Processes: r0 r1 Event queue r0 t=0.1 Executing - r1 t=0.1

slide-28
SLIDE 28

SimPy Overview

Environment t = 0.1 Processes: r0 r1 Event queue r1 t=0.1 Executing - r0 t=0.1

slide-29
SLIDE 29

SimPy Example - Robot Race

  • A robot’s speed is about 2-4 meters/second
slide-30
SLIDE 30
slide-31
SLIDE 31

SimPy Example - Robot Race

  • All SimPy processes run in a single thread
  • Parameters that affect performance:

○ Number of simulated components ○ Time tick granularity

  • Can run in ‘real-time’ mode
slide-32
SLIDE 32

Benefits of DES

  • Accelerates development time and faster CI
slide-33
SLIDE 33

Benefits of DES

  • Accelerates development time and faster CI
  • Realistic and deterministic simulation
slide-34
SLIDE 34

Benefits of DES

  • Accelerates development time and faster CI
  • Realistic and deterministic simulation
  • Simulate any date and time of the day
slide-35
SLIDE 35

Multi-Threaded System

Orders Stock Motion

. . .

Backend

slide-36
SLIDE 36

Time Leak - Event-Driven Component

  • Not naturally tied to time
  • SimPy supports event-driven processes
  • Not suitable for multi-threaded systems
slide-37
SLIDE 37

Time Leak - Event-Driven Component

  • Not naturally tied to time
  • SimPy supports event-driven processes
  • Not suitable for multi-threaded systems

Solution: Inherit from Queue and create a SimPy process that joins on itself in each time tick

slide-38
SLIDE 38
slide-39
SLIDE 39

Implementation

  • SimPy code runs in simulation only
  • Can’t use the usual time-related functions.

Wrapping time-related functionality in our

  • wn module

○ time.time() ○ time.sleep() ○ . . .

  • Debugging - simulation timestamp in log
slide-40
SLIDE 40

Distributed Simulation

slide-41
SLIDE 41

Distributed Simulation

slide-42
SLIDE 42

Distributed Simulation

create simpy process start local simpy do some work r e a d y

  • nce all clients

are ready approve progress local simpy loop

slide-43
SLIDE 43

Distributed Simulation

create simpy process start local simpy do some work r e a d y

  • nce all clients

are ready approve progress local simpy loop sim time freezes

slide-44
SLIDE 44
slide-45
SLIDE 45

Summary

  • Simulation is a powerful tool
  • DES makes it more powerful
  • is SimPle
  • Time leak - synchronize all components time
  • Easy to extend to a distributed simulation
slide-46
SLIDE 46

Thank You!