petab-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. petab_mcp-0.1.0/.gitignore +19 -0
  2. petab_mcp-0.1.0/LICENSE +21 -0
  3. petab_mcp-0.1.0/PKG-INFO +341 -0
  4. petab_mcp-0.1.0/README.md +292 -0
  5. petab_mcp-0.1.0/pyproject.toml +215 -0
  6. petab_mcp-0.1.0/src/petab_mcp/__init__.py +42 -0
  7. petab_mcp-0.1.0/src/petab_mcp/__main__.py +8 -0
  8. petab_mcp-0.1.0/src/petab_mcp/_skills/antimony-authoring/SKILL.md +104 -0
  9. petab_mcp-0.1.0/src/petab_mcp/_skills/independence-audit/SKILL.md +72 -0
  10. petab_mcp-0.1.0/src/petab_mcp/_skills/petab-model-building/SKILL.md +109 -0
  11. petab_mcp-0.1.0/src/petab_mcp/_skills/reading-fits/SKILL.md +106 -0
  12. petab_mcp-0.1.0/src/petab_mcp/_skills/statements-grammar/SKILL.md +133 -0
  13. petab_mcp-0.1.0/src/petab_mcp/antimony_guard.py +73 -0
  14. petab_mcp-0.1.0/src/petab_mcp/cli.py +189 -0
  15. petab_mcp-0.1.0/src/petab_mcp/constants.py +340 -0
  16. petab_mcp-0.1.0/src/petab_mcp/constraints.py +872 -0
  17. petab_mcp-0.1.0/src/petab_mcp/criteria.py +262 -0
  18. petab_mcp-0.1.0/src/petab_mcp/dask_engine.py +415 -0
  19. petab_mcp-0.1.0/src/petab_mcp/data_access.py +1961 -0
  20. petab_mcp-0.1.0/src/petab_mcp/dedup.py +280 -0
  21. petab_mcp-0.1.0/src/petab_mcp/engine.py +702 -0
  22. petab_mcp-0.1.0/src/petab_mcp/errors.py +217 -0
  23. petab_mcp-0.1.0/src/petab_mcp/filelock.py +58 -0
  24. petab_mcp-0.1.0/src/petab_mcp/fitting.py +3432 -0
  25. petab_mcp-0.1.0/src/petab_mcp/formatting.py +312 -0
  26. petab_mcp-0.1.0/src/petab_mcp/identifiability.py +1348 -0
  27. petab_mcp-0.1.0/src/petab_mcp/literals.py +341 -0
  28. petab_mcp-0.1.0/src/petab_mcp/logging_setup.py +274 -0
  29. petab_mcp-0.1.0/src/petab_mcp/mechanisms.py +1844 -0
  30. petab_mcp-0.1.0/src/petab_mcp/messages.py +77 -0
  31. petab_mcp-0.1.0/src/petab_mcp/model.py +127 -0
  32. petab_mcp-0.1.0/src/petab_mcp/model_edits.py +1223 -0
  33. petab_mcp-0.1.0/src/petab_mcp/multistart.py +375 -0
  34. petab_mcp-0.1.0/src/petab_mcp/nesting.py +267 -0
  35. petab_mcp-0.1.0/src/petab_mcp/notation.py +711 -0
  36. petab_mcp-0.1.0/src/petab_mcp/operations.py +2921 -0
  37. petab_mcp-0.1.0/src/petab_mcp/parameters.py +420 -0
  38. petab_mcp-0.1.0/src/petab_mcp/pool.py +119 -0
  39. petab_mcp-0.1.0/src/petab_mcp/pool_stress.py +239 -0
  40. petab_mcp-0.1.0/src/petab_mcp/problem.py +539 -0
  41. petab_mcp-0.1.0/src/petab_mcp/problem_sbml.py +1093 -0
  42. petab_mcp-0.1.0/src/petab_mcp/progress_signals.py +115 -0
  43. petab_mcp-0.1.0/src/petab_mcp/protocols.py +166 -0
  44. petab_mcp-0.1.0/src/petab_mcp/provenance.py +516 -0
  45. petab_mcp-0.1.0/src/petab_mcp/reconcile.py +2802 -0
  46. petab_mcp-0.1.0/src/petab_mcp/reduction.py +529 -0
  47. petab_mcp-0.1.0/src/petab_mcp/references.py +206 -0
  48. petab_mcp-0.1.0/src/petab_mcp/regimes.py +804 -0
  49. petab_mcp-0.1.0/src/petab_mcp/regulation.py +1523 -0
  50. petab_mcp-0.1.0/src/petab_mcp/residual_tests.py +609 -0
  51. petab_mcp-0.1.0/src/petab_mcp/schemes.py +923 -0
  52. petab_mcp-0.1.0/src/petab_mcp/seeding.py +73 -0
  53. petab_mcp-0.1.0/src/petab_mcp/server.py +3328 -0
  54. petab_mcp-0.1.0/src/petab_mcp/session.py +2111 -0
  55. petab_mcp-0.1.0/src/petab_mcp/skills.py +262 -0
  56. petab_mcp-0.1.0/src/petab_mcp/statements.py +593 -0
  57. petab_mcp-0.1.0/src/petab_mcp/tracing.py +532 -0
  58. petab_mcp-0.1.0/src/petab_mcp/validation.py +1318 -0
  59. petab_mcp-0.1.0/src/petab_mcp/validation_data.py +1210 -0
  60. petab_mcp-0.1.0/src/petab_mcp/withheld.py +91 -0
  61. petab_mcp-0.1.0/tests/conftest.py +277 -0
  62. petab_mcp-0.1.0/tests/data/regulator_corpus/mechanisms.json +6632 -0
  63. petab_mcp-0.1.0/tests/data/regulator_corpus/rows.json +7274 -0
  64. petab_mcp-0.1.0/tests/data/regulator_corpus/verdicts.json +3212 -0
  65. petab_mcp-0.1.0/tests/data/toy_v1/conditions.tsv +2 -0
  66. petab_mcp-0.1.0/tests/data/toy_v1/conversion_reaction.xml +66 -0
  67. petab_mcp-0.1.0/tests/data/toy_v1/measurements.tsv +7 -0
  68. petab_mcp-0.1.0/tests/data/toy_v1/model.ant +13 -0
  69. petab_mcp-0.1.0/tests/data/toy_v1/observables.tsv +2 -0
  70. petab_mcp-0.1.0/tests/data/toy_v1/parameters.tsv +6 -0
  71. petab_mcp-0.1.0/tests/data/toy_v1/problem.yaml +11 -0
  72. petab_mcp-0.1.0/tests/data/toy_v2/measurements.tsv +7 -0
  73. petab_mcp-0.1.0/tests/data/toy_v2/model.ant +13 -0
  74. petab_mcp-0.1.0/tests/data/toy_v2/observables.tsv +2 -0
  75. petab_mcp-0.1.0/tests/data/toy_v2/parameters.tsv +6 -0
  76. petab_mcp-0.1.0/tests/data/toy_v2/problem.yaml +11 -0
  77. petab_mcp-0.1.0/tests/test_amici_log_rate_limit.py +154 -0
  78. petab_mcp-0.1.0/tests/test_antimony_guard.py +64 -0
  79. petab_mcp-0.1.0/tests/test_build_env.py +115 -0
  80. petab_mcp-0.1.0/tests/test_build_lock.py +306 -0
  81. petab_mcp-0.1.0/tests/test_chi2.py +109 -0
  82. petab_mcp-0.1.0/tests/test_cli.py +140 -0
  83. petab_mcp-0.1.0/tests/test_constraints.py +758 -0
  84. petab_mcp-0.1.0/tests/test_criteria.py +411 -0
  85. petab_mcp-0.1.0/tests/test_dask_engine.py +753 -0
  86. petab_mcp-0.1.0/tests/test_data_access.py +1177 -0
  87. petab_mcp-0.1.0/tests/test_dedup.py +332 -0
  88. petab_mcp-0.1.0/tests/test_dedup_statements.py +102 -0
  89. petab_mcp-0.1.0/tests/test_diagnosis_never_compiles.py +290 -0
  90. petab_mcp-0.1.0/tests/test_disk_full.py +230 -0
  91. petab_mcp-0.1.0/tests/test_early_stop.py +950 -0
  92. petab_mcp-0.1.0/tests/test_effective_parameter_count.py +257 -0
  93. petab_mcp-0.1.0/tests/test_engine.py +638 -0
  94. petab_mcp-0.1.0/tests/test_every_state_catalyst.py +202 -0
  95. petab_mcp-0.1.0/tests/test_filelock.py +115 -0
  96. petab_mcp-0.1.0/tests/test_fit.py +1106 -0
  97. petab_mcp-0.1.0/tests/test_fitting.py +683 -0
  98. petab_mcp-0.1.0/tests/test_fix_pointers.py +137 -0
  99. petab_mcp-0.1.0/tests/test_formatting.py +193 -0
  100. petab_mcp-0.1.0/tests/test_hardcoded_constants.py +324 -0
  101. petab_mcp-0.1.0/tests/test_held_inputs.py +194 -0
  102. petab_mcp-0.1.0/tests/test_identifiability.py +932 -0
  103. petab_mcp-0.1.0/tests/test_logging_setup.py +143 -0
  104. petab_mcp-0.1.0/tests/test_make_changes.py +3369 -0
  105. petab_mcp-0.1.0/tests/test_mechanisms.py +758 -0
  106. petab_mcp-0.1.0/tests/test_model.py +33 -0
  107. petab_mcp-0.1.0/tests/test_model_edits.py +935 -0
  108. petab_mcp-0.1.0/tests/test_multistart.py +822 -0
  109. petab_mcp-0.1.0/tests/test_nesting_advisory.py +476 -0
  110. petab_mcp-0.1.0/tests/test_noise_sigma_advice.py +999 -0
  111. petab_mcp-0.1.0/tests/test_notation.py +254 -0
  112. petab_mcp-0.1.0/tests/test_objective_agreement.py +161 -0
  113. petab_mcp-0.1.0/tests/test_objective_reconciliation.py +132 -0
  114. petab_mcp-0.1.0/tests/test_observation_model_reuse.py +299 -0
  115. petab_mcp-0.1.0/tests/test_operations.py +1239 -0
  116. petab_mcp-0.1.0/tests/test_parameter_change_schema.py +171 -0
  117. petab_mcp-0.1.0/tests/test_parameters.py +140 -0
  118. petab_mcp-0.1.0/tests/test_pin.py +92 -0
  119. petab_mcp-0.1.0/tests/test_pool.py +396 -0
  120. petab_mcp-0.1.0/tests/test_pool_stress.py +61 -0
  121. petab_mcp-0.1.0/tests/test_problem.py +227 -0
  122. petab_mcp-0.1.0/tests/test_problem_sbml.py +998 -0
  123. petab_mcp-0.1.0/tests/test_progress_signals.py +148 -0
  124. petab_mcp-0.1.0/tests/test_protocols.py +99 -0
  125. petab_mcp-0.1.0/tests/test_provenance.py +253 -0
  126. petab_mcp-0.1.0/tests/test_reconcile.py +1198 -0
  127. petab_mcp-0.1.0/tests/test_reduction.py +600 -0
  128. petab_mcp-0.1.0/tests/test_reduction_corpus.py +404 -0
  129. petab_mcp-0.1.0/tests/test_references.py +43 -0
  130. petab_mcp-0.1.0/tests/test_regimes.py +260 -0
  131. petab_mcp-0.1.0/tests/test_regulation.py +1456 -0
  132. petab_mcp-0.1.0/tests/test_regulator_corpus.py +257 -0
  133. petab_mcp-0.1.0/tests/test_replicate_lof.py +1019 -0
  134. petab_mcp-0.1.0/tests/test_residual_tests.py +379 -0
  135. petab_mcp-0.1.0/tests/test_scaling.py +75 -0
  136. petab_mcp-0.1.0/tests/test_schemes.py +539 -0
  137. petab_mcp-0.1.0/tests/test_score_at_nominal.py +187 -0
  138. petab_mcp-0.1.0/tests/test_seed_model.py +450 -0
  139. petab_mcp-0.1.0/tests/test_seeding.py +118 -0
  140. petab_mcp-0.1.0/tests/test_server.py +1295 -0
  141. petab_mcp-0.1.0/tests/test_session.py +186 -0
  142. petab_mcp-0.1.0/tests/test_set_model.py +429 -0
  143. petab_mcp-0.1.0/tests/test_sigma_misfit_signals.py +255 -0
  144. petab_mcp-0.1.0/tests/test_skills.py +277 -0
  145. petab_mcp-0.1.0/tests/test_statements.py +241 -0
  146. petab_mcp-0.1.0/tests/test_tool_output_schema.py +114 -0
  147. petab_mcp-0.1.0/tests/test_undefined_readouts.py +311 -0
  148. petab_mcp-0.1.0/tests/test_validation.py +612 -0
  149. petab_mcp-0.1.0/tests/test_validation_data.py +931 -0
  150. petab_mcp-0.1.0/tests/test_validation_data_transfer.py +670 -0
  151. petab_mcp-0.1.0/tests/test_version_provenance.py +410 -0
  152. petab_mcp-0.1.0/tests/test_warm_starts.py +421 -0
