Local Simulation
This example models a shop packing orders. The simulation prints events and telemetry to the terminal. It needs no container, so it is the place to start. Each tab shows the example written one way: as a YAML blueprint, with the builder API, or with the low-level API. Ways to write a simulation compares the three.
In the output, look for each order's queued, started and finished events, and for the packers' readings every 2 simulation seconds. The capacity reading changes when the scenario adds packers at 10 seconds and removes one at 20 seconds.
Before You Start
The example needs only desflow, which each Quick Start below installs, and no other service. Services for the Examples lists the services the other examples need.
Steps
Run It
This example builds the same simulation as the builder example in the Builder tab, from a YAML blueprint and nothing else. No Python is written: the arrival loop, the task and the statistics are all declared in the file.
It writes to ConsoleEgress and needs no container, so it is the place to start.
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip:
What It Does
The run prints every record to the terminal and stops after 30 simulation seconds, which at factor: 1.0 is 30 real seconds. Add --until 10 to stop after 10 simulation seconds instead. Check the Result shows what it prints.
This version builds the simulation with the builder API (SimulationContext). It adds ConsoleEgress and no ingress. add_process starts capacity_changes, which waits on the simulation clock and changes the number of packers at 10 and 20 seconds, as the YAML scenario does.
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip:
This version wires the simulation by hand on DynamicRealtimeEnvironment, the low-level API.
Quick Start
desflow examples get downloads the example at the release you install, into a folder of its own. Pick uv or pip:
Check the Result
The three tabs print the same records, which a test checks by running each version unpaced. Telemetry lines carry [TEL] and events carry [EVT]. These are the events of the first order, and the packers' capacity reading before and after the first change:
Each order produces a queued, a started and a finished event. Every event carries the order's key, such as orders-1, with the task's name and instance. The finished event is the task's payload, with the task id added as order_id because of id_field. The capacity reading shows the scenario: one packer, three from 10 seconds, then two from 20 seconds.
Full Files
Full files
The blueprint declares one resource, one service and one arrival. spawn names the task each arrival starts. stats: minimal publishes the packers' four readings and the task's in_progress every 2 simulation seconds. The scenario changes the number of packers at 10 and 20 seconds.
Files live in the examples/yaml/ folder of the repository, and the label on each block below is its path there.
This script builds the model, runs it for 30 simulation seconds, and streams events and telemetry directly to your terminal.
Scripts live in the examples/ folder of the repository, and the label on the block below is this one's path there.
This script builds the model and runs it for 30 simulation seconds. The capacity_changes process changes the number of packers from 1 to 3 at 10 seconds, then down to 2 at 20 seconds. Events and telemetry stream directly to your terminal, driven by plain SimPy generators.
Scripts live in the examples/ folder of the repository, and the label on the block below is this one's path there.
| examples/low-level/local_example.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |