Skill Tracer
Skills › Scientific Agent Skills › simpy › simulation-methodology.md

simulation-methodology.md

296 lines · skills/simpy/references/simulation-methodology.md at 5f2bc03

Open on GitHub
1# Simulation-study methodology (not SimPy API)
2
3Verified 2026-07-23. This guide applies established discrete-event simulation
4methods to SimPy models. SimPy schedules events; it does not perform these study
5design decisions automatically.
6

Simulation-study methodology (not SimPy API)

Verified 2026-07-23. This guide applies established discrete-event simulation methods to SimPy models. SimPy schedules events; it does not perform these study design decisions automatically.

Raw lines 1 to 6
7## 1. Start with the conceptual model
8
9Before code, specify:
11- purpose, decision context, stakeholders, and intended domain;
12- system boundary, entities, resources, queues, routes, state, and termination;
13- input data provenance and fitted/assumed distributions;
14- initial conditions and time units;
15- performance measures/estimands;
16- assumptions, simplifications, exclusions, and known limits;
17- required accuracy and validation evidence.
19Robinson defines conceptual modeling as abstraction from a real or proposed system
20and emphasizes validity, credibility, utility, feasibility, and the simplest model
21adequate for purpose. Sargent frames validity relative to the intended application
22and domain, not as a universal property.
24Use a unit table:
26| Quantity | Unit | Convention |
27|---|---|---|
28| `env.now` | minutes | starts at opening |
29| interarrival | minutes/entity | strictly positive |
30| service | minutes | sampled at service start |
31| throughput | entities/hour | convert from minute horizon |
33SimPy time is unitless. Unit inconsistency can produce a perfectly executable but
34invalid model.

1. Start with the conceptual model

Before code, specify:

  • purpose, decision context, stakeholders, and intended domain;
  • system boundary, entities, resources, queues, routes, state, and termination;
  • input data provenance and fitted/assumed distributions;
  • initial conditions and time units;
  • performance measures/estimands;
  • assumptions, simplifications, exclusions, and known limits;
  • required accuracy and validation evidence.

Robinson defines conceptual modeling as abstraction from a real or proposed system and emphasizes validity, credibility, utility, feasibility, and the simplest model adequate for purpose. Sargent frames validity relative to the intended application and domain, not as a universal property.

Use a unit table:

QuantityUnitConvention
env.nowminutesstarts at opening
interarrivalminutes/entitystrictly positive
serviceminutessampled at service start
throughputentities/hourconvert from minute horizon

SimPy time is unitless. Unit inconsistency can produce a perfectly executable but invalid model.

Raw lines 7 to 35
36## 2. Terminating versus steady-state studies

2. Terminating versus steady-state studies

Raw lines 36 to 37
38### Terminating
40A terminating simulation has a natural, predeclared endpoint: closing time,
41completion of an order, end of a mission, or another event relevant to the purpose.
42Initial conditions are part of the estimand and should normally be identical across
43replications.
45Decide how to handle entities still present at a fixed clock horizon:
47- stop and report/censor unfinished paths;
48- stop arrivals at closing but drain the system;
49- terminate on an explicit completion event.
51These answer different questions. Numeric `env.run(until=horizon)` is half-open and
52does not drain.

Terminating

A terminating simulation has a natural, predeclared endpoint: closing time, completion of an order, end of a mission, or another event relevant to the purpose. Initial conditions are part of the estimand and should normally be identical across replications.

Decide how to handle entities still present at a fixed clock horizon:

  • stop and report/censor unfinished paths;
  • stop arrivals at closing but drain the system;
  • terminate on an explicit completion event.

These answer different questions. Numeric env.run(until=horizon) is half-open and does not drain.

Raw lines 38 to 53
54### Nonterminating / steady state
56A nonterminating system has no natural endpoint and targets a long-run parameter.
57Arbitrary initialization creates transient bias. A finite warm-up deletion may
58reduce that bias, but neither a warm-up nor a long run proves stationarity or
59convergence.
61Use a declared replication/deletion design:
631. estimate/justify warm-up in a pilot study;
642. make independent production replications;
653. apply the same deletion rule to each;
664. make the post-deletion run much longer than warm-up;
675. assess sensitivity to longer warm-up and run length.
69Do not label a finite-horizon operating-day model "steady state" merely because it
70has many events.

