Skip to content

Independent runs and experiments ​

A Simulation executes one run at a time. Batch execution distributes independent cases across workers; it does not divide the agents in one simulation across threads. Each case supplies a unique ID and a complete input including its explicit seed.

ts
import { runBatch } from '@grabm/abm/node'
import type { SimulationInputData } from '@grabm/abm'

/** Consume each case before requesting another. Filesystem output avoids full-result IPC. */
export async function compareSeeds(
  input: SimulationInputData,
  outputDirectory: string,
) {
  const cases = [42, 43, 44].map((seed) => ({
    id: `seed-${seed}`,
    input: { ...input, run: { ...input.run, seed } },
  }))
  const references = []
  for await (const outcome of runBatch(cases, { workers: 'auto', outputDirectory })) {
    if (outcome.status === 'failed') throw outcome.error
    references.push({ id: outcome.id, result: outcome.result })
  }
  return references
}

Use runBatch from @grabm/abm/node for isolated Node child processes or from @grabm/abm/experiments for browser module workers. Browser options accept the same createWorker bundler override as Simulation. No caller-managed worker pool is required. Node options can set outputDirectory to publish datasets and return references; without it, completed cases contain full in-memory results.

Concurrency and lifecycle ​

The default is one worker. workers: 'auto' uses at most four, leaves one reported CPU available where possible, and never exceeds the case count. Explicit positive integer counts override this heuristic. CPU counts are hints, not memory measurements. Backend applications must enforce admission limits across multiple batches/jobs.

The async iterator yields { id, status: 'completed', result } or { id, status: 'failed', error } as cases finish. Each slot retains at most one unconsumed result. The iterator does not collect a complete experiment for you. A failed case is not retried automatically. An aborted signal cancels queued and active work and rejects with AbortError; breaking iteration also releases active workers. Concurrent runs use fresh engine state, so their outputs do not depend on concurrency.

Compare several seeds ​

summarizeExperiments is available from /analytics and /experiments. Pass records with alternative, seed, and result, optionally naming a baseline. It reports sample count, mean, sample standard deviation, minimum, and maximum for completed trips, mean completed-trip travel time, unmet decisions, and peak observed facility occupancy. No-trip mean travel is represented as zero and should be interpreted alongside completed-trip count.

Paired differences subtract baseline from candidate for matching seeds only. Duplicate alternative/seed records and mismatched result seeds are rejected. With fewer than two samples, reported standard deviation is zero; this is not evidence of certainty. Preserve raw measures and sample counts alongside composite scores. Keep reporting resolution aligned when comparing occupancy summaries.

Synthetic reference tests establish accounting and reproducibility. These summaries are not empirical validation, confidence intervals, or automatic calibration.

Documentation for the grABM library.