Skip to content

Introduce a cara.monte_carlo subpackage for managing monte carlo simulations

Philip Elson requested to merge pelson/cara:feature/mc_module into master

This is an entirely additive change, since cara already supports vectorised model evaluation. It essentially makes it easy to build a model with many samples in a declarative manner - in that regard, it is simply a sugar coating, but it does allow us to start expressing default values in terms of distributions, rather than single items.

The MC models generated here are created at runtime, which means that it is hard for a static analysis tool such as mypy, as well as for auto-completion in IDEs, to know exactly how to work with these classes. I have another MR that needs some refinement, which will also generate a type stub file for the module to address this, but it is rather complex currently and takes away from the focus of this change.

Using the model looks something like:

import cara.monte_carlo as mc

from cara.monte_carlo.sampleable import Normal


v = mc.Virus(
    Normal(0.5, 5),
    10,
    Normal(0.5, 5),
)
virus = v.build_model(size=50)

The result will be that virus has type cara.models.Virus, with 50 samples of the two distinct Normal distributions.

Further work needed to add the missing sampleable distributions (cc @nimounet, who I think will work on that), but this should be fairly simple and additive.

Merge request reports

Loading