Skip to content

calibrate

Python reference for nagasim.calibrate.calibrate.

Tune factors until the model reproduces observed targets.

Every target's term is summed into one objective, which nagasim.optimize minimises (the default method), or which rejection ABC uses as its distance (method="abc", see _calibrate_abc).

Parameters:

Name Type Description Default
layout dict or str

The model, or a path to it.

required
targets list

CalibrationTarget objects or dicts: {"kpi", "observed", "weight"?, "tolerance"?}; {"kpi": "entity_log/Throughput Time", "observed_sample": [...]} for a distribution matched by the KS statistic; or SeriesTarget objects ({"series", "data", "weight"?}) for a trajectory.

required
factors list of Factor

What to tune, addressing the model through the same override paths that scenarios use.

required
budget int

Hard cap on replications.

200
replications_per_point int

Replications of each evaluated point.

5
seed int

Seed of replication 0.

0
workers int

Process-pool size.

1
run_length optional

Fall back to the model's own settings.

None
warmup optional

Fall back to the model's own settings.

None
confidence float

Level of the intervals used by the search.

0.95
evaluator optional

The evaluation seam, for a caller or a test that supplies its own. The default builds the optimizer's evaluator with the calibration objective wired in and budget as its cap.

None
on_progress callable

As in nagasim.api.run_model.

None
should_stop callable

As in nagasim.api.run_model.

None
record_logs bool

As in nagasim.api.run_model.

None
log_level str

The level every point runs at (D1395); by default the lowest that records the targets.

None
method ('optimize', 'abc')

"optimize" searches for the best point; "abc" draws a posterior sample by rejection ABC as well (samples, posterior, tolerance).

"optimize"
accept float

ABC only: the share of prior samples accepted, at least 20 of them.

0.05

Returns:

Type Description
CalibrationResult

The fitted factor values and the fit of each target.

See Also

nagasim.optimize.optimize : The search it is built on. nagasim.inputfit.best_fit : Fit one input distribution to a sample.

Examples:

>>> from pathlib import Path
>>> import nagasim
>>> from nagasim.calibrate import calibrate
>>> from nagasim.optimize import Factor
>>> path = Path(nagasim.__file__).parent / "models" / "single_server.json"
>>> factor = Factor(path="blocks.process_1.params.dist_params.rate",
...                 kind="continuous", low=1.1, high=2.0, name="rate")
>>> target = {"kpi": "system/Avg Queue Length", "observed": 2.0}
>>> fit = calibrate(str(path), [target], [factor], budget=12,
...                 replications_per_point=2, run_length=200, warmup=20, seed=0)
>>> type(fit).__name__
'CalibrationResult'