cosmotron_mcp.tools.inference¶
build_cosmosis_inference ¶
build_cosmosis_inference(session_dir: str, sacc_path: str | None = None, sampler: str | None = None, firecrown_config: str | None = None, priors: dict | None = None, sampler_options: dict | None = None, scale_cuts: dict | None = None, camb_accuracy: str = 'default') -> dict
Assemble a CosmoSIS + Firecrown (YAML-factory) inference config for the session SACC.
PREFER the spec chain — draft_inference_spec → update_inference_spec
→ validate_inference_spec → compile_inference, then
run_inference(config_dir=...). This auto-build path (and
run_inference with config_dir=None, which calls it internally) is
the legacy route: it skips the human spec gate and the deterministic
dry-run.
Resolves (explicit arg › task text) the firecrown factory, the priors, the sampler
(+ hyperparameters), and inference scale cuts (ℓ-ranges → firecrown
data_source.filters; these are INFERENCE-only and never touch the NaMaster
measurement lmax). SAVES the experiment YAML + an HDF5 SACC under
{session_dir}/inference/; writes values.ini (ranged min default max for prior'd
params → SAMPLED, scalar otherwise → FIXED), a priors.ini for gaussian priors, and a
firecrown-only pipeline.ini. sampler defaults to test when none is requested.
δz photo-z shift priors: a task ## nz shifts: block (per-bin
src0: gaussian(0.0, 0.011) lines, or nz_shifts: <two-column file>) is resolved
into pipeline_config.nz_shifts at bootstrap. When present, this ADDS a per-bin
PhotoZShiftFactory to the auto-generated firecrown factory for the named probe(s)
and a <tracer>_delta_z gaussian prior (→ sampled) — the tool owns the YAML/ini,
the model only names the tracer + prior. A user-supplied firecrown config owns its
own systematics and is left untouched. No shifts declared → factory unchanged.
If priors are requested from the literature ("same priors as DESI DR2"), returns
needs_literature and writes NO chain config — the orchestrator must fetch +
human-confirm them first. Config-only — launch with run_inference.
camb_accuracy: "default" (science-grade HMcode2020+feedback) | "fast" (takahashi halofit, coarse k/z) | "linear" (camb linear-only, CCL adds halofit — SUPER fast). The two test profiles are for smoke tests only; pair with sampler="test" or a small n_live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory (must have a SACC data vector). |
required |
sacc_path
|
str | None
|
Explicit SACC path; defaults to the session's
|
None
|
sampler
|
str | None
|
CosmoSIS sampler family token (see the |
None
|
firecrown_config
|
str | None
|
Path to a user-supplied Firecrown YAML config; omit to auto-generate one. |
None
|
priors
|
dict | None
|
Prior specs, e.g. |
None
|
sampler_options
|
dict | None
|
Sampler hyperparameter overrides. |
None
|
scale_cuts
|
dict | None
|
Per-tracer/pair ℓ-range filters, e.g.
|
None
|
camb_accuracy
|
str
|
|
'default'
|
Returns:
| Type | Description |
|---|---|
dict
|
The assembled config paths, or |
dict
|
config written) if priors were requested from the literature and |
dict
|
need human confirmation first. |
Source code in cosmotron_mcp/server.py
4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 | |
run_inference ¶
run_inference(session_dir: str, config_dir: str | None = None, firecrown_config: str | None = None, sampler: str | None = None, priors: dict | None = None, sampler_options: dict | None = None, scale_cuts: dict | None = None, ncores: int | None = None, jobspec: dict | None = None, camb_accuracy: str = 'default') -> dict
Launch a CosmoSIS inference run as a background job; return a job_id immediately.
PREFER passing config_dir=<compiled_dir> from the spec chain
(draft_inference_spec → update_inference_spec → validate_inference_spec
→ compile_inference) — that path carries the human spec gate and the
deterministic dry-run. Omitting config_dir auto-builds one from the
session SACC via the legacy build_cosmosis_inference route, skipping
both.
Resolves/builds the config (from the session SACC if config_dir is omitted), then
submits cosmosis <pipeline.ini> via submit_job — NON-BLOCKING. Poll with
check_job(session_dir, job_id). For a real (non-test) sampler, call
summarise_posterior(session_dir, job_id) once the job is done.
A real sampler runs under mpirun -n ncores (parallel pool). ncores resolves from
the explicit arg › a count in the task ("on N cores") › otherwise needs_cores is
returned (NO job) so the orchestrator ASKS the user — it carries available +
suggested. Surface warning (auto factory); needs_literature likewise means no job
ran. The test sampler runs serially (no MPI, no gate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
config_dir
|
str | None
|
Pre-built inference config directory; omit to build one from the session SACC. |
None
|
firecrown_config
|
str | None
|
Path to a user-supplied Firecrown YAML config;
forwarded to |
None
|
sampler
|
str | None
|
CosmoSIS sampler family token; forwarded when building fresh. |
None
|
priors
|
dict | None
|
Prior specs; forwarded when building fresh. |
None
|
sampler_options
|
dict | None
|
Sampler hyperparameter overrides; forwarded when building fresh. |
None
|
scale_cuts
|
dict | None
|
Per-tracer/pair ℓ-range filters; forwarded when building fresh. |
None
|
ncores
|
int | None
|
MPI core count for a real (non- |
None
|
jobspec
|
dict | None
|
Optional resource dict, forwarded to |
None
|
camb_accuracy
|
str
|
Forwarded to |
'default'
|
Returns:
| Name | Type | Description |
|---|---|---|
Local |
dict
|
``{job_id, status, config_dir, pipeline_ini, run_dir, sampler, |
dict
|
ncores, chain_path, config_source, warning, needs_literature, |
|
dict
|
needs_cores} |
|
dict
|
orchestrator must ask the user how many cores to use. Remote (slurm): |
|
dict
|
|
Source code in cosmotron_mcp/server.py
4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 | |
summarise_posterior ¶
summarise_posterior(session_dir: str, job_id: str, params: list[str] | None = None, param_labels: dict[str, str] | None = None) -> dict
Summarise a finished inference chain: per-parameter constraints + a corner plot.
Reads the chain the sampler wrote (inference/chain.txt), computes mean ± std and
16/50/84th percentiles per SAMPLED parameter, writes
inference/posterior_summary.json, and renders plots/posterior_corner.png
(getdist). Registers both artefacts. The test sampler has no chain → returns
{status: "no_chain"}.
Derived duplicate columns (CosmoSIS appends uppercase copies such as OMEGA_M, SIGMA_8 after the sampled ones) are deduplicated automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
job_id
|
str
|
Job id of the finished (or running) |
required |
params
|
list[str] | None
|
Subset of parameters to show in the corner plot, matched
case-insensitively against the short column name (part after
|
None
|
param_labels
|
dict[str, str] | None
|
Custom LaTeX label overrides keyed by short param
name (case-insensitive), bare LaTeX with no surrounding |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
sampler has no chain → |