Example

Atmospheric CO₂ Bathtub

Level: Intermediate

climatestocks-flowsbalancing-loopslow-drainpolicy

What it shows

CO₂ rises while emissions exceed the sink: the same cut turns the bathtub around, but waiting until year 50 leaves a higher peak and a higher year-120 level.

How to use

Open the model in the playground, change one parameter in the YAML, and run it again. The annotated simulation.py below is the model. Each config is a saved scenario: Cut now (year 20), Delay (year 50).

Open in Playground

Key parameters

  • Stocks: atmospheric CO₂
  • Flows: emissions, removals
  • Feedback loops: sink removal (balancing)
  • Probes: co2_atmos, emissions, removals, net_flow

Stocks and Flows

Learn about the foundational concepts of Stocks and Flows in systems thinking and how they interact to create system behavior.

Take the Quiz
simulation.py

The CO₂ bathtub turns when emissions fall below the sink

Atmospheric CO₂ is a stock with a slow drain: it rises while emissions outrun removals, and it turns the year a cut pushes the faucet below that drain. The knob is when the cut arrives. The same 70% cut in year 20 peaks at 877 and is still 511 at year 120; delay it to year 50 and the peak is 909 and the century ends at 601. Neither run reaches the new balance near 300 — the sink removes about one percent a year, so waiting leaves the extra CO₂ in the tub.


from tys import probe, progress

Step the bathtub once a year. The peak is the year before the cut.

def simulate(cfg: dict):

    import simpy
    env = simpy.Environment()

    co2 = float(cfg["initial_co2"])          # stock already in the air
    emit_rate = float(cfg["emission_rate"])  # annual inflow, before any cut
    sink_rate = float(cfg["sink_rate"])      # fraction of the stock removed each year
    years = int(cfg["years"])
    cut_year = cfg.get("policy_year")        # KNOB: the year the cut arrives
    cut_frac = float(cfg.get("cut_fraction", 1.0))
    if cut_year is not None:
        cut_year = int(cut_year)

    peak_co2 = None
    peak_year = None
    done = env.event()

One update: faucet minus a percent of the stock

Removals are sink_rate * co2, so the tub heads for emissions / sink_rate. Before the cut that balance is 1000 and the stock is still climbing toward it. The cut multiplies emissions by cut_fraction at the start of policy_year. Keeping 30% drops the faucet from 10 to 3, under the ~9 the sink is already removing, so that same year net flow changes sign and the stock turns. The new balance is 300, and a 1% drain does not get there inside this window.

    def run():
        nonlocal co2, emit_rate, peak_co2, peak_year
        for y in range(years):
            if cut_year is not None and y == cut_year:
                emit_rate *= cut_frac
            removals = sink_rate * co2
            net = emit_rate - removals
            co2 = max(co2 + net, 0.0)
            if peak_co2 is None or co2 > peak_co2:
                peak_co2 = co2
                peak_year = y

Stock, the two flows, and their difference. net_flow is the turning signal: positive while the tub fills, negative after.

            probe("co2_atmos", env.now, co2)
            probe("emissions", env.now, emit_rate)
            probe("removals", env.now, removals)
            probe("net_flow", env.now, net)
            pct = int(100 * (y + 1) / years)
            if y == years - 1:
                progress(100, "The drain is still catching up. The new balance is not in this window.")
            elif cut_year is not None and y == cut_year:
                progress(pct, "Emissions fell below the sink. The stock turns this year.")
            else:
                progress(pct)
            yield env.timeout(1)

        equilibrium = emit_rate / sink_rate if sink_rate > 0 else None
        done.succeed({
            "final_co2": co2,
            "peak_co2": peak_co2,
            "peak_year": peak_year,
            "equilibrium": equilibrium,
        })

    env.process(run())
    env.run(until=done)
    return done.value


def requirements():
    return {"external": ["simpy==4.1.1"]}
Cut now (year 20).yaml
# cut-now.yaml — default. The 70% cut lands in year 20, while emissions still exceed the sink.
# The stock peaks the year before (877) and is still 511 at year 120, far above the new balance of 300.
# delayed.yaml is the same file with policy_year: 50.
initial_co2: 850
emission_rate: 10
sink_rate: 0.01
years: 120
policy_year: 20
cut_fraction: 0.3
Charts (Cut now (year 20))

co2_atmos

CO₂ in the air. It climbs while emissions exceed the sink and turns the year of the cut; the axis runs from the new balance (300) to the old one (1000).

