telescopic.engine

The engine: replicates of coupled chains, run in lockstep lanes with refill.

Classes

Replicates

The outputs of a set of replicates, sorted by replicate index, and their run's settings.

Settings

The settings of a run.

Status

The progress of a run, given to its monitor after every iteration.

telescopic.engine.check_settings(settings)

Check the settings of a run and return them with Python integers.

They need integers \(0 \le k \le m\), \(L \ge 1\) and thin \(\ge 1\), and an integer max_iter above \(\max(L, m)\) or None, at most \(2^{31} - 1\) when the run stores the times of its atoms, and keep None or an integer \(\ge 0\), only with store. NumPy integers become int.

Parameters:
settingsSettings

The settings to check.

Returns:
Settings
Raises:
TypeError

If a setting is not an integer.

ValueError

If the settings break a bound.

telescopic.engine.merge(parts)

Join the outputs of disjoint sets of replicates of one run, sorted by replicate index.

The parts must share the root seed, the settings and the dimension; the requested and the abandoned indices are the unions of theirs. For a target evaluated point by point the result is bitwise that of one run of all the replicates; for a vectorized one it can differ from it as a run with other lanes does (run()).

Parameters:
partssequence of Replicates

The outputs to join, at least one.

Returns:
Replicates
telescopic.engine.run(
target,
kernel,
initial,
indices,
*,
k,
m,
lag,
thin=1,
max_iter=None,
rng=None,
lanes=256,
store=True,
keep=None,
keep_paths=False,
monitor=None,
)

Run the replicates indices of the estimator \(H_S\).

Each replicate draws \(X_0\) and then \(Y_0\) from initial with its own stream, runs \(X\) alone for lag steps, then the coupled kernel until \(X_t = Y_{t-L}\) under ==, then \(X\) alone until \(t = m\). For a log-density evaluated point by point, a replicate’s output depends only on the root seed, its index and the arguments, bitwise, never on the other replicates or on lanes. For a vectorized one the kernels compute their products with BLAS, whose rounding can depend on the replicates beside it and on the number of BLAS threads: the output repeats bitwise with the same arguments, lanes, BLAS build and number of BLAS threads, and otherwise a replicate can differ by rounding, which can move its meeting time and its whole output, while the estimates agree within their error bars (Reproducibility, in Run in parallel). The engine emits no warning: it records what its caller needs to warn about.

Parameters:
targetTarget

The target to sample.

kernelKernel

A tuned kernel.

initial

An object with rvs(random_state=generator), a callable initial(rng) or an array of points of shape (n, d), as for telescopic.initial.as_initial().

indicesarray_like of int, shape (R,)

Distinct replicate indices, at least one, started in this order.

k, mint

First and last averaged times, \(0 \le k \le m\).

lagint

The lag \(L \ge 1\).

thinint

Average every thin-th time from k.

max_iterint, optional

Censor a pair still unmet when \(t\) reaches max_iter, which must exceed max(lag, m). None runs every pair until it meets.

rngNone, int, numpy.random.SeedSequence or numpy.random.Generator

The root seed, recorded in the output. Runs of other indices with the same SeedSequence or integer can be merged.

lanesint

Number of replicates advanced together, at most the number requested.

storebool

Whether to store the signed measures and distances; meeting-time pilots do not.

keepint, optional

With store: store the signed measures, their times and the distances of the replicates of index below keep only, and the moments of every replicate (center and moments of Replicates), at a cost of \(O(p)\) per atom with \(p = d(d + 3)/2\) up to \(d = 100\) and \(2d\) above it. None stores the signed measures and distances of every replicate, and no moments.

keep_pathsbool

Whether to keep the paths of both chains, for inspection.

monitorcallable(), optional

Called with a Status after every iteration. Once it returns true, no new replicate starts and the ones in progress finish, so the finished indices are those started.

Returns:
Replicates
Raises:
Exception

An error raised while the replicates run, such as one of the log-density, is raised again as the same object once the replicates finished before it are recorded: its attribute telescopic_replicates holds them, a Replicates whose abandoned lists the replicates in progress, or None when no record could be made, and one note says so. An exception object raised in several runs carries the attribute and the note of the last of them.

Notes

Memory: stored_bytes() gives the size of the stored atoms and distances.

telescopic.engine.stored_bytes(settings, ndim, coupled)

Bytes of the atoms, distances and moments that replicates store.

A replicate that met after \(c = \tau - L\) coupled steps stores the \(|S|\) atoms of the time average and two atoms for each of the \(\max(0, c - k)\) terms of the bias correction, each of \(8d + 20\) bytes (its coordinates in atoms, its weight, its replicate in owner and its time), and \(c\) distances of 24 bytes (distance_owner, distance_time and distance). This is exact when thin is 1 and \(m - k + 1 \ge L\), and an upper bound otherwise, where some terms of the correction have no atoms. With store=False nothing is stored. With keep, only the first keep replicates store atoms and distances, and every replicate stores its moments, \(8(p + d)\) bytes (center and moments of Replicates), with \(p = d(d + 3)/2\) up to \(d = 100\) and \(2d\) above.

Parameters:
settingsSettings

The settings of the run.

ndimint

The dimension \(d\).

coupledarray_like of int, shape (R,)

\(\tau - L\) of each replicate, non-negative, in the order of their indices.

Returns:
float

The total over the replicates.