boosting simulation performance with python
play

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


  1. Boosting Simulation Performance with Python Eran Friedman

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

  3. Background

  4. About Me ● Eran Friedman ● Team lead @ Fabric ● Nowadays developing the Ground Robot

  5. Outline ● Simulations - why? ● How to use DES? ● How to use SimPy? ● What are the challenges? ● How to distribute?

  6. Simulation “An approximate imitation of the operation of a process or system ...” - Wikipedia

  7. Simulation Backend . . . Orders Stock Motion

  8. Simulation Backend . . . Orders Stock Motion

  9. Importance of Simulations COVID-19

  10. Importance of Simulations Automated regression tests

  11. Importance of Simulations Analyze performance & compare algorithms

  12. Importance of Simulations Run in the cloud

  13. Importance of Simulations Verify warehouse layout

  14. Importance of Simulations Inject failures & improve robustness

  15. Importance of Simulations Simulate a large facility

  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 t=0.1 t=0.2 x=0cm x=20cm x=40cm

  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 t=0.1 t=0.2 x=0cm x=20cm x=40cm

  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 t=0.1 t=0.2 x=0cm x=20cm x=40cm

  19. SimPy Library ● Discrete-event simulation (DES) framework ● Created in 2002 ● MIT license ● Pure Python ● No dependencies

  20. SimPy Overview Environment t = 0 Processes: r0 r1 Event queue

  21. SimPy Overview Environment t = 0 r1 t=0 r0 Processes: t=0 r0 r1 Event queue

  22. SimPy Overview Environment t = 0 Executing - r0 r1 Processes: t=0 t=0 r0 r1 Event queue

  23. SimPy Overview Environment t = 0 r0 Executing - t=0.1 r0 r1 Processes: t=0 t=0 r0 r1 Event queue

  24. SimPy Overview Environment t = 0 r0 Executing - t=0.1 r1 Processes: t=0 r0 r1 Event queue

  25. SimPy Overview Environment t = 0 Executing - r1 r0 Processes: t=0 t=0.1 r0 r1 Event queue

  26. SimPy Overview Environment t = 0 r1 Executing - t=0.1 r1 r0 Processes: t=0 t=0.1 r0 r1 Event queue

  27. SimPy Overview Environment t = 0 r1 Executing - t=0.1 r0 Processes: t=0.1 r0 r1 Event queue

  28. SimPy Overview Environment t = 0.1 Executing - r0 r1 Processes: t=0.1 t=0.1 r0 r1 Event queue

  29. SimPy Example - Robot Race ● A robot’s speed is about 2-4 meters/second

  30. 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

  31. Benefits of DES ● Accelerates development time and faster CI

  32. Benefits of DES ● Accelerates development time and faster CI ● Realistic and deterministic simulation

  33. Benefits of DES ● Accelerates development time and faster CI ● Realistic and deterministic simulation ● Simulate any date and time of the day

  34. Multi-Threaded System Backend . . . Orders Stock Motion

  35. Time Leak - Event-Driven Component ● Not naturally tied to time ● SimPy supports event-driven processes ● Not suitable for multi-threaded systems

  36. 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

  37. Implementation ● SimPy code runs in simulation only ● Can’t use the usual time-related functions. Wrapping time-related functionality in our own module ○ time.time() ○ time.sleep() ○ . . . ● Debugging - simulation timestamp in log

  38. Distributed Simulation

  39. Distributed Simulation

  40. Distributed Simulation create simpy process start local simpy loop do some work r e a d y once all clients approve are ready progress local simpy

  41. Distributed Simulation create simpy process start local simpy loop do some work r e a d y sim time freezes once all clients approve are ready progress local simpy

  42. 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

  43. Thank You!

Recommend


More recommend