r/SimPy • • Jun 27 '25

Virtual Simulation Engineer v2

8 Upvotes

This one now uses SimPy under the hood.

Design, build and execute a discrete-event simulation in Python entirely using natural language in a single browser window.

Here's the link to try it out: https://gemini.google.com/share/ad9d3a205479

Let me know what you think!


r/SimPy • • May 03 '25

Tried using Entity-Component-System for a SimPy model and honestly… it’s pretty decent

3 Upvotes

You ever look at your simulation code and think, “This is getting way too complex”?

That was me a few months ago - OOP spaghetti everywhere, random methods buried in class hierarchies, and a creeping sense that I was the problem.

So I decided to try out ECS - that architecture pattern all the game devs use. Turns out, it actually works really well for SimPy simulations too.

Here’s the vibe:

  • Entities: just IDs. They’re like name tags for your stuff (machines, people, whatever).

  • Components: dumb little data containers. Stuff like Position, Status, Capacity. They describe what the entity is.

  • Systems: this is where the actual logic lives. They go, “which entities have X and Y?” and then make them do things. It’s clean and elegant.

You can add new behaviours without blowing up the whole codebase. No need to inherit from 14 classes or refactor everything. Just add a new component and a new system. Done.

It’s basically a form of “extreme composition” so it’s useful for when you need reconfigurability at scale.

Anyway, I’m curious - anyone else using ECS for simulations? Any gotchas to share?


r/SimPy • • Jul 21 '25

You can use Claude Code (and potentially Gemini CLI) to specify, run and analyse your existing simulations in Python entirely agentically

9 Upvotes

Here’s an on-the-fly example of how with Claude Code and a Python simulation in SimPy. In essence, you just need to:

  1. Separate the concerns in the code:

That is, at a minimum, have:

Input parameters --> simulation code --> output data

The more you can separate concerns the better. E.g. this is a step improvement:

Input parameters --> data validation --> simulation code --> output data

2. Then, just let the AI know how to work with your simulation. This is where Claude Code or Gemini CLI really shine - as you specify a CLAUDE.md or GEMINI.md file with all the context instructions.

I’ve also found this useful for debugging complex simulations when there are lots of input and output parameters.


r/SimPy • • Apr 28 '25

Adding item to the front of a Store queue

2 Upvotes

Is there any way to add an item to the front of store queue?

I know it’s possible to use priorities to change the order, but I was wondering if I can just put an item in a specific location in the queue.

Thanks


r/SimPy • • Aug 30 '25

Coroutines, Semi-Coroutines, and the Origins of SimPy

Thumbnail
youtube.com
3 Upvotes

Based on some discussion in

[Tool] Discover Ciw — A Powerful Python Library for Queueing Network Simulation 🚦🐍 : r/SimPy

I decided to read

gnosis.cx/publish/programming/charming_python_b5.txt.

Some audio issues kick in around 38 minutes in: What happened to my audio quality after 38 minutes? : r/NewTubers which I didn't notice while recording/posting. I don't expect I'll go back to re-record, but now I know I cannot trust that microphone.


r/SimPy • • Aug 07 '25

New manifesto from Klaus Müller (the creator of SimPy) and co-authored by me

Thumbnail reddit.com
3 Upvotes

r/SimPy • • Mar 07 '25

Simulations for Computer Systems?

4 Upvotes

I have a need to do some analysis on computer system which includes CPUs, caches, memories, other processing elements (streaming type), interconnections (AXI, Ethernet, DMA, etc.), etc. Would SimPy be suitable for such computer systems when there is no actual application software available yet and the need is to verify the system architecture feasibility in the defined cases? Or are there better solutions or approaches?

