Make PyBNF agent-ready, as bngsim 0.18.0 is: a guide in the package, errors and results a program can read, and a command with JSON output

Aperta
#1,054 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The issue proposes many independently scoped changes; choose one checklist item before starting. Read the corresponding PyBNF implementation and tests, then use the bngsim issue or release branch cited for the related behavior. Define completion around that item's listed outcome and add a test that keeps it correct, as the issue requests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

More and more fits will be set up and run by an AI agent on someone's behalf. The person says "fit this model to these data." The agent writes a configuration file, runs PyBNF, reads the output and reports a best fit. Often nobody reads the configuration. For that user, what matters most is whether PyBNF helps the agent reach a right answer and tells it when it has not.

bngsim did this work under lanl/bngsim#1710, and its coming 0.18.0 release (branch release/0.18.0) has all of it. That issue leaves PyBNF out and says why it should follow: "An agent asked to fit a model needs the same things there." This issue is that work for PyBNF.

PyBNF already has the hard part. It refuses configurations it cannot run correctly, and most refusals name the cause and a fix. PybnfError carries hints, and an edition 1 key such as fit_type gets an error that names job_type. What PyBNF lacks is the easy part. An agent has no guide made for it, errors are text only, every failure exits with code 1, and the results are text files written for a person.

Where an agent goes wrong with PyBNF today, by stage:

  1. Choosing. PyPI describes PyBNF as fitting BioNetGen and SBML models "using metaheuristics." It does not mention gradient fitting, profile likelihood, the MCMC samplers, Antimony or PEtab. (bngsim: lanl/bngsim#1698.)
  2. Knowing the keys. The agent remembers an old release, or nothing. There is no guide in the package and no llms.txt on the docs site.
  3. Recovering from a wrong key. job_typ = fit gets "job_typ is not a valid configuration key" with no suggestion. bngsim answers a wrong name with the right one, and answers another tool's names with the call to use.
  4. Getting started. No example ships in the wheel. The tutorial lessons in examples/tutorial would be ideal, since each fits data made from known parameters, but they exist only in the repository.
  5. Running the right thing. A run with no terminal and an existing output_dir crashes with EOFError (#1041). There is no way to check a configuration without starting the fit.
  6. Knowing what it has. Results are spread over text files. Nothing says, in one place a program can read, what was fit, with which backend and seed, how the run ended, how many simulations failed, and what each file holds.
  7. Checking before reporting. Nothing tells the agent whether to trust the fit: whether the best fit sits on a bound, whether the starts agree, whether the objective value comes back when the best fit is run again.
  8. Acting from a shell. pybnf has one mode, -c CONF. Errors go to standard output, every failure exits 1, and there is no --version, --json or doctor command.

Proposed work. Each item can become its own issue.

Cheap, and each helps on its own:

  • The PyPI description, README and module docstring say what PyBNF does now: the algorithms, the model formats, PEtab, gradient fitting, profile likelihood and the samplers. The README gets a section for AI agents.
  • An agent guide for the installed version, inside the wheel: pybnf.agent_guide(), pybnf guide, and pybnf skill --out FILE to write it as a SKILL.md. It covers a minimal edition 2 configuration, the rules that otherwise give wrong answers, what a refusal means, what needs what, a translation table from PEtab, pyPESTO, Data2Dynamics, COPASI and edition 1 keys, and how to check a fit. The test suite runs every configuration in it.
  • llms.txt and llms-full.txt on the docs site, reusing bngsim's Sphinx extension (docs/_ext/llms_txt.py).
  • A misspelled key, keyword or name gets its close matches (job_typ gets job_type). Keys from other tools get the edition 2 key to use.
  • A run with no terminal never prompts. It refuses with a message that names the directory and the flag to use (#1041).
  • pybnf --version.

Errors and results that a program can read:

  • Every PybnfError carries a stable code, details, remedies and to_dict(), with a generated page of codes, as bngsim's errors do. A bngsim error that PyBNF wraps keeps its code.
  • A results record, Results/record.json: the PyBNF and bngsim versions, the configuration file and its hash, the edition, job_type, seed and backend of each model, the best fit and its objective value, why the run stopped, the number of evaluations and of failed simulations, every warning with a code, and what each file in Results holds.
  • A progress file a program can poll during a long fit, so an agent does not have to read the log.
  • pybnf inspect CONF: load and resolve the configuration with the same checks a run makes, then report the job, the free parameters with their bounds and priors, the experiments and the model outputs their columns match, the backend of each model and why, and the simulation budget. It runs nothing.

Built on those:

  • A check of a finished fit's Results directory: parameters at a bound, agreement among starts, the objective value on a rerun of the best fit, the fraction of failed simulations, and for a stochastic fit the confirmation from #659. It needs a name other than check, which job_type = check (model checking) already uses.
  • Bundled examples: pybnf examples lists the tutorial lessons, and pybnf examples NAME --out DIR writes one out with the parameters its data were made from.
  • Subcommands for the pybnf command (doctor, guide, skill, examples, inspect, run), each with --json: one JSON object on standard output, an error as JSON on standard error, and an exit code for each outcome (usage error, configuration refused, run failed, budget or time limit reached). pybnf -c CONF keeps working.
  • pybnf doctor: the PyBNF and bngsim versions, bngsim.capabilities(), whether BNG2.pl is found and where, and which optional packages are installed (libRoadRunner, petab, dask, jax, arviz), with the fix for each one that is missing.

Measuring it. bngsim measures its version of this with agents in lanl/bngsim-benchmarks#17. A fitting task belongs in the same benchmark: give an agent a model and data, and score whether it reports the right best fit and says when the fit cannot be trusted.

A caution, carried over from lanl/bngsim#1710. Every item adds surface that has to stay right. The guide is tested by running it, the translation table by a test that pins it, and the JSON schema belongs to the command, so there is only one. An item that no test can keep right should not be built.

How this was checked. On 2026-11-27, with PyBNF 1.8.2 from main on macOS, a configuration with job_typ = fit exited 1 and printed "job_typ is not a valid configuration key" to standard output, with nothing on standard error. The bngsim features above come from its release/0.18.0 branch and from lanl/bngsim#1710.

Lingua principale
Python
Stelle
26
Fork
25
Merge medio
4h 25m
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lanl/PyBNF

Tutte le issue di lanl/PyBNF

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.