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

未关闭
#1,054 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
26
派生
25
平均合并
4 小时 25 分钟
30 天内合并 PR
9

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lanl/PyBNF 的其他 Issue

查看 lanl/PyBNF 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。