@@ -0,0 +1,19 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .venv/
10
+ venv/
11
+ .DS_Store
12
+
13
+ # AMICI-compiled model output
14
+ *_amici/
15
+ amici_models/
16
+ petab_mcp_amici/
17
+
18
+ # Provenance/version store written next to a problem
19
+ .petab_mcp/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fabian Fröhlich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.5
2
+ Name: petab-mcp
3
+ Version: 0.1.0
4
+ Summary: A local MCP server for interactively editing a PEtab (v2) model/parameters and scoring against fixed data.
5
+ Project-URL: Homepage, https://github.com/frohlich-lab/PEtab-MCP
6
+ Project-URL: Repository, https://github.com/frohlich-lab/PEtab-MCP
7
+ Author: Fabian Fröhlich
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: amici,mcp,parameter-estimation,petab,sbml,systems-biology
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
17
+ Requires-Python: >=3.12
18
+ Requires-Dist: amici>=1.2.0
19
+ Requires-Dist: antimony>=3.2
20
+ Requires-Dist: anyio>=3.1
21
+ Requires-Dist: bionetgen>=0.8.7
22
+ Requires-Dist: cloudpickle
23
+ Requires-Dist: duckdb>=0.9
24
+ Requires-Dist: fastmcp<5,>=4
25
+ Requires-Dist: fides>=0.8.1
26
+ Requires-Dist: h5py>=3
27
+ Requires-Dist: indra<1.25,>=1.24
28
+ Requires-Dist: numpy>=1.23
29
+ Requires-Dist: pandas>=1.5
30
+ Requires-Dist: petab>=0.10.0
31
+ Requires-Dist: pypesto[petab]>=0.8.0
32
+ Requires-Dist: pysb>=1.17
33
+ Requires-Dist: python-dateutil<3
34
+ Requires-Dist: python-libsbml>=5.19
35
+ Requires-Dist: scipy>=1.10
36
+ Requires-Dist: sympy>=1.10
37
+ Provides-Extra: dask
38
+ Requires-Dist: dask-jobqueue>=0.8.5; extra == 'dask'
39
+ Requires-Dist: distributed>=2023.12.0; extra == 'dask'
40
+ Provides-Extra: dev
41
+ Requires-Dist: dask-jobqueue>=0.8.5; extra == 'dev'
42
+ Requires-Dist: distributed>=2023.12.0; extra == 'dev'
43
+ Requires-Dist: mcp<3,>=2.3; extra == 'dev'
44
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
45
+ Requires-Dist: pytest-xdist>=3; extra == 'dev'
46
+ Requires-Dist: pytest>=7; extra == 'dev'
47
+ Requires-Dist: ruff>=0.6; extra == 'dev'
48
+ Description-Content-Type: text/markdown
49
+
50
+ # PEtab MCP
51
+
52
+ [![CI](https://github.com/frohlich-lab/PEtab-MCP/actions/workflows/ci.yml/badge.svg)](https://github.com/frohlich-lab/PEtab-MCP/actions/workflows/ci.yml)
53
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
54
+
55
+ ## Disclaimer
56
+
57
+ Research software under active, rapid and heavy development: **use it at your own risk**. Tool
58
+ names, schemas and agent-facing behaviour change without notice. Its behaviour has been tuned and
59
+ checked on benchmark problems only, and it is not for clinical or regulatory use. It comes
60
+ without warranty of any kind; see the [LICENSE](https://github.com/frohlich-lab/PEtab-MCP/blob/main/LICENSE).
61
+
62
+ ## Overview
63
+
64
+ A local [MCP](https://modelcontextprotocol.io) server that wraps a single
65
+ [PEtab v2](https://petab.readthedocs.io/en/latest/v2/documentation_data_format.html)
66
+ parameter-estimation problem (a PEtab v1 problem is upgraded on load) and turns mechanistic
67
+ model building into a **disciplined, auditable** workflow for LLM agents — the loop behind
68
+ model-building assistants such as [petabgpt](https://github.com/frohlich-lab/petabgpt).
69
+
70
+ Point an agent at a dataset and it proposes and refines a mechanistic model, one justified
71
+ change at a time. The experimental design stays fixed and the model is edited only through
72
+ one constrained tool, so an agent cannot silently rewrite the rules of the problem. Every
73
+ change is **scored** on the spot (fit and simulated), **versioned** (nothing overwritten,
74
+ nothing lost), and **justified** (a rationale attached, optionally checked against PubMed).
75
+ This means that instead of a black box just delivering a model, you get the model and
76
+ inspectable provenance describing how it developed.
77
+
78
+ Simulation/objective use [AMICI](https://github.com/AMICI-dev/AMICI)'s PEtab v2 import,
79
+ optimization uses [pyPESTO](https://github.com/ICB-DCM/pyPESTO) with the
80
+ [Fides](https://github.com/fides-dev/fides) trust-region optimizer. All are **required** —
81
+ fitting is not optional machinery.
82
+
83
+ The agent harness that drives this server — the analyst panel, the judge, the zero-shot
84
+ benchmark examples and the run explorer — lives in
85
+ [frohlich-lab/petab_mcp](https://github.com/frohlich-lab/petab_mcp).
86
+
87
+ ## Install
88
+
89
+ ```bash
90
+ pip install -e . --group pins # installs AMICI + pyPESTO (a C++ toolchain is required)
91
+ ```
92
+
93
+ The `pins` group (pip >= 25.1) adds unreleased commits of pysb and petab, which PyPI refuses as
94
+ dependencies. No released pysb installs beside AMICI, so an install from PyPI names its commit:
95
+
96
+ ```bash
97
+ pip install petab-mcp "pysb @ git+https://github.com/pysb/pysb.git@9fc6bcb118683ad851e0a4d5604abe646f77cae3"
98
+ ```
99
+
100
+ AMICI compiles generated C++ and needs a toolchain: a C++ compiler, CMake, Ninja, and the
101
+ pip `swig` binary on `PATH`. AMICI ships only a source distribution, so it is built on install
102
+ (BLAS comes from the `scipy-openblas64` wheel, or Accelerate on macOS).
103
+
104
+ A model built from statements (`make_changes`' `statements` route, `petab_mcp.problem_sbml`)
105
+ has its rules expanded into reactions by BioNetGen, which the `bionetgen` package ships.
106
+ BioNetGen is a Perl program, so `perl` must be on `PATH`. Without it every statements build is
107
+ refused with `Expanding the statements into reactions failed: [Errno 2] No such file or
108
+ directory: 'perl'`; the Antimony routes do not use it. macOS and most Linux distributions ship
109
+ perl, slim container images do not.
110
+
111
+ ## Run
112
+
113
+ ```bash
114
+ petab-mcp --petab-yaml path/to/problem.yaml
115
+ # --provenance-dir DIR --reference-validation {required,best_effort,off}
116
+ # --build-root DIR --skills-dir DIR
117
+ # --entity-map PATH (make_changes offers the `statements` route in place of the Antimony
118
+ # routes, never both; see src/petab_mcp/seeding.py)
119
+ # --constraints PATH (with --entity-map: causal claims every model must make; see src/petab_mcp/constraints.py)
120
+ # --constraint-updates {off,any} (any: offers set_constraints, which replaces them mid-session)
121
+ # --transport {stdio,sse,streamable-http}
122
+ # --criterion {bic,caic,aic,aicc,hqc,tic} (env PETAB_MCP_CRITERION; default bic)
123
+ # --fit-pool ADDRESS (env PETAB_MCP_FIT_POOL; see "Fitting on SLURM")
124
+ # env PETAB_MCP_FIT_AMICI_N_THREADS=T (AMICI threads per start, default 1; workers x T <= cores; on a pool, job-cpu = processes x T)
125
+ ```
126
+
127
+ Provenance is written to `<problem_dir>/.petab_mcp/` by default and is durable — restarting
128
+ resumes the latest version (a store written by the PEtab v1 server is refused). The server's
129
+ stderr goes to `stderr.log` there, beside `petab_mcp.log` and the fit log `pypesto.log`. A ready toy
130
+ problem lives at `tests/data/toy_v2/`; `tests/data/toy_v1/` is the same problem in v1 form.
131
+
132
+ ## Fitting on SLURM
133
+
134
+ The fits of many servers, a sweep's runs say, share one pool of SLURM workers. `petab-mcp-pool`
135
+ runs the pool as a SLURM job of its own, and a server joins it with `--fit-pool ADDRESS` (or
136
+ `PETAB_MCP_FIT_POOL`). Both need the `dask` extra (`pip install -e '.[dask]' --group pins`).
137
+
138
+ ```bash
139
+ petab-mcp-pool --slurm-max-jobs N --address-file PATH # --port 8786
140
+ petab-mcp --petab-yaml problem.yaml --build-root DIR --fit-pool "$(cat PATH)"
141
+ ```
142
+
143
+ The pool's scheduler listens on `--port` of the pool's node, so a pool restarted there comes back at
144
+ the same address, and the address goes to `--address-file` once it listens. The pool submits N
145
+ worker jobs as it starts and keeps them, idle or not, until it stops, so start it for a sweep and
146
+ stop it after. It does not scale with its queue: dask's `adapt` cancelled each new job before its
147
+ workers could take a batch (#250). On SIGTERM it removes the address file, waits up to 10 min for
148
+ the batches running, then cancels its jobs, failing the fits still waiting. It needs:
149
+
150
+ - **every server inside a SLURM allocation**, never on the login node: a server compiles every model
151
+ itself, and a worker never does;
152
+ - **one `--build-root` on storage the compute nodes share**, the same for every server of the pool,
153
+ not `$TMPDIR`: the workers import the compiled models by the server's path, and read each fit's
154
+ problem from its `fit_problems/`, where the fit leaves it once for all its starts. Servers on two
155
+ nodes building one model wait for each other through a POSIX (`fcntl`) lock there, so the
156
+ storage's locks must hold across nodes, as GPFS's do;
157
+ - **one environment for the pool and its servers**: a start is pickled, so a server refuses a pool
158
+ whose `amici`, `pypesto`, `petab` or `petab-mcp` differs from its own, naming both. After a pin
159
+ bump, restart the pool;
160
+ - **a job of 2 CPUs and 8 GB for the pool itself**: at 1200 workers and 100 servers its scheduler
161
+ used about one core and 1.4 GB (`python -m petab_mcp.pool_stress`, on NEMO);
162
+ - **the worker jobs and the scheduler configured in dask's own config**, not by flags: a YAML file
163
+ in `~/.config/dask/` (or `DASK_*` variables) where the pool runs, for example:
164
+
165
+ ```yaml
166
+ jobqueue:
167
+ slurm:
168
+ queue: <partition>
169
+ cores: 32
170
+ processes: 32 # = cores: one single-threaded worker per core, a core per start
171
+ memory: 64GiB
172
+ walltime: "3-00:00:00" # longer than the pool will run
173
+ death-timeout: 600 # seconds a starting worker waits for the scheduler
174
+ local-directory: $TMPDIR # the node's own scratch
175
+ log-directory: <shared storage>/dask-logs
176
+ distributed:
177
+ scheduler:
178
+ worker-ttl: "10 minutes" # well above the longest heartbeat gap pool_stress reports
179
+ ```
180
+
181
+ A worker job is not replaced when it ends: with several workers to a job, jobqueue never resubmits
182
+ it, and the pool stays smaller. Its running batches are rerun on other workers. So give worker jobs
183
+ a walltime longer than the pool will run, and restart the pool between sweeps. A worker `--lifetime`
184
+ buys nothing: a worker reaching it drops its running batch, as a killed one does. The default
185
+ `death-timeout` of 60 s is too short for a full job's workers to import from shared storage.
186
+
187
+ A dask task runs as many starts as fill `PETAB_MCP_FIT_TASK_SECONDS` (default 270) at the
188
+ 90th-percentile start time of the session's previous fit, or at its per-start cap (by default
189
+ `PETAB_MCP_FIT_PER_START_TIMEOUT`) without one, but no more than spread the fit over the pool's idle
190
+ workers; `PETAB_MCP_FIT_STARTS_PER_TASK` fixes the number instead. A pool lost mid-fit, or a worker
191
+ that cannot import a model, ends the call with `infrastructure_error: fit_pool: `, as a full disk
192
+ does (see "Tools"). How the pool's parts fit together, and what was measured on NEMO, is in
193
+ [docs/fit-pool.md](docs/fit-pool.md).
194
+
195
+ ## Tools
196
+
197
+ `make_changes` is the single tool that changes the model or its parameter search space, and
198
+ it always fits — see its docstring in [`src/petab_mcp/server.py`](src/petab_mcp/server.py),
199
+ and the [`reading-fits`](src/petab_mcp/_skills/reading-fits/SKILL.md) skill for what its
200
+ result's fields mean. Everything else is read-only: problem/model/
201
+ parameter inspection (`describe_problem`, `list_conditions`, `list_experiments`, `get_model`,
202
+ `get_parameters`, ...), fit
203
+ inspection (`get_fit_summary`, `get_fit_diagnosis`, `query_data` — arbitrary SQL over the
204
+ fit via DuckDB), and provenance (`get_provenance`, `list_versions`, `restore_version`, ...).
205
+ A live server also exposes these as MCP resources under `petab://...`. Each submodule of
206
+ [`src/petab_mcp`](src/petab_mcp/) is documented in its own docstrings.
207
+
208
+ A refused call returns a result that says why (`error`, and `error_cause` where the refusal has a
209
+ class). A full disk or exceeded quota (ENOSPC, EDQUOT) is not a refusal: nothing the agent can
210
+ change fixes it, so wherever it strikes (edit, AMICI build, fit, stored result) the call ends as an
211
+ MCP tool error whose text starts with `infrastructure_error: disk_full: `. Any edit it carried is
212
+ undone, and a fit it ends does not count against the identical-fit guard. A client should end the
213
+ run on it and resubmit once the disk has room
214
+ ([`errors.InfrastructureError`](src/petab_mcp/errors.py)).
215
+
216
+ A start still running its session's per-start cap (by default `PETAB_MCP_FIT_PER_START_TIMEOUT`)
217
+ plus 600 s after it could have begun (stuck inside one simulation, where Fides never checks its
218
+ cap) is stopped and scored as a failed start;
219
+ the fit is scored from the rest and reports `n_starts_killed`. A stopped warm start from the
220
+ parent's optimum is rerun once. A fit whose starts stop finishing ends the same way as a full disk,
221
+ as `infrastructure_error: fit_wedged: `, with its workers stopped and nothing scored: when no
222
+ start finishes for a start's cap + 600 s while others wait for a worker, when every start was
223
+ stopped, or when a rerun warm start is stopped again ([`multistart`](src/petab_mcp/multistart.py)).
224
+ Every 5 minutes a running fit logs how many of its starts are done. While a change is being
225
+ fitted, a second `make_changes` on the session waits for nothing: it is refused at once with
226
+ `error_cause: fit_in_progress` (text starting `make_changes: fit_in_progress: `), and the
227
+ running fit's result becomes the next version: `wait_for_fit` waits for it on the server and
228
+ answers with that version's row, or with how far the fit has got. A client that cancels a call (MCP
229
+ `notifications/cancelled`) stops its fit, and the edit is undone. A call that carries a progress
230
+ token gets an MCP progress notification every 30 s while it runs, naming the session's running
231
+ change: its phase (`compiling`, `queued` with none of its starts running, or `running`), the
232
+ seconds spent in it and its starts done, so a client can time a call out on silence instead of on a
233
+ budget.
234
+
235
+ ## Design notes
236
+
237
+ Principles to hold onto when extending this package.
238
+
239
+ - **No free-form editing.** The model is only ever changed through `make_changes`, and every
240
+ change must carry a justification. Don't add a second way to write to the model.
241
+ - **A change and its score never come apart.** `make_changes` always fits and snapshots a
242
+ version — there is no edit without a fit, and no fit without a version.
243
+ - **SBML and PEtab stay consistent automatically.** Reconciliation (new symbols, orphan
244
+ pruning, parametric initial conditions) is the server's job, not the agent's — but a few
245
+ cases (an IC of exactly 0, a condition-table override, an assignment rule, a compound
246
+ expression) are deliberately left untouched because minting there would be wrong, not just
247
+ unnecessary. Read [`src/petab_mcp/reconcile.py`](src/petab_mcp/reconcile.py) before
248
+ "fixing" one of these.
249
+ - **Every operation is versioned and logged.** Provenance under `.petab_mcp/` is append-only
250
+ and durable; extend what a version records rather than bypassing it.
251
+ - **Iteration is cheap; results are not cached.** Structural edits recompile, parameter
252
+ edits don't — but a model an earlier version already fitted (its structure, its bounds, as many
253
+ starts) is refused a wasted refit, never served from a fit-result cache (there isn't one). A
254
+ refit is a `make_changes` without a model route, and a new version.
255
+ - **Fit inspection is SQL, not a growing menu.** A new way to look at a fit should be a
256
+ `query_data` query over the DuckDB tables, not a new bespoke tool.
257
+ - **Comparisons must be valid before they're reported.** A commit that isn't nested in what
258
+ it's compared against is flagged, not silently ranked by score.
259
+ - **One score, named, on one scale.** Models are ranked by a complexity-penalised score of the
260
+ form `2·nll + penalty` — `bic` by default; `caic`, `aic`, `aicc`, `hqc` or `tic` (Takeuchi,
261
+ charging the effective parameter count `k_eff = tr(J·H⁻¹)` the server computes) via
262
+ `--criterion`. Every fit reports every score plus `criterion`/`criterion_value`, and every
263
+ gate — new best, plateau stop, de-dup, merge price, the harness judge — reads that one
264
+ value, so they cannot disagree; canonical BIC is recorded on every run regardless, and
265
+ `result.json` carries the whole table. Named penalties and nothing between them: the fixed
266
+ effect-size thresholds carry over when the penalty is swapped, not when it is scaled. See
267
+ [`src/petab_mcp/criteria.py`](src/petab_mcp/criteria.py) before adding one.
268
+ - **The estimation scale is the server's.** PEtab v2 dropped `parameterScale`, so the server keeps
269
+ the column as an extension of the parameter table and hands it to pyPESTO's v2 importer as its
270
+ `parameter_scales`, which puts AMICI's simulator on it too — every pyPESTO problem is built
271
+ through `fitting.pypesto_problem`, never handed to pyPESTO linear. A problem that states a
272
+ prior is refused at load: the objective is the likelihood the criterion scores.
273
+ - **A statement says everything its rate reads.** On the `statements` route a row's statement is
274
+ the claim and its binding the maths behind it, the two given apart under the row's prefix
275
+ (`statements=["r1: RAF phosphorylates MEK"], bindings={"r1": "two_step kf=k_on"}`), so a rate (a
276
+ written `rate`, a `scheme`) reads only the agents the statement names: its roles, the partners they are written bound or not
277
+ bound to, and the agents it states regulate its rate without taking part, `inhibited_by`,
278
+ `activated_by` or `modulated_by` ("RAF phosphorylates MEK, inhibited by sorafenib"). A scheme
279
+ reads one by its kind, in a rate or as a molecule its rules bind (sorafenib sequestering RAF),
280
+ on sites named after each other, so the complex is the one the partner notation writes
281
+ (`RAF{!sorafenib}`) and the claim stays on the statement. Each is
282
+ recorded as the kind the reaction's rate shows for every value of its names within their
283
+ bounds: inhibited where it never rises with it, activated where it never falls, modulated where
284
+ neither can be shown. That rate is the row's net rate as the model builds it, read off the
285
+ reactions its rules make in the whole model's expansion: the row's own agents, the states other
286
+ rows give them and its bindings, its intermediates steady and its products absent, since where a
287
+ step sits decides which way its own rate moves the reaction. A direction counts where sympy
288
+ proves it and the rate, read at points across its names' ranges, moves no other way; it is
289
+ signed again whenever a row, a binding or a bound changes. A regulator that rate does not change
290
+ with, acting only on a step it cannot see (a product's degradation, a complex coming apart), is
291
+ refused, pointing to that step's own row: a regulator is a claim about its statement's own
292
+ reaction, so each claim keeps one meaning and a causal graph never puts it on another reaction.
293
+ Products stay absent in that rate, so a regulator that acts only with the product present
294
+ (feedback through it, autoregulation, autocatalysis) does not move it either: its refusal names
295
+ the rows that state it, the product stated as a regulator too, or that step on a row of its own
296
+ so.
297
+ Any other claim the maths does not bear out is recorded as what it does show, beside what was
298
+ stated, never refused: the edit reports it and asks the agent to reconsider, and `get_model` and
299
+ the English mark it ("activated by sorafenib (from its rate)")
300
+ ([`statements`](src/petab_mcp/statements.py), [`regulation`](src/petab_mcp/regulation.py)).
301
+ INDRA has no statement about a
302
+ reaction, so a causal graph gets the nearest one it has, wider than the claim
303
+ (`statements.as_indra`: "inhibited by sorafenib" on RAF's step is `Inhibition(sorafenib, RAF)`).
304
+ A condition input the entity map
305
+ does not map to an agent is no agent, so a row's binding may read it (`kf="k*dose"`) and the
306
+ condition table says what it is, unless a seed of an agent at its id alone makes it that agent.
307
+ Which inputs are agents is the problem author's call, made in the entity map, or the modeller's,
308
+ made by such a seed; one mapped either way is read only as the agent it is.
309
+ - **A constraint is a claim the model must make.** A session may start with causal constraints
310
+ (`--constraints`), statements rows without bindings that each end `, directly` (one row's claim
311
+ entails it) or `, indirectly` (the network the rows expand to carries it, with its sign), with
312
+ `not ..., directly` and `X does not affect Y` forbidding what they name; `make_changes` refuses a
313
+ model that breaks one, a parameter edit included, since a bound can turn a regulator. Each claim
314
+ is a row's own, its regulators as their rates record them, so a constraint rests on the maths,
315
+ never on what the agent wrote; `activates` is about the forms the constraints declare active,
316
+ never inferred from the agent's rows. An indirect constraint is traced, as the MSB 2023 paper
317
+ traces a signal: every molecule gets a tag site, and BioNetGen expands the rows' model with the
318
+ subject's molecules tagged and each rule handing a driver's tag to what it changes or makes
319
+ ([`tracing`](src/petab_mcp/tracing.py)). Which way a model moves an object is not decidable from
320
+ its structure once it has feedback, so an indirect constraint holds wherever the trace moves it as
321
+ claimed, whatever else the trace finds: that sign is the fit's to say
322
+ ([`constraints`](src/petab_mcp/constraints.py)). With `--constraint-updates any`,
323
+ `set_constraints` replaces them for whoever drives the session, logged with whether it loosens or
324
+ tightens them; a version a new set breaks keeps the verdicts it was committed under, but is
325
+ flagged, cannot be restored and no longer ranks as the best.
326
+ - **A hardcoded constant is not free.** `k` is the estimated parameters plus every numeric
327
+ literal in the model's math bar a few structural ones (each distinct value once — see
328
+ [`src/petab_mcp/literals.py`](src/petab_mcp/literals.py)), so freezing a fitted value costs
329
+ what estimating it costs and there is no threshold to round past. A genuinely known constant
330
+ ships as a fixed row: the problem author's call, not the agent's.
331
+
332
+ ## Development
333
+
334
+ ```bash
335
+ pip install -e '.[dev]' --group pins # AMICI + pyPESTO are core deps; dev adds pytest + ruff
336
+ pytest # needs the full install (AMICI/pyPESTO are hard deps); PubMed is stubbed
337
+ ```
338
+
339
+ ## License
340
+
341
+ MIT