﻿# SimPy Container withdrawals: a whole-amount grant is not continuous physical flow

Read SimPy ContainerGet as an amount-threshold operation, and model transfer duration separately when a digital twin needs the path of material through time.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/simulation-simpy-container-whole-amount-not-continuous-flow/
Language: en

## A plausible completion time can hide a different level trace

A liquid-handling twin requests a batch from a shared tank and then waits for its transfer duration. The dashboard plots Container level as if it were a sensor reading of liquid leaving continuously. The operation may produce the intended completion time while representing inventory at a different boundary. Decide whether the modeled level means physical material in the tank, unreserved stock or another accounting quantity before comparing the trace with real instrumentation.

## The grant removes a complete requested amount

The pinned [Container implementation](https://gitlab.com/team-simpy/simpy/-/raw/4.1.2/src/simpy/resources/container.py) checks whether enough level exists for the requested amount. When it does, it subtracts that whole amount and succeeds the request; otherwise the operation remains pending. This is not an automatically evolving flow process. The code does not gradually drain the available fraction while waiting for the remainder. Preserve the request amount and grant time when explaining the inventory step to a consumer of simulation output.

## Service duration is a separate modeled operation

The official [refueling example](https://simpy.readthedocs.io/en/stable/examples/gas_station_refuel.html) acquires a pump, withdraws fuel from the container and then waits for a duration derived from the refueling rate. That sequence is a useful queueing abstraction, but the timeout does not retroactively spread the withdrawal over its duration. Interpret the example according to its stated accounting operations. Do not use its container trajectory as a high-fidelity hydraulic prediction merely because a rate appears in the service-time calculation.

## Define reservation and physical inventory separately if needed

If the application needs to reserve a whole batch before transfer, a discrete stock deduction may be appropriate for available inventory. Physical material still in transit or in the source tank requires its own state and transfer rule. If continuous depletion matters, choose an explicitly modeled flow or a justified discretization with conservation checks. Do not silently reinterpret Container level halfway through a report, switching between available stock and physical volume to make each graph look plausible.

## Propose a partial-stock threshold fixture

A proposed fixture should start with less stock than a requested batch, inspect that withdrawal remains pending and then add enough material to satisfy it. Retain the resulting level change and the separate service-completion time. Compare these against the declared inventory meaning, including any in-transit state. No SimPy material-transfer experiment was executed here. Acceptance should establish quantity conservation and accounting boundaries rather than infer a measured physical flow profile from a queueing primitive.

## Keep the physical fidelity claim explicit

The [simulation-validation study](/journal/cxl-pool-simulator-two-host-validation-optical-bandwidth-sweep/) covers another distinction between model output and physical evidence; [stack reproducibility](/journal/software-stack-reproducibility/) supports preserving the transfer implementation. A correct Container balance validates an accounting abstraction. It does not validate pump dynamics, pressure, mixing or sensor response. Those require different state equations and reference data when the twin’s purpose extends beyond batch availability, queueing and completion-time accounting.
