npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@plantagoai/yoursim-engine

v0.1.2

Published

Discrete-event simulation engine + CLI: model service/queue/network systems, estimate waits/utilization/throughput, and optimize designs against a budget and service targets.

Readme

@plantagoai/yoursim-engine

A zero-dependency TypeScript discrete-event simulation (DES) engine for service, queue, and network systems. No DOM, no Node-specific APIs — the same code runs in the browser (in a Web Worker), in Node (CLI and tests), and in any other JS host.

You describe a system as a graph of five generic node types — source, queue, resource, branch, sink — then run seeded replications to get KPIs with 95% confidence intervals, record a single run for playback, or optimize parameters against a budget and service targets.

Public API

All exports come from the package entry point (src/index.ts).

buildSimulation(model, seed, emit?) → BuiltSimulation

Validates model, wires up the runtime nodes with seeded per-node RNG streams, and returns a controllable simulation. The optional emit callback receives every SimEvent as it happens (used by recordRun and detailed experiments).

interface BuiltSimulation {
  sim: Simulation;
  nodes: Map<string, RuntimeNode>;
  run(until: number): void;       // advance the clock to `until`
  resetStats(): void;             // discard collected stats (used for warm-up)
  summaries(): Record<string, Record<string, number>>; // per-node metrics
}

runExperiment(model, settings, onProgress?, options?) → ExperimentResult

Runs settings.replications independent replications, applies the warm-up, and aggregates each metric into a mean and a 95% CI half-width. Pass { detailed: true } to also collect percentiles, histograms, and time series.

interface RunSettings {
  horizon: number;      // total run length (includes warm-up)
  warmup: number;       // stats before this time are discarded
  replications: number;
  seed: number;
}

interface MetricSummary { mean: number; ci95: number }

interface ExperimentResult {
  replications: number;
  nodes: Record<string, Record<string, MetricSummary>>; // nodeId → metric → summary
  detail?: DetailStats; // present when options.detailed is true
}

type OnProgress = (completed: number, total: number) => void;
interface ExperimentOptions { detailed?: boolean; buckets?: number }

recordRun(model, settings) → RunRecording

Runs one replication (using the same seed as experiment replication 0) and records every event, for deterministic animated playback.

interface RunRecording {
  horizon: number;
  warmup: number;
  nodeIds: string[];
  events: SimEvent[];
}

optimize(model, problem, settings, options?, ceSeed?, onProgress?) → OptimizationResult

Cross-Entropy search over integer design variables (servers or capacity on chosen nodes), minimizing total cost subject to constraints on KPIs. Uses common random numbers (a fixed settings.seed) across candidates for fair comparison.

interface OptVariable {
  nodeId: string; param: 'servers' | 'capacity';
  min: number; max: number; costPerUnit: number;
}
interface OptConstraint {
  nodeId: string; metric: string;
  soft?: number; hard?: number; wSoft: number; wHard: number;
}
interface OptProblem { variables: OptVariable[]; constraints: OptConstraint[] }

interface Candidate {
  values: Record<string, number>; cost: number;
  metrics: Record<string, number>; score: number; feasible: boolean;
}
interface OptimizationResult {
  best: Candidate;
  trajectory: { iter: number; bestScore: number; eliteMeanScore: number }[];
  evaluations: Candidate[];
}

Constraint metric may be any per-node metric (e.g. avgWait, utilization) or the percentile metrics p95Wait / p95TimeInSystem (which automatically enable detailed mode).

Other exports

Simulation, EventCalendar, Random, streamSeed, sample (+ Distribution), Tally, TimeWeighted, the node classes (SourceNode, QueueNode, ResourceNode, BranchNode, SinkNode), quantile, histogram, and the optimizer helpers (applyVariables, scoreAndFeasible, costOf, metricValue, needsDetailed). Model types: SimModel, ModelNode, ModelEdge, NodeType, and the per-type *Params.

Minimal usage

import { runExperiment, type SimModel } from '@plantagoai/yoursim-engine';

const model: SimModel = {
  schemaVersion: 1,
  nodes: [
    { id: 'src', type: 'source', params: { interarrival: { dist: 'exp', mean: 10 } } },
    { id: 'q', type: 'queue', params: { discipline: 'fifo' } },
    { id: 'svc', type: 'resource', params: { servers: 1, service: { dist: 'exp', mean: 8 } } },
    { id: 'out', type: 'sink', params: {} },
  ],
  edges: [
    { id: 'e1', from: 'src', to: 'q' },
    { id: 'e2', from: 'q', to: 'svc' },
    { id: 'e3', from: 'svc', to: 'out' },
  ],
};

const result = runExperiment(model, {
  horizon: 20000, warmup: 2000, replications: 20, seed: 42,
});

console.log(result.nodes['svc'].utilization);          // ~0.8 (ρ = 8/10)
console.log(result.nodes['out'].avgTimeInSystem.mean); // mean time in system

CLI

The package also ships a JSON-in/JSON-out CLI:

npx @plantagoai/yoursim-engine run docs/examples/mm1.json --pretty

Commands: validate, run, optimize <problem.json>, record. Settings come from the model's settings block or --horizon --warmup --replications --seed; add --pretty for indented JSON. See the tutorial.