Nonterminating / steady state

A nonterminating system has no natural endpoint and targets a long-run parameter. Arbitrary initialization creates transient bias. A finite warm-up deletion may reduce that bias, but neither a warm-up nor a long run proves stationarity or convergence.

Use a declared replication/deletion design:

  1. estimate/justify warm-up in a pilot study;
  2. make independent production replications;
  3. apply the same deletion rule to each;
  4. make the post-deletion run much longer than warm-up;
  5. assess sensitivity to longer warm-up and run length.

Do not label a finite-horizon operating-day model "steady state" merely because it has many events.

Raw lines 54 to 71
72## 3. Random seeds and streams
74Pseudo-random generation is deterministic given algorithm, state, and consumption
75order. Reproducibility requires recording:
77- RNG implementation and Python/package versions;
78- base seed and derived per-replication seeds;
79- mapping of streams to stochastic sources;
80- replication index and configuration;
81- any common-random-number pairing.
83Use separate local RNG objects for distinct sources:
85```python
86arrival_rng = random.Random(arrival_seed)
87service_rng = random.Random(service_seed)
88```
90Avoid module-global `random.seed()` in reusable models: unrelated code can consume
91or reset the shared stream.
93L'Ecuyer recommends independent streams/substreams, often one stream per stochastic
94source and one substream per replication. Distinct hash-derived seeds, as used by
95the bundled scripts, provide deterministic separation for a compact standard-library
96example; they do **not** mathematically prove stream independence. For high-stakes
97or large parallel experiments, use a generator/package with explicit tested stream
98and jump/substream facilities and document it.

3. Random seeds and streams

Pseudo-random generation is deterministic given algorithm, state, and consumption order. Reproducibility requires recording:

  • RNG implementation and Python/package versions;
  • base seed and derived per-replication seeds;
  • mapping of streams to stochastic sources;
  • replication index and configuration;
  • any common-random-number pairing.

Use separate local RNG objects for distinct sources:

arrival_rng = random.Random(arrival_seed)
service_rng = random.Random(service_seed)

Avoid module-global random.seed() in reusable models: unrelated code can consume or reset the shared stream.

L'Ecuyer recommends independent streams/substreams, often one stream per stochastic source and one substream per replication. Distinct hash-derived seeds, as used by the bundled scripts, provide deterministic separation for a compact standard-library example; they do not mathematically prove stream independence. For high-stakes or large parallel experiments, use a generator/package with explicit tested stream and jump/substream facilities and document it.

Raw lines 72 to 99
100### Common random numbers
102For paired alternatives, intentionally using the same source-specific random
103numbers can reduce variance of differences. Keep replication pairs aligned and use
104separate source streams so a demand draw in one alternative does not become a
105service draw in another. Analyze paired replication differences. Common random
106numbers are a designed variance-reduction method, not independent streams across
107alternatives.

Common random numbers

For paired alternatives, intentionally using the same source-specific random numbers can reduce variance of differences. Keep replication pairs aligned and use separate source streams so a demand draw in one alternative does not become a service draw in another. Analyze paired replication differences. Common random numbers are a designed variance-reduction method, not independent streams across alternatives.

Raw lines 100 to 108
109## 4. Independent replications
111Within-run entity outcomes are usually dependent: customers share queues and system
112state. The basic independent unit is a complete replication using an independent
113stream set.
115For each replication:
117- reset model state and statistical counters;
118- use the same scenario/configuration and intended initial-condition rule;
119- use new independent random streams;
120- produce one estimate per performance measure.
122Law's output-analysis tutorial stresses that one run does not produce "the answer."
123Use at least two replications to estimate variance; practical counts should be
124chosen from desired precision, distribution shape, computational cost, and a pilot,
125not a universal magic number.
127The bundled replication runner caps counts and records every derived seed. It does
128not automatically choose a sufficient replication count.

4. Independent replications

