LoggingΒΆ

Msprime uses the Python logging infrastructure to help debugging complex simulations. Messages at the INFO level are high-level information about the state of the current simulation, such as switches in simulation model, etc. While it is straightforward to set up logging messages using the built-in Python methods, the daiquiri library is a bit more convenient. For example,

import daiquiri
import msprime

daiquiri.setup(level="INFO")
ts = msprime.sim_ancestry(
    10,
    population_size=1000,
    model=[
        msprime.DiscreteTimeWrightFisher(duration=100),
        msprime.StandardCoalescent(),
    ],
    random_seed=1234
)
2021-06-18 13:27:55,637 [2322] INFO     msprime.ancestry: Sampling 10 individuals with ploidy 2 in population 0 (name='pop_0') at time 0
2021-06-18 13:27:55,642 [2322] INFO     msprime.ancestry: Starting replicate 0
2021-06-18 13:27:55,644 [2322] INFO     msprime.ancestry: model[0] {'name': 'dtwf'} started at time=0 nodes=20 edges=0
2021-06-18 13:27:55,645 [2322] INFO     msprime.ancestry: Running model {'name': 'dtwf'} until max time: 100.000000
2021-06-18 13:27:55,647 [2322] INFO     msprime.ancestry: model[1] {'name': 'hudson'} started at time=100 nodes=25 edges=10
2021-06-18 13:27:55,648 [2322] INFO     msprime.ancestry: Running model {'name': 'hudson'} until max time: inf
2021-06-18 13:27:55,649 [2322] INFO     msprime.ancestry: Completed at time=5876.22 nodes=39 edges=38

When running larger simulations and trying to figure out when they might finish, it can be helpful to use the DEBUG logging output. For example:

daiquiri.setup(level="DEBUG")
ts = msprime.sim_ancestry(
    10 ** 5,
    population_size=10000,
    recombination_rate=2e-8,
    sequence_length=1e6,
    random_seed=32
)
2021-06-18 13:27:55,658 [2322] INFO     msprime.ancestry: Sampling 100000 individuals with ploidy 2 in population 0 (name='pop_0') at time 0
2021-06-18 13:27:55,781 [2322] INFO     msprime.ancestry: Starting replicate 0
2021-06-18 13:27:55,790 [2322] INFO     msprime.ancestry: model[0] {'name': 'hudson'} started at time=0 nodes=200000 edges=0
2021-06-18 13:27:55,791 [2322] INFO     msprime.ancestry: Running model {'name': 'hudson'} until max time: inf
2021-06-18 13:27:55,840 [2322] DEBUG    msprime.ancestry: time=0.0104295 ancestors=190080 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:55,874 [2322] DEBUG    msprime.ancestry: time=0.0219435 ancestors=180166 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:55,912 [2322] DEBUG    msprime.ancestry: time=0.0346803 ancestors=170256 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:55,948 [2322] DEBUG    msprime.ancestry: time=0.0491285 ancestors=160336 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:55,986 [2322] DEBUG    msprime.ancestry: time=0.0657941 ancestors=150418 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,026 [2322] DEBUG    msprime.ancestry: time=0.0847891 ancestors=140540 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,067 [2322] DEBUG    msprime.ancestry: time=0.106283 ancestors=130644 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,113 [2322] DEBUG    msprime.ancestry: time=0.131827 ancestors=120740 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,163 [2322] DEBUG    msprime.ancestry: time=0.161742 ancestors=110874 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,218 [2322] DEBUG    msprime.ancestry: time=0.197291 ancestors=101020 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,278 [2322] DEBUG    msprime.ancestry: time=0.240122 ancestors=91192 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,346 [2322] DEBUG    msprime.ancestry: time=0.293227 ancestors=81390 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,422 [2322] DEBUG    msprime.ancestry: time=0.361519 ancestors=71580 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,512 [2322] DEBUG    msprime.ancestry: time=0.45156 ancestors=61818 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,609 [2322] DEBUG    msprime.ancestry: time=0.573763 ancestors=52074 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,719 [2322] DEBUG    msprime.ancestry: time=0.755864 ancestors=42402 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,844 [2322] DEBUG    msprime.ancestry: time=1.03995 ancestors=32814 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:56,984 [2322] DEBUG    msprime.ancestry: time=1.54834 ancestors=23356 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,158 [2322] DEBUG    msprime.ancestry: time=2.72085 ancestors=14190 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,377 [2322] DEBUG    msprime.ancestry: time=7.38436 ancestors=5736 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,542 [2322] DEBUG    msprime.ancestry: time=150.174 ancestors=558 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,566 [2322] DEBUG    msprime.ancestry: time=4639.98 ancestors=154 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,580 [2322] DEBUG    msprime.ancestry: time=17020.3 ancestors=100 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,592 [2322] DEBUG    msprime.ancestry: time=35240.4 ancestors=96 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,601 [2322] DEBUG    msprime.ancestry: time=66125.6 ancestors=62 ret=ExitReason.MAX_EVENTS
2021-06-18 13:27:57,608 [2322] DEBUG    msprime.ancestry: time=192317 ancestors=0 ret=ExitReason.COALESCENCE
2021-06-18 13:27:57,609 [2322] DEBUG    msprime.ancestry: Skipping remaining 0 models
2021-06-18 13:27:57,610 [2322] INFO     msprime.ancestry: Completed at time=192317 nodes=407802 edges=437129

In this example we run a reasonably large simulation and turn on the DEBUG output. This will then periodically (every 10,000 simulation events) print out the current time in the simulation, and the number of extant ancestral lineages.

Warning

The format of these logging messages is not fixed and may change arbitrarily in the future. If you need to obtain the information within them, please open an issue on GitHub so that we can provide a documented API for this.