Samples120 @ 0.00–119.00
Valuesmin 511.32, mean 696.08, median 684.28, max 877.31, σ 121.49

emissions

Annual emissions. They stay at 10 until the policy year, then step down to 3 — the same cut in both presets.

Samples120 @ 0.00–119.00
Valuesmin 3.00, mean 4.17, median 3.00, max 10.00, σ 2.61

removals

CO₂ the sink removes that year, one percent of the stock. It rises with the tub and only slowly follows the stock back down.

Samples120 @ 0.00–119.00
Valuesmin 5.13, mean 6.99, median 6.88, max 8.77, σ 1.21

net_flow

Emissions minus removals. Positive fills the tub; the line crosses below zero on the year of the cut, which is the peak.

Samples120 @ 0.00–119.00
Valuesmin -5.77, mean -2.82, median -3.17, max 1.50, σ 2.11
Final Results (Cut now (year 20))
MetricValue
final_co2511.32
peak_co2877.31
peak_year19.00
equilibrium300.00
Delay (year 50).yaml
# delayed.yaml — same bathtub, cut held until year 50. The peak rises to 909 and year 120 ends at 601.
# Only policy_year differs from cut-now.yaml.
initial_co2: 850
emission_rate: 10
sink_rate: 0.01
years: 120
policy_year: 50
cut_fraction: 0.3
Charts (Delay (year 50))

co2_atmos

CO₂ in the air. It climbs while emissions exceed the sink and turns the year of the cut; the axis runs from the new balance (300) to the old one (1000).

Samples120 @ 0.00–119.00
Valuesmin 601.48, mean 796.70, median 848.24, max 909.25, σ 99.61

emissions

Annual emissions. They stay at 10 until the policy year, then step down to 3 — the same cut in both presets.

Samples120 @ 0.00–119.00
Valuesmin 3.00, mean 5.92, median 3.00, max 10.00, σ 3.45

removals

CO₂ the sink removes that year, one percent of the stock. It rises with the tub and only slowly follows the stock back down.

Samples120 @ 0.00–119.00
Valuesmin 6.05, mean 7.99, median 8.50, max 9.09, σ 0.98

net_flow

Emissions minus removals. Positive fills the tub; the line crosses below zero on the year of the cut, which is the peak.

Samples120 @ 0.00–119.00
Valuesmin -6.09, mean -2.07, median -3.35, max 1.50, σ 2.84
Final Results (Delay (year 50))
MetricValue
final_co2601.48
peak_co2909.25
peak_year49.00
equilibrium300.00
FAQ
What sets the turning point?
The stock rises while emissions exceed removals and falls once emissions drop below them. Removals are sink_rate times the stock, so at the starting 850 they are 8.5 against emissions of 10. A cut has to push emissions under the removal rate already in force. Keeping 30% (a faucet of 3) does that the year the policy arrives, which is why the peak is the year before policy_year. A shallower cut that left emissions above current removals would keep filling the tub, only more slowly, toward a still-high balance of emissions / sink_rate.
Why does waiting raise both the peak and the level at year 120?
The two presets share every parameter except policy_year. Each year before the cut, inflow still exceeds the drain, so the stock climbs: 877 in year 19 if the cut lands in year 20, 909 in year 49 if it waits until year 50. After the cut the new balance is 300 either way, but the gap to that balance shrinks by only one percent a year. Thirty fewer years of drain, starting from a higher peak, is why year 120 is 601 instead of 511.
Why hasn't the level reached the new balance?
The sink removes one percent of the stock per year. Closing a gap of several hundred units at that rate takes longer than this 120-year window, so both runs are still well above 300 at the end. There is no stabilization year to plot inside the window — the stock and the sign of net flow are the signals that move.
Which probe shows the story?
co2_atmos is the stock, drawn on a shared axis from the new balance (300) to the old one (1000) so the two presets stay comparable. net_flow is emissions minus removals: positive while the tub fills, and it crosses below zero on the year of the cut, which is the peak. emissions is the step down from 10 to 3; removals is the drain slowly following the stock.
What misconception does this debunk?
That cutting emissions immediately lowers atmospheric CO₂, and that delaying the same cut only postpones an identical outcome. The level is the accumulation of the imbalance, so it turns only when the faucet falls below the drain, and the extra CO₂ is still in the tub a century later. This is a one-stock teaching bathtub, not a calibrated carbon cycle: the sink does not saturate, and the units are chosen so that arithmetic stays legible.