Within-run entity outcomes are usually dependent: customers share queues and system state. The basic independent unit is a complete replication using an independent stream set.

For each replication:

  • reset model state and statistical counters;
  • use the same scenario/configuration and intended initial-condition rule;
  • use new independent random streams;
  • produce one estimate per performance measure.

Law's output-analysis tutorial stresses that one run does not produce "the answer." Use at least two replications to estimate variance; practical counts should be chosen from desired precision, distribution shape, computational cost, and a pilot, not a universal magic number.

The bundled replication runner caps counts and records every derived seed. It does not automatically choose a sufficient replication count.

Raw lines 109 to 129
130## 5. Confidence intervals
132Given independent replication estimates `X_1, ..., X_n`, a common two-sided
133Student-t interval for their mean is:
135`mean(X) +/- t_(n-1, 1-alpha/2) * s(X) / sqrt(n)`.
137State:
139- estimand and unit;
140- number of independent replications;
141- confidence level and method;
142- point estimate, interval, and half-width;
143- warm-up/run length and missing/unfinished handling.
145Conditions and caveats:
147- replication estimates must be independent and comparably generated;
148- the t interval is exact under normal replication estimates and approximate under
149 suitable large-sample behavior;
150- a tiny `n` gives unstable variance and distribution diagnostics;
151- a narrow interval around a biased/invalid model result is still wrong;
152- optional stopping based on observed precision needs a valid sequential procedure.

5. Confidence intervals

Given independent replication estimates X_1, ..., X_n, a common two-sided Student-t interval for their mean is:

mean(X) +/- t_(n-1, 1-alpha/2) * s(X) / sqrt(n).

State:

  • estimand and unit;
  • number of independent replications;
  • confidence level and method;
  • point estimate, interval, and half-width;
  • warm-up/run length and missing/unfinished handling.

Conditions and caveats:

  • replication estimates must be independent and comparably generated;
  • the t interval is exact under normal replication estimates and approximate under suitable large-sample behavior;
  • a tiny n gives unstable variance and distribution diagnostics;
  • a narrow interval around a biased/invalid model result is still wrong;
  • optional stopping based on observed precision needs a valid sequential procedure.
Raw lines 130 to 153
154### Never make a naive single-run CI
156Do not feed all customer waits from one run to an IID t interval. Positive serial
157dependence can severely understate variance. Law (2020) illustrates dramatic
158undercoverage from this approach.
160For one long steady-state run, use a justified output-analysis method such as batch
161means, spectral methods, or regenerative analysis with diagnostics. The bundled
162CLI deliberately implements independent replications, not a naive single-run CI.

Never make a naive single-run CI

Do not feed all customer waits from one run to an IID t interval. Positive serial dependence can severely understate variance. Law (2020) illustrates dramatic undercoverage from this approach.

For one long steady-state run, use a justified output-analysis method such as batch means, spectral methods, or regenerative analysis with diagnostics. The bundled CLI deliberately implements independent replications, not a naive single-run CI.

Raw lines 154 to 163
164## 6. Warm-up and transient bias
166Warm-up is an estimand/study-design issue, not an `Environment` option. SimPy has no
167automatic steady-state detector.
169Good practice:
171- reason from initial conditions and system dynamics;
172- inspect multiple pilot replications, not one noisy path;
173- use an established rule (for example Welch-type graphical analysis or a
174 documented method);
175- separate pilot selection from production inference;
176- use the same declared deletion in production runs;
177- examine sensitivity to longer warm-up and run length;
178- report discarded observations/time and window membership rule.
180Schruben developed tests for initialization bias; Robinson and Hoad et al. developed
181warm-up selection procedures. No method makes every model stationary, and visual
182flattening is not proof.
184Choose the measurement-window rule before analysis:
186- arrivals after warm-up;
187- departures after warm-up;
188- entities entirely contained after warm-up;
189- time integral clipped to `[warm_up, horizon)`.
191These estimate different quantities. The bundled queue scripts use completed
192entities whose arrival is at or after warm-up for customer means, but count all
193departures inside the window for throughput. Loss uses only arrivals/rejections
194inside the window; resource integrals are clipped to the window. They disclose
195unfinished entities. A completion-censored arrival cohort is not an unbiased
196estimator of the waiting time of all arrivals.

