Simulation API¶
Runs a model and reads its outputs. Guide: Running Simulations.
Simulation ¶
A Facade for running a simulation from a defined Model.
The engine follows the model: run and engine rebuild it when
model_definition no longer serializes to the JSON the engine was built
from, for example after Model.update_parameters.
Source code in commol/api/simulation.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
Attributes¶
engine
property
¶
The engine for the current model_definition.
It is rebuilt, at step 0, when the model changed since it was built.
Otherwise it is the same object, in the state the last run or
step left it.
simulation_outputs
property
¶
Names of the columns returned by simulation runs.
Methods:¶
__init__ ¶
__init__(model: Model) -> None
Initializes the simulation engine from a Pydantic Model definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
A fully constructed and validated model object, of any kind. None values for parameters/initial conditions if used for calibration. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the structure of the model is not a |
Source code in commol/api/simulation.py
run ¶
run(num_steps: int, *, seed: int | None = None) -> SimulationResults
Runs the simulation from the initial state on its default grid.
Every call starts at position 0 with the current model_definition,
so two calls with the same model, and the same seed for a stochastic
engine, give the same result. To continue a run, call
simulation.engine.step().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_steps
|
int
|
The number of steps: the results hold the positions
|
required |
seed
|
int | None
|
The seed of a stochastic engine, a whole number from 0 to
|
None
|
Returns:
| Type | Description |
|---|---|
SimulationResults
|
One value per position for each output, the positions, the seed of a stochastic run, and the model. |
Raises:
| Type | Description |
|---|---|
InfeasibleStateError
|
If a step leaves an amount below zero; the message names the compartment, the step and the flows out of it. |
ValueError
|
If a parameter or initial condition has no value, or the seed is
not a whole number from 0 to |
RuntimeError
|
If a rate cannot be evaluated or is not a number; the message names the flow and the position. |
Source code in commol/api/simulation.py
run_at ¶
run_at(at: Sequence[float], *, seed: int | None = None) -> SimulationResults
Runs the simulation from the initial state and reports at given positions.
The positions are on the axis, the independent variable of the model. The engine decides which positions its model type reports at: a DifferentialEquations model at any finite, non-negative position, from the dense output of its solver; a DifferenceEquations model only at integer steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
Sequence[float]
|
Sorted, unique positions to report at. |
required |
seed
|
int | None
|
The seed of a stochastic engine; see |
None
|
Returns:
| Type | Description |
|---|---|
SimulationResults
|
One value per position for each output, the positions, the seed of a stochastic run, and the model. |
Raises:
| Type | Description |
|---|---|
InfeasibleStateError
|
If a step leaves an amount below zero; the message names the compartment, the step and the flows out of it. |
ValueError
|
If a parameter or initial condition has no value, the positions are not sorted and unique, or the engine does not report at one of them; the message is the engine's. |
RuntimeError
|
If a rate cannot be evaluated or is not a number; the message names the flow and the position. |
Source code in commol/api/simulation.py
replicates ¶
replicates(count: int, *, seed: int | None = None) -> ReplicateRuns
Replicates of the runs of a stochastic engine.
The returned object has run and run_at, as Simulation, and
they return SimulationReplicates: count runs, each with its own seed,
run in parallel in the engine. Replicate i takes the seed derived
from seed and i (the SplitMix64 of the SplitMix64 of seed
plus i), so two seeds share no replicate, and a replicate gives the
same run however many replicates run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
How many replicates, at least 1. |
required |
seed
|
int | None
|
The seed the replicate seeds derive from, a whole number from 0 to
|
None
|
Returns:
| Type | Description |
|---|---|
ReplicateRuns
|
The runner of the replicates. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the engine is deterministic (every replicate would be equal),
|
Source code in commol/api/simulation.py
outputs_for ¶
Names of the outputs a source id expands into.
The structure of the model groups its outputs by source
(ModelStructure.outputs_by_source): for an aggregate model, by
bin and accumulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
A source id, such as a bin id or an accumulator id. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Output names for that id, in the order the engine reports them. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in commol/api/simulation.py
group_outputs ¶
Group output names by the bin or accumulator they belong to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Iterable[str]
|
Bin and accumulator ids. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Each id mapped to its output names, keeping the order given. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an id is not a bin or accumulator of the model. |
Source code in commol/api/simulation.py
total_series ¶
Sum the given outputs at each position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Mapping[str, Sequence[float]]
|
Simulation results, such as those of |
required |
ids
|
Iterable[str]
|
Bin and accumulator ids, each for all its outputs
( |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
One value per position of |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an id is not a bin, accumulator or output of the model, or an
expected output is missing from |
Source code in commol/api/simulation.py
windowed_totals ¶
windowed_totals(results: SimulationResults, ids: Iterable[str], window: float, at: Iterable[float] | None = None) -> list[float]
Amount the given accumulators gained over each window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
SimulationResults
|
Simulation results, with their positions. |
required |
ids
|
Iterable[str]
|
Accumulator ids, each for all its outputs, and output names, each for itself. Their outputs are summed before windowing. |
required |
window
|
float
|
Length of one window on the axis. |
required |
at
|
Iterable[float] | None
|
Positions at which windows close. Defaults to every complete window of the results. Pass the observation positions to reproduce exactly the values a calibration used. |
None
|
Returns:
| Type | Description |
|---|---|
list[float]
|
One increment per window. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an id is not a bin, accumulator or output of the model, or an
expected output is missing from |
ValueError
|
If |
Source code in commol/api/simulation.py
sample ¶
sample(results: SimulationResults, ids: Iterable[str], at: Iterable[float]) -> list[float]
Value of the given bins and accumulators at each position of at.
A bin holds an amount at a position, so the value is read at that
position, not over the window before it; windowed_totals reads the
gain of an accumulator over a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
SimulationResults
|
Simulation results, with their positions. |
required |
ids
|
Iterable[str]
|
Bin and accumulator ids, each for all its outputs
( |
required |
at
|
Iterable[float]
|
Positions to read, each a position of |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
One value per position in |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an id is not a bin, accumulator or output of the model, or an
expected output is missing from |
ValueError
|
If the results have no value at a position in |
Source code in commol/api/simulation.py
SimulationResults ¶
Bases: ComparedByValue, dict[str, list[float]]
Values of every output at each position on the axis.
A dict from output name to one value per position, so
results["A"], json.dumps(results) and
pandas.DataFrame(results) work as for any mapping. The positions the
values were read at are in :attr:positions.
Two results are equal when their values (a NaN equal to a NaN), their
positions, their seed and their model are (ComparedByValue); a plain
dict is not a result, so it is not equal to one. Results can change,
so they have no hash.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
list[float]
|
Positions on the axis, ascending. |
seed |
int | None
|
The seed of the run of a stochastic engine, which repeats it; None for a deterministic engine, whose runs depend on no seed. |
model |
Model | None
|
The model of the run, which |
Source code in commol/api/results.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
Attributes¶
plot
property
¶
plot: ResultsPlot
The figures of the run: plot.series() and plot.cumulative().
They name each series from model; results with no model draw only
their outputs.
Methods:¶
__init__ ¶
__init__(positions: Iterable[float], values: Mapping[str, Sequence[float]] | None = None, seed: int | None = None, model: Model | None = None) -> None
Results at the given positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Iterable[float]
|
Positions on the axis, ascending. |
required |
values
|
Mapping[str, Sequence[float]] | None
|
One value per position for each output. |
None
|
seed
|
int | None
|
The seed of the run, or None when it depends on no seed. |
None
|
model
|
Model | None
|
The model of the run, or None when no model is known. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an output does not have one value per position. |
Source code in commol/api/results.py
from_rows
classmethod
¶
from_rows(positions: Sequence[float], names: Sequence[str], rows: Sequence[Sequence[float]], seed: int | None = None, model: Model | None = None) -> SimulationResults
Results from one row of output values per position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Sequence[float]
|
Positions on the axis, ascending. |
required |
names
|
Sequence[str]
|
Output names, in the order of each row. |
required |
rows
|
Sequence[Sequence[float]]
|
One row per position. |
required |
seed
|
int | None
|
The seed of the run, or None when it depends on no seed. |
None
|
model
|
Model | None
|
The model of the run, or None when no model is known. |
None
|
Returns:
| Type | Description |
|---|---|
SimulationResults
|
One series per output name. |
Source code in commol/api/results.py
rows ¶
Every output at each position, one row per position.
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
|
Source code in commol/api/results.py
quantities ¶
The quantities of interest of this run, as a Propagation reduces
each of its runs.
The run must hold every position the quantities read: the results of
Simulation.run_at(quantity_schedule(quantities)) hold them all.
Each position is found within 1e-9, as an observation finds its
row (index_at of crates/commol-calibration/src/observation.rs), and
Rust reduces the rows with the code of Propagation, so the values
equal those of a Propagation of a sample of one draw with the
parameters of this run.
On the ODE engine, Simulation.run reports a position that is not a
breakpoint by interpolation, so a value read from it can differ from
that of a run that ends there by about the relative tolerance of the
solver, and PeakPosition can change on a near-tie.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantities
|
Sequence[Quantity]
|
The quantities; a |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
One value per label of the quantities, in their order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there is no quantity, two scalars have one label, a quantity
names an output the results do not have, or the run lacks a
position a quantity reads; the message lists every such position
with its quantity and says to call |
Source code in commol/api/results.py
report ¶
report(positions: Sequence[float], window: float, windows: int, observed_data: Iterable[ObservedDataPoint] = (), accumulators: Iterable[str] = (), prediction_intervals: PredictionIntervals | None = None) -> SimulationReport
Report the observed data, compartment series and accumulators of the run.
The blocks share one window axis, so the observed values, the windowed accumulator increments and the sampled series can be read against each other. Add whatever envelope you need around them, such as a run label, axis labels or summary figures in the terms of your domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Sequence[float]
|
Positions the series and cumulative accumulators are sampled at; each must be a position of the results. |
required |
window
|
float
|
Length of one window on the axis. |
required |
windows
|
int
|
Number of windows on the observed and windowed axes. |
required |
observed_data
|
Iterable[ObservedDataPoint]
|
The calibration targets to report alongside the run. |
()
|
accumulators
|
Iterable[str]
|
Accumulator ids to report; their outputs come from |
()
|
prediction_intervals
|
PredictionIntervals | None
|
Prediction intervals of a conformal method
( |
None
|
Returns:
| Type | Description |
|---|---|
SimulationReport
|
Keys |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the results have no value at a position the report reads, or
they have no |
KeyError
|
If an accumulator is not a bin or accumulator of the model. |
Source code in commol/api/results.py
compared_values ¶
__repr__ ¶
The positions, the seed and the values.
ReplicateRuns ¶
Runs replicates of a stochastic model; Simulation.replicates makes it.
Attributes:
| Name | Type | Description |
|---|---|---|
simulation |
Simulation
|
The simulation whose model the replicates run. |
count |
int
|
How many replicates. |
seed |
int | None
|
The seed the replicate seeds derive from; None draws one at each run,
which the replicates keep ( |
Source code in commol/api/simulation.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
Methods:¶
__init__ ¶
__init__(simulation: Simulation, count: int, seed: int | None) -> None
The replicates of a simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
The simulation whose model the replicates run. |
required |
count
|
int
|
How many replicates. |
required |
seed
|
int | None
|
The seed the replicate seeds derive from; None draws one at each run. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
With the message of the engine, if |
Source code in commol/api/simulation.py
run ¶
run(num_steps: int) -> SimulationReplicates
Every replicate from the initial state, on the default grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_steps
|
int
|
The number of steps: each replicate holds the positions
|
required |
Returns:
| Type | Description |
|---|---|
SimulationReplicates
|
One |
Raises:
| Type | Description |
|---|---|
InfeasibleStateError
|
If a replicate leaves the values the model allows. |
ValueError
|
If a parameter or a value of the model has no value. |
Source code in commol/api/simulation.py
run_at ¶
run_at(at: Sequence[float]) -> SimulationReplicates
Every replicate from the initial state, reported at given positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
Sequence[float]
|
Sorted, unique positions to report at. |
required |
Returns:
| Type | Description |
|---|---|
SimulationReplicates
|
One |
Raises:
| Type | Description |
|---|---|
InfeasibleStateError
|
If a replicate leaves the values the model allows. |
ValueError
|
If a parameter has no value, the positions are not sorted and unique, or the engine does not report at one of them. |
Source code in commol/api/simulation.py
SimulationReplicates ¶
Bases: ComparedByValue, list[SimulationResults]
Replicates of a run of a stochastic engine, one SimulationResults each.
A list of runs at the same positions, each with its own seed:
replicates[i].seed repeats replicate i. The statistics reduce the
replicates position by position, and member_statistics reduces them as
ci_percentiles requires.
Two replicates are equal when their runs, their seed, their positions and
their model are (ComparedByValue); a plain list of the same runs is
not equal to them. They have no hash.
Attributes:
| Name | Type | Description |
|---|---|---|
seed |
int
|
The seed the replicate seeds derive from. |
positions |
list[float]
|
Positions on the axis, shared by every replicate. |
model |
Model | None
|
The model of the replicates, which |
Source code in commol/api/results.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | |
Attributes¶
plot
property
¶
plot: ReplicatesPlot
The figures of the replicates: plot.series(), their mean and band,
and plot.cumulative().
Methods:¶
__init__ ¶
__init__(runs: Iterable[SimulationResults], seed: int, positions: Sequence[float], model: Model | None = None) -> None
Replicates of one run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
Iterable[SimulationResults]
|
One run per replicate, at |
required |
seed
|
int
|
The seed the replicate seeds derive from. |
required |
positions
|
Sequence[float]
|
Positions on the axis, ascending. |
required |
model
|
Model | None
|
The model of the replicates, or None when no model is known. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a run is not at |
Source code in commol/api/results.py
mean ¶
mean() -> SimulationResults
The mean of the replicates at each position, for each output.
Returns:
| Type | Description |
|---|---|
SimulationResults
|
One series of means per output, with no seed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no replicates. |
Source code in commol/api/results.py
quantiles ¶
quantiles(levels: Sequence[float]) -> dict[float, SimulationResults]
Quantiles of the replicates at each position, for each output.
The quantile is the one convention of commol (weighted_quantiles
with equal weights, NumPy's method="hazen").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
levels
|
Sequence[float]
|
Quantile levels, each between 0 and 1, such as |
required |
Returns:
| Type | Description |
|---|---|
dict[float, SimulationResults]
|
The results of each level. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a level is outside |
Source code in commol/api/results.py
quantities ¶
The quantities of interest of each replicate, as
SimulationResults.quantities reads one run.
Each replicate is reduced on its own, with no mean: a summary across
the replicates is a reduction of these values, such as
member_statistics.
A stochastic Propagation gives draw j the seed
draw_seeds[j] and runs its replicate i with the seed replicate
i of Simulation.replicates(count, seed=draw_seeds[j]) takes. So
those replicates, of the model at the values of draw j, give the
quantities of the runs of that draw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantities
|
Sequence[Quantity]
|
The quantities; a |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, float]]
|
One dict per replicate, in seed order, with one value per label of the quantities. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no replicates, there is no quantity, two scalars have one label, a quantity names an output the replicates do not have, or they lack a position a quantity reads. |
Source code in commol/api/results.py
member_statistics ¶
The spread of one output across the replicates, at each position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
An output name. |
required |
confidence_level
|
float
|
Confidence level of the interval, strictly between 0 and 1. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[float]]
|
Keys |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no replicate has the output. |
ValueError
|
If the confidence level is out of range or there are no replicates. |
Source code in commol/api/results.py
report ¶
report(confidence_level: float, positions: Sequence[float], window: float, windows: int, observed_data: Iterable[ObservedDataPoint] = (), accumulators: Iterable[str] = (), prediction_intervals: PredictionIntervals | None = None) -> SimulationReport
Report the replicates as SimulationResults.report reports one run.
Every number becomes a {mean, median, ci_lower, ci_upper, min,
max} block, reduced replicate by replicate; the layout is the one of
the report of a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_level
|
float
|
Confidence level of the reported intervals, strictly between 0 and 1. |
required |
positions
|
Sequence[float]
|
Positions the series and cumulative accumulators are sampled at; each must be a position of the replicates. |
required |
window
|
float
|
Length of one window on the axis. |
required |
windows
|
int
|
Number of windows on the observed and windowed axes. |
required |
observed_data
|
Iterable[ObservedDataPoint]
|
The calibration targets to report alongside the replicates. |
()
|
accumulators
|
Iterable[str]
|
Accumulator ids to report; their outputs come from |
()
|
prediction_intervals
|
PredictionIntervals | None
|
Prediction intervals of a conformal method
( |
None
|
Returns:
| Type | Description |
|---|---|
SimulationReport
|
Keys |
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are no replicates, the confidence level is out of range,
the replicates have no value at a position the report reads, or
they have no |
KeyError
|
If an accumulator is not a bin or accumulator of the model. |
Source code in commol/api/results.py
compared_values ¶
__repr__ ¶
The number of replicates, their seed and their positions.
ODESolver ¶
Bases: BaseModel
Settings of the DifferentialEquations engine.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
Literal['tsit45', 'bdf']
|
|
rtol |
float
|
Relative tolerance of each state component. |
atol |
float
|
Absolute tolerance of each state component, in the unit of the bins. |
Source code in commol/context/engine.py
StochasticEventsSettings ¶
Bases: BaseModel
Settings of the StochasticEvents engine.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
Literal['direct', 'tau_leaping']
|
|
tau |
float | None
|
The length of a leap of |
epsilon |
float
|
How much a propensity may change in one chosen leap, relative to its value. |
tolerance |
float
|
Relative tolerance of the time of an event when a rate reads |
rounding |
Rounding | None
|
How to make whole the initial amounts that are not. None requires whole amounts. |
Source code in commol/context/engine.py
StochasticStepsSettings ¶
Bases: BaseModel
Settings of the StochasticSteps engine.
Attributes:
| Name | Type | Description |
|---|---|---|
rounding |
Rounding | None
|
How to make whole the initial amounts that are not. None requires whole amounts. |
Source code in commol/context/engine.py
InfeasibleStateError
module-attribute
¶
A run left the values its model allows, such as an amount below zero.
A difference-equations step or an impulse that leaves a compartment below
zero raises it. A stochastic engine raises it for a rate it cannot draw, such
as a negative rate, an impulse fraction outside 0 to 1, or an absolute
impulse that is not a whole number. It is a ValueError; a calibration
treats such a run as infeasible.
Windows and positions¶
windowed_totals ¶
windowed_totals(series: Sequence[float], positions: Sequence[float], window: float, at: Iterable[float] | None = None) -> list[float]
Amount a cumulative series gained over each window.
Each value is the series at the end of the window minus the series at its
start, at - window, each found with the tolerance of the axis: the
rule of a windowed observation (window_increments of
crates/commol-calibration/src/observation.rs), so the value is the
prediction a calibration compares an observation against when that
observation sets window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Sequence[float]
|
A cumulative series, one value per position. |
required |
positions
|
Sequence[float]
|
Positions of the series, ascending, such as
|
required |
window
|
float
|
Length of one window on the axis. |
required |
at
|
Iterable[float] | None
|
Positions at which windows close. Defaults to every complete window of
the series ( |
None
|
Returns:
| Type | Description |
|---|---|
list[float]
|
One increment per requested position. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in commol/api/windows.py
sample ¶
Read a series at the given positions.
Compartment counts are instantaneous, so they are read at the position
rather than averaged over the interval leading to it. Each position is
found with the tolerance of the axis, as an observation finds its row
(index_at of crates/commol-calibration/src/observation.rs), so 0.1
+ 0.2 reads the value at 0.3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Sequence[float]
|
One value per position. |
required |
positions
|
Sequence[float]
|
Positions of the series, ascending. |
required |
at
|
Iterable[float]
|
Positions to read. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
One value per position in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a position in |