Antifragile System

A simple model where each failure reduces the probability of future failures.

Level:Intermediate

learningrobustnessresilienceadaptation

  • 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.

Explore Feedback Loops
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 {
        "builtin": ["micropip", "pyyaml"],
        "external": ["simpy==4.1.1"],
    }
config.yaml
failure_rate: 0.3
learning_rate: 0.1
iterations: 50