What about other frameworks like Salabim (https://www.salabim.org/) or PyDES (https://pydes.readthedocs.io/en/latest/), how to these compare to SimPy and what would be the easiest to start with?


r/SimPy • • Nov 26 '25

Two ways to request resources in SimPy - and why I prefer the "verbose" one

4 Upvotes

If you've worked with SimPy, you've probably seen the with statement pattern everywhere in the docs:

def customer(env, resource):
    with resource.request() as req:
        yield req
        # use the resource
        yield env.timeout(5)
    # resource automatically released here

Clean, right? The context manager handles the release for you. But there's another way that I've come to prefer – explicit requests and releases:

def customer(env, resource):
    req = resource.request()
    yield req
    # use the resource
    yield env.timeout(5)
    resource.release(req)

"But that's more code!" I hear you say. Yes. And that's partly the point.

Why I favour the explicit approach

1. It forces discipline

When you have to write resource.release(req) yourself, you're forced to think about when that release happens. You can't just let Python handle it when the block ends. This matters because in simulation modelling, the timing of resource releases is often critical to your model's behaviour. Making it explicit keeps you honest.

2. It gives you more flexibility

Sometimes you don't want to release at the end of a neat code block. Maybe you need to:

  • Release early based on a condition

  • Release in a different branch of logic

  • Hold onto a resource across multiple yield statements where the release point isn't obvious

With explicit releases, you put the resource.release(req) exactly where the logic demands it.

3. Multiple resources get messy fast

This is the big one. Say you need a machine AND an operator. With context managers:

def job(env, machine, operator):
    with machine.request() as machine_req:
        yield machine_req
        with operator.request() as operator_req:
            yield operator_req
            # now we have both
            yield env.timeout(10)
        # operator released
    # machine released

That nesting gets ugly. And what if you don't release them at the same time? What if the operator can leave after setup but the machine stays occupied? Now you're fighting the structure.

Compare with explicit:

Flat, readable, and the resource lifecycle is right there in the code.def job(env, machine, operator):
    machine_req = machine.request()
    yield machine_req
    
    operator_req = operator.request()
    yield operator_req
    
    # setup phase - need both
    yield env.timeout(2)
    
    # operator can leave, machine keeps running
    operator.release(operator_req)
    
    yield env.timeout(8)
    
    machine.release(machine_req)

The counterargument

The with statement exists to prevent you forgetting to release. Fair point. But if you're building simulations of any complexity, you should be testing them anyway – and a forgotten release shows up pretty quickly when your queues grow forever.

I'd rather have code where I can see exactly what's happening than code that hides important behaviour behind syntactic sugar.

Anyone else have a preference? Interested to hear if others have run into the nested with problem.


r/SimPy • • Nov 28 '25

Help with bachelor's thesis

2 Upvotes

Hi, guys. I am not a native English speaker so if you will be puzzled by some obscure wording in the post, please, ask away. So I have a theme for my Bachelor's Thesis which is essentially "Automatization of a system of video fixation of traffic violations using discrete event modelling". I didn't contact my thesis supervisor yet (there are some problems with thesis mentorship in general, because my uni is kinda shitty to be honest). So, my question is will SimPy be of any help? I assume it's Python documentation on Discrete Event modellig.


r/SimPy • • Dec 27 '24

Found a nice little free tutorial on SimPy in a Google Colab notebook

Thumbnail
colab.research.google.com
5 Upvotes

r/SimPy • • Jan 24 '25

What are you working on at the moment?

6 Upvotes

For me I’m currently building a little case study on simulating a new supply chain.

Aiming to balance total cost of ownership against system performance (e.g. % of deliveries made on time).


r/SimPy • • Oct 13 '24

What do you want to see in my new course on simulation in Python with SimPy?

3 Upvotes

Edit: the course is now live - you can find more information here: https://simulation.teachem.digital/school-of-simulation-enterprise

Hi folks, I am gathering some data to help design a new SimPy course I am building.

If you'd like to contribute I'd be really grateful for your feedback here - please select all that apply: https://www.teachem.digital/simulation-course/help-design-the-simulation-course


r/SimPy • • Nov 04 '24

A quick vlog: the real challenge in simulation isn’t the code - it’s winning people over

Thumbnail
linkedin.com
4 Upvotes

r/SimPy • • Mar 08 '25

How to integrate simpy with maps?

4 Upvotes

I have a project requiring me to integrate multilayered world maps (openstreetmap or google maps) with a python script. I would like to show entities (trucks, trains) are flowing through those maps and be displayed. However, as far as I understand SimPy is a resource based discrete event simulation library and not an entity based one.

So my question is, do I need to define some shadow entities within simpy’s environment to make this possible or are there any built in methods exist?


r/SimPy • • May 31 '25

Car Service Simulation - SimPy Tutorial (looking for feedback)

Thumbnail
teachyourselfsystems.com
4 Upvotes

I want t put together a somewhat dense simulation script together that can act as a good tutorial for a software developer that knows Python and recently discovered SimPy. This is the best I could come up with so far. Any ideas for improvements? Thanks!


r/SimPy • • May 15 '25

Trying to model a robotic system

2 Upvotes

I am struggling a bit when modeling my system. It is a robotic system with two containers receiving items on a regular time interval. When a user-defined number of items are present in either container, a request is made for a robot to 'pick' these items and place them in a third container. The 'robot' is a resource with capacity =1. The robot has a cycle time of 2 sec. 1 second is used to place the items in container 3, and the remaining second is for returning and thus becoming available again. When the robot places items in container 3, container 3 it is unavailable for 3 seconds. I am using timeout statements to simulate the cycle times. The issue I am struggling with is: I want the robot to timeout for half of it's cycle, then start the timeout for container three and simultaneously begin the timeout for the remaining half of the robot cycle. My current solution has to wait for the container 3 timeout to complete before I can begin the remaining timeout for the robot because I yield the timeouts sequentially. How can I do this?

Here is the problem area.

yield 
env.timeout(robot_cycle/2)
yield 
env.timeout(Container3)
yield 
env.timeout(robot_cycle / 2)

Would appreciate any insight into this.


r/SimPy • • Sep 11 '24

Decent introductory lecture on SimPy from PyData NYC 2022

Thumbnail
youtube.com
4 Upvotes

r/SimPy • • Apr 19 '26

Major update to dynamic-des: Custom variables and Kafka event routing for sophisticated simulations

Post image
4 Upvotes

Hello r/SimPy!

A while back I shared dynamic-des, a package I built for updating resource capacities on the fly. I wanted to share major updates today showing how much the scope of the package has expanded. I have added two major features to help build and stream sophisticated physical simulations:

1. Mutating Custom Variables on the Fly

In standard DES, modeling hidden machine degradation (like a roller slowly wearing out or suddenly breaking) is tricky if you want external systems to interact with it. To solve this for a Hot Strip Mill simulation I was building, I updated the package to allow custom variables inside the SimPy environment. Using the package's Kafka integration, a user can now use an external web dashboard to inject a control message directly into the running SimPy loop. This instantly mutates a wear_state variable and alters the physics engine's output on the fly for the very next slab of steel.

2. Custom Kafka Topic Router

I also added a custom event router. On top of the standard telemetry and lifecycle events, you can now route specific simulation records to entirely different Kafka topics. This is essential for building modern data pipelines; for example, it allows me to cleanly separate immediate model prediction events and delayed ground-truth physical events into their own dedicated streams right from the simulation.

Full Architecture

I wired all of this up into a complete Event-Driven Architecture where an external Apache Flink pipeline tries to predict the output of the SimPy model using Online Machine Learning.

If you want to see a reference architecture for how dynamic-des handles external state injections and custom event routing to generate realistic, streaming concept drift, check out the repo!


r/SimPy • • May 12 '25

I expect this will be of interest to some!

Thumbnail
reddit.com
6 Upvotes

r/SimPy • • Mar 22 '25

Trouble in Real Time Simulations

3 Upvotes

I am currently working on a real time simulation using simpy and I must say it is a great framework for DES. There is a line introduced there which states: Events scheduled for time t may take just up to t+1 for their computation, before an error is raised. This line is causing me trouble during simulations. What is the purpose of this line? Can one not simply surpass it by increasing the time factor


r/SimPy • • Apr 18 '25

I Wrote 9 Articles Comparing Various Leading Discrete-Event Simulation Softwares Against Python's SimPy

Thumbnail
reddit.com
2 Upvotes

r/SimPy • • Sep 05 '24

Some Helpful Resources

2 Upvotes

SimPy official documentation: https://simpy.readthedocs.io/en/latest/

Code on GitLab: https://gitlab.com/team-simpy/simpy

A free guide to SimPy (required email signup): http://www.teachem.digital


r/SimPy • • Feb 08 '25

Simulation for Financial Scenarios

5 Upvotes

Currently working on integrating a financial model with operations model to determine risk. Anyone out there who has worked with financial metrics and been successful? Thanks 😎


r/SimPy • • Sep 05 '24

Nice SimPy animation - mining use case

Thumbnail
youtube.com
5 Upvotes

r/SimPy • • Sep 05 '24

The Engineer’s Way

1 Upvotes

When a project is young and the questions are vast,
And the engineers gather to plan,
They measure and model, they simulate fast,
To make sense of the world if they can.
For the world’s full of numbers, both steady and sly,
And the future's a path none can see—
But give them a system, and charts reaching high,
They’ll show what the outcome shall be.

They’ll start with a question, a humble request:
“What drives this machine we must know?”
They’ll sketch out the pieces, then run with the rest,
In the dance where the data must flow.
With inputs and outputs, assumptions made plain,
They’ll build up a model so tight,
And test it again, through the sun and the rain,
Till it shines in the cold morning light.

But mind you the pitfalls, the variables wild,
For a model’s no better than clay—
If handled too loosely or trusted too mild,
It’ll crack when you send it to play.
So verify swiftly, and validate strong,
Let no idle error slip by,
And only when sure that the outputs belong,
Can you trust it to run or to fly.

Then pass it along to the folks at the head,
The managers keen to decide,
Show them the paths where their choices are led,
And let insight be their guide.
For decisions are forged in the heat of the race,
Where time and the budget press near,
But a model well-tuned will hold steady the pace,
And bring certainty out of the fear.

So here’s to the ones who shape futures untold,
With code and a clear, steady hand—
For the truth in their numbers is worth more than gold,
As they help us to build and to stand.