Gillespie SSA For A Tristable Gene Regulatory Network
Domain: physical_sciences — Systems & Microbial Biology

Summary: Implement exact Gillespie stochastic simulation and tau-leaping in NumPy for a three-gene mutual-inhibition chemical kinetics model, then report validation, multistability, bifurcation, and acceleration results.

Task prompt:
You are implementing a NumPy-only stochastic simulation workflow for a
three-gene mutual-inhibition regulatory network. The full scientific
specification is in `base/input/problem_spec.md`.

## Your Task
1. Read `base/input/problem_spec.md` end to end. It defines:
   - Tier 1: exact Gillespie SSA for a birth-death process.
   - Tier 2: exact Gillespie SSA for a three-gene mutual-inhibition network.
   - Tier 3: bifurcation scan plus tau-leaping comparison.
   - Required JSON schemas, seeds, event counts, parameters, and runtime budget.

2. Set up the Python runtime with:
   ```
   uv sync --frozen --project base/input/runtime_env
   ```
   Then run your code with `base/input/runtime_env/.venv/bin/python` or activate
   that environment. It provides NumPy only; use the standard library for JSON,
   time, and math utilities.

3. Implement the simulations from scratch in Python/NumPy:
   - Use `numpy.random.default_rng(seed)` for all random number generation.
   - Use exact SSA for Tier 1 and Tier 2.
   - Implement tau-leaping for Tier 3 with the leap condition and non-negative
     population handling described in the spec.
   - Do not use SciPy, GillesPy2, BioSimulator, StochPy, COPASI, StochKit, or
     any dedicated stochastic simulation package.

4. Save all final artifacts under `base/output`:
   - `base/output/tier1_results.json`
   - `base/output/tier2_results.json`
   - `base/output/tier3_results.json`
   - `base/output/gillespie_solver.py`

   `gillespie_solver.py` should be your reusable implementation, not a notebook
   transcript, so the simulation can be reproduced from source.

## Output Contract
- Follow the JSON schemas in `problem_spec.md` for all three result files.
- Probabilities and basin fractions must be finite values in `[0, 1]` and should
  sum to one where the spec defines a partition.
- Use the exact Tier 3 alpha grid and comparison points from the spec.
- Overwrite stale files in `base/output` if they already exist.

## Boundaries
- Do not modify anything under `base/input`.
- Write only under `base/output`.


The agent must:
Read `input/problem_spec.md` for the birth-death validation, three-gene mutual-inhibition model, bifurcation scan, tau-leaping requirements, seeds, event counts, and JSON schemas.
Provision the Python runtime via `uv sync --frozen --project input/runtime_env` and run with the resulting NumPy environment.
Implement exact Gillespie SSA for Tier 1 and Tier 2 using `numpy.random.default_rng(seed)`.
Compute Tier 2 trajectory statistics, basin fractions, ensemble statistics, and 50 lag autocorrelation arrays.
Implement the Tier 3 alpha scan and tau-leaping comparison, enforcing non-negative populations and the specified leap condition.
Write the three result JSON files plus reusable `gillespie_solver.py` under `output/`.

Software: Python
NumPy

Input files:
name: Problem specification
format: `.md`
description: Full task specification with models, parameters, seeds, required simulations, output schemas, banned libraries, and runtime budget.
name: Runtime manifest
format: `.toml`
description: Declares the NumPy-only Python runtime the agent installs with uv.
name: Runtime lockfile
format: `.lock`
description: Reproducible lock companion to the runtime manifest.