6. Warm-up and transient bias

Warm-up is an estimand/study-design issue, not an Environment option. SimPy has no automatic steady-state detector.

Good practice:

  • reason from initial conditions and system dynamics;
  • inspect multiple pilot replications, not one noisy path;
  • use an established rule (for example Welch-type graphical analysis or a documented method);
  • separate pilot selection from production inference;
  • use the same declared deletion in production runs;
  • examine sensitivity to longer warm-up and run length;
  • report discarded observations/time and window membership rule.

Schruben developed tests for initialization bias; Robinson and Hoad et al. developed warm-up selection procedures. No method makes every model stationary, and visual flattening is not proof.

Choose the measurement-window rule before analysis:

  • arrivals after warm-up;
  • departures after warm-up;
  • entities entirely contained after warm-up;
  • time integral clipped to [warm_up, horizon).

These estimate different quantities. The bundled queue scripts use completed entities whose arrival is at or after warm-up for customer means, but count all departures inside the window for throughput. Loss uses only arrivals/rejections inside the window; resource integrals are clipped to the window. They disclose unfinished entities. A completion-censored arrival cohort is not an unbiased estimator of the waiting time of all arrivals.

Raw lines 164 to 197
198## 7. Verification and validation
200Sargent distinguishes:
202- **conceptual model validity** — assumptions/theories and representation are
203 reasonable for intended purpose;
204- **computerized model verification** — implementation matches the conceptual
205 model;
206- **operational validation** — outputs have sufficient accuracy over the intended
207 domain;
208- **data validity** — data are adequate and correct for building/testing/running.

7. Verification and validation

Sargent distinguishes:

  • conceptual model validity — assumptions/theories and representation are reasonable for intended purpose;
  • computerized model verification — implementation matches the conceptual model;
  • operational validation — outputs have sufficient accuracy over the intended domain;
  • data validity — data are adequate and correct for building/testing/running.
Raw lines 198 to 209
210### Verification
212Use:
214- deterministic traces and event-order assertions;
215- conservation/balance identities;
216- extreme and degenerate cases;
217- analytical queue benchmarks where assumptions match;
218- independent implementation or hand calculations;
219- tests for resource release, cancellation, preemption, and deadlock;
220- monitor-on versus monitor-off equivalence.
222Passing tests establishes implementation evidence, not real-world validity.

Verification

Use:

  • deterministic traces and event-order assertions;
  • conservation/balance identities;
  • extreme and degenerate cases;
  • analytical queue benchmarks where assumptions match;
  • independent implementation or hand calculations;
  • tests for resource release, cancellation, preemption, and deadlock;
  • monitor-on versus monitor-off equivalence.

Passing tests establishes implementation evidence, not real-world validity.

Raw lines 210 to 223
224### Validation
226Use evidence appropriate to purpose:
228- subject-matter expert face validation;
229- historical/holdout system data;
230- graphical and statistical comparison of system/model behavior;
231- predictive validation when future observations become available;
232- comparison with accepted models;
233- traces/animations for logic review;
234- parameter variability and sensitivity analysis.
236Predeclare acceptable accuracy where possible. Validation is iterative and
237domain-specific; failure in a required operating condition invalidates use there.

Validation

Use evidence appropriate to purpose:

  • subject-matter expert face validation;
  • historical/holdout system data;
  • graphical and statistical comparison of system/model behavior;
  • predictive validation when future observations become available;
  • comparison with accepted models;
  • traces/animations for logic review;
  • parameter variability and sensitivity analysis.

Predeclare acceptable accuracy where possible. Validation is iterative and domain-specific; failure in a required operating condition invalidates use there.

