Antifragile System

A simple antifragile system simulation where each failure reduces the probability of future failures.

Level: Beginner

reinforcing-loopreliability

  • Flows: failure
  • Feedback Loops: learning from failure
  • Probes: failure, failure_rate, total_failures

Feedback Loops

Understand the balancing and reinforcing feedback loops that drive system behavior and create complex dynamics in systems thinking.

Take the Quiz
simulation.py

Learning from failure – an antifragile system

Welcome! Each time the system trips up it tweaks itself so that another failure becomes a little less probable. This tiny loop lets us watch reliability grow as the system learns from its mistakes.


from tys import probe, progress

Simulate a system that improves after each failure.

def simulate(cfg: dict):

    import simpy
    import random

    env = simpy.Environment()

    failure_rate = cfg["failure_rate"]  # probability of failure each step
    learning_rate = cfg["learning_rate"]  # failure rate reduction after failure
    iterations = cfg["iterations"]

    done = env.event()

Loop through iterations and update the failure rate.

    def run():
        nonlocal failure_rate
        failures = 0
        for t in range(iterations):
            if random.random() < failure_rate:
                failures += 1
                failure_rate *= 1 - learning_rate
                probe("failure", env.now, 1)
            else:
                probe("failure", env.now, 0)
            probe("failure_rate", env.now, failure_rate)
            probe("total_failures", env.now, failures)
            progress(int(100 * (t + 1) / iterations))
            yield env.timeout(1)
        done.succeed({"failures": failures, "final_failure_rate": failure_rate})

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


def requirements():
    return {
        "external": ["simpy==4.1.1"],
    }
Default.yaml
failure_rate: 0.3
learning_rate: 0.1
iterations: 50
Charts (Default)

failure

failure chart
Samples50 @ 0.00–49.00
Valuesmin 0.00, mean 0.12, median 0.00, max 1.00, σ 0.32

failure_rate

failure_rate chart
Samples50 @ 0.00–49.00
Valuesmin 0.16, mean 0.23, median 0.22, max 0.30, σ 0.06

total_failures

total_failures chart
Samples50 @ 0.00–49.00
Valuesmin 0.00, mean 2.74, median 3.00, max 6.00, σ 2.54
Final Results (Default)
MetricValue
failures6.00
final_failure_rate0.16
FAQ
How does failure reduce future failure probability?
Each time a failure occurs the failure_rate is multiplied by (1 - learning_rate), lowering the chance of failing again.
Where is randomness used in this simulation?
Each iteration compares random.random() to failure_rate to decide if a failure happens.
When does the run event resolve?
After iterations steps complete the event succeeds with the failure count and final rate.