agentsclimarketplace

Pysb diagnose

Skill ShihChiangLo/grill-my-model/skills/pysb-diagnose

Diagnose a PySB model whose output looks wrong — a curve that rises and never falls, a flat observable, a species that should be conserved but is not, negative concentrations, an integrator that fails or crawls, a dose-response with the wrong midpoint, or a simulation that disagrees with experimental data. Use when a model already exists and the question has shifted from "what should I build" to "why is it doing that". Triggers on "the simulation looks wrong", "this curve shouldn't do that", "my model doesn't match my data", "why is it going to zero", or an integrator error message.From its SKILL.md

Install
npx -y skills add ShihChiangLo/grill-my-model --skill pysb-diagnose

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

7.3 KB, as published. Nobody here has run it

Diagnosing a model that looks wrong

The model exists. The question is no longer "what do you want to build" but "what did you expect, and what did you get". Those are the two facts you need before touching anything.

Do not start editing. A model that surprises its author is doing something, and the something is information. Find it first.

The opening move

Always ask these two, in this order, before any investigation:

"What did you expect this curve to do?"

"What is it doing instead?"

Get both in the user's own words. Users very often discover the answer while answering the first one, because it forces them to state a mechanism they had not written down.

Then, and only then, look at the model.

Triage: is it broken, or is it right and surprising?

Run scripts/validate_model.py (in skills/pysb-model-builder/scripts/) before anything else. It separates the two cases quickly. Errors mean broken. A clean run with a surprising curve usually means the model is faithfully doing what was specified, and the specification does not match what the user believes they specified — which is the more interesting failure and the one the interview exists to catch.

Say this distinction out loud. "The model is doing exactly what we told it; the question is whether we told it the right thing" reframes the situation from a bug hunt into a modelling conversation, which is where the value is.

Symptom table

A curve rises and never comes back down

Almost always a missing reverse process: no phosphatase, no degradation, no unbinding, no GTP hydrolysis. Check whether every modification rule has a counterpart.

Ask: "in your cells, does this come back down? Over what timescale?" If yes, the model is missing the mechanism that does it, and adding it usually costs one rule and one parameter.

An observable is completely flat

Three candidates, in order of likelihood: the observable's pattern matches nothing (a site state was misspelled, or the pattern is over-constrained); the species has no reactions connecting it to anything; or its initial condition is zero and nothing produces it.

Check len(model.species) and print the species list. A pattern that matches nothing is silent — PySB does not warn.

Total amount of something drifts when it should be conserved

The validator's conservation check reports this with the rules that could explain it. If no rule explains it, there is an accounting bug: a rule that produces more copies of a monomer than it consumes. This is the classic consequence of encoding states as separate monomers (pitfalls.md §2), where a rule converts ERK into pERK and total ERK silently disappears.

Negative concentrations

Usually numerical, occasionally structural. Tighten tolerances first:

integrator_options={'rtol': 1e-10, 'atol': 1e-14}

If negatives persist and are large relative to the species' own scale, look for a rule that consumes a species faster than it can be replenished — often a first-order rate that is far too large, or a pseudo-first-order lump with the wrong unit.

nan in the output, or the integrator fails

Stiffness or a bad parameter. Check for rate constants spanning more than about ten orders of magnitude — that usually indicates a unit mix-up rather than genuine stiffness. Then check for values above the physical limits in kinetic_parameters.md: nothing bimolecular exceeds ~1e10 M⁻¹s⁻¹.

Bisect: set suspicious parameters to a middle value one at a time and see which one restores integration.

Simulation is correct but far too slow

Install cython. Check the species count — above a few hundred, look for a monomer with more sites than the reactions actually use (pitfalls.md §9).

The dose-response midpoint is off by orders of magnitude

Check, in this order:

  1. Units. A factor of 1e3 or 1e6 is a nM/µM/M mix-up, not biology.
  2. Depletion. If the target concentration is comparable to the ligand concentration, the apparent EC50 exceeds the true Kd. Compare the model's target concentration against the real assay's.
  3. Protocol. Pre-incubation time, dilution steps, and readout time all move the apparent IC50 — dramatically so for covalent or slow-binding inhibitors, where apparent IC50 falls indefinitely with incubation time. The model must simulate the actual protocol, not an idealised equilibrium.
  4. Readout timing. Reading at 10 minutes when the model is read at steady state is not a comparison.

The model disagrees with experimental data

Before touching parameters, check that the observable matches what the assay measures (pitfalls.md §6). A phospho-antibody sees the protein in complexes; an observable constrained to the free form does not. This produces systematically wrong shapes that look exactly like a parameter problem and are not.

Then check whether the disagreement is in shape or in scale. A scale mismatch is often a normalisation or a units issue. A shape mismatch is mechanistic and means the model is missing something — which is a result, not a failure, and worth saying so.

Only then consider parameters, and be explicit about which ones were placeholders to begin with.

A rule seems to fire on species it shouldn't

The wildcard trap (pitfalls.md §1). Print the generated reactions and look at what the rule actually produced:

from pysb.bng import generate_equations
generate_equations(model)
for i, rxn in enumerate(model.reactions):
    print(i, rxn['rule'], [model.species[j] for j in rxn['reactants']],
          '->', [model.species[j] for j in rxn['products']])

This is the single most useful debugging output in PySB, and non-expert users never know it exists. Show it to them.

Useful introspection

len(model.species)                      # network size
model.species                           # every species generated
model.reactions                         # every concrete reaction
model.odes                              # symbolic ODE right-hand sides
[p.name for p in model.parameters]
res.species                             # per-species trajectories, not just observables

res.species is the one to reach for when an observable behaves strangely — it shows where the material actually went.

Closing a diagnosis

State three things: what the model was actually doing, why (mechanistically, not in terms of code), and what changed. If the answer was "the model is right and the expectation was wrong", say that clearly and record it in model_card.md — a surprise that survives investigation is the most valuable output a model produces, and it will be forgotten by next week if it is not written down.

Update model_spec.yaml, regenerate model.py, and re-validate. Never leave a hand-patched model.py that no longer matches its spec.

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.