Raw lines 224 to 238
239## 8. Sensitivity and uncertainty
241Vary uncertain inputs, structural assumptions, warm-up, run length, capacities,
242queue discipline, and initial conditions over defensible ranges. Preserve paired
243random streams for alternative comparisons when intentionally using common random
244numbers.
246Separate:
248- **Monte Carlo uncertainty** — finite replications;
249- **parameter uncertainty** — uncertain input values/distributions;
250- **structural uncertainty** — alternate model logic/boundaries;
251- **validation discrepancy** — model versus system;
252- **scenario uncertainty** — different future conditions.
254A replication CI addresses only the first under the configured model.

8. Sensitivity and uncertainty

Vary uncertain inputs, structural assumptions, warm-up, run length, capacities, queue discipline, and initial conditions over defensible ranges. Preserve paired random streams for alternative comparisons when intentionally using common random numbers.

Separate:

  • Monte Carlo uncertainty — finite replications;
  • parameter uncertainty — uncertain input values/distributions;
  • structural uncertainty — alternate model logic/boundaries;
  • validation discrepancy — model versus system;
  • scenario uncertainty — different future conditions.

A replication CI addresses only the first under the configured model.

Raw lines 239 to 255
256## 9. Reproducibility and reporting
258The STRESS-DES guidelines organize complete reporting around objectives, model
259logic, data, experimentation, implementation, and code access. At minimum retain:
261- conceptual model and assumptions;
262- exact config and input-data provenance;
263- SimPy/Python versions and environment lock/pin;
264- source revision;
265- seed/stream manifest;
266- warm-up, horizon, entity/event caps, and replications;
267- metric definitions and unit conversions;
268- validation/sensitivity evidence;
269- raw replication-level outputs and analysis code.
271Reproducibility of the program is not validity of the model.

9. Reproducibility and reporting

The STRESS-DES guidelines organize complete reporting around objectives, model logic, data, experimentation, implementation, and code access. At minimum retain:

  • conceptual model and assumptions;
  • exact config and input-data provenance;
  • SimPy/Python versions and environment lock/pin;
  • source revision;
  • seed/stream manifest;
  • warm-up, horizon, entity/event caps, and replications;
  • metric definitions and unit conversions;
  • validation/sensitivity evidence;
  • raw replication-level outputs and analysis code.

Reproducibility of the program is not validity of the model.

Raw lines 256 to 272
273## 10. No causal claims from a queue simulation alone
275A simulation computes implications of encoded assumptions. Changing a parameter
276and observing an output difference is a **model-based scenario contrast**, not an
277identified causal effect in the real system. Causal language requires defensible
278causal assumptions/design, calibrated interventions, and validation beyond SimPy.
280Use phrasing such as:
282> Under the specified arrival, service, routing, and capacity assumptions, the
283> simulated scenario produced ...

10. No causal claims from a queue simulation alone

A simulation computes implications of encoded assumptions. Changing a parameter and observing an output difference is a model-based scenario contrast, not an identified causal effect in the real system. Causal language requires defensible causal assumptions/design, calibrated interventions, and validation beyond SimPy.

Use phrasing such as:

Under the specified arrival, service, routing, and capacity assumptions, the simulated scenario produced ...
Raw lines 273 to 284
285## Primary method sources
287- [Law, "Statistical Analysis of Simulation Output Data," WSC 2020](https://informs-sim.org/wsc20papers/134.pdf)
288- [L'Ecuyer, "Random Number Generation with Multiple Streams," WSC 2015](https://informs-sim.org/wsc15papers/003.pdf)
289- [Sargent, "Verification and Validation of Simulation Models," WSC 2010](https://www.informs-sim.org/wsc10papers/016.pdf)
290- [Robinson, "Conceptual Modelling for Simulation Part I," 2008](https://doi.org/10.1057/palgrave.jors.2602368)
291- [Schruben, "Detecting Initialization Bias," 1982](https://doi.org/10.1287/opre.30.3.569)
292- [Robinson, warm-up selection, 2007](https://ideas.repec.org/a/eee/ejores/v176y2007i1p332-346.html)
293- [Hoad, Robinson, Davies, replication selection, 2010](https://doi.org/10.1057/jors.2009.121)
294- [Monks et al., STRESS guidelines, 2018](https://doi.org/10.1080/17477778.2018.1442155)
296See `sources.md` for full dated notes.