Clock Process

This is the smallest useful Cimba Python model: a process that wakes up on a fixed period. It shows the essential shape of every model — a Model subclass with typed fields, a process function, a collect function, and an experiment.

import cimba.sim as sim


class Clock(sim.Model):
    tick_count: sim.Output   # scalar result reported per trial
    ticks: sim.State         # trial-local counter, auto-zeroed

    @sim.process
    def ticker(self: "Clock"):
        while True:
            sim.hold(1.0)
            self.ticks = self.ticks + 1

    @sim.collect
    def collect(self: "Clock"):
        self.tick_count = self.ticks


model = Clock("Clock")

def main() -> None:
    exp = model.experiment(replications=1, duration=3.5, warmup=0.0, seed=12)
    exp.run()
    print(int(exp["tick_count"][0]))


if __name__ == "__main__":
    main()

The ticker wakes at simulated times 1.0, 2.0, and 3.0. The trial ends at 3.5, before the wakeup that would have happened at 4.0, so tick_count is 3.