Synthetic data (`increment.simulate`)
Generate example data or a logged policy trace without a warehouse. These generators do not certify an analysis method’s assumptions.
Scenario
Section titled “Scenario”ScenarioControls for a synthetic A/B test data generation run.
n_days sets only the timestamp spread of generated events, never
the data volume: conversion and revenue draw at most one event per
unit for the whole window, and the count metric’s mean is fixed
regardless of window length. Compute per-unit totals, not per-day
rates, from the output.
simulate_raw_logs
Section titled “simulate_raw_logs”simulate_raw_logs(scenario)Generate a synthetic raw event log for a full A/B experiment.
Returns a single pa.Table (one row per event) with columns:
unit_id- experimental unit id.ts- event timestamp.event-"exposure","conversion","visit","revenue", (encouragement designs only)"uptake"/"outcome", or (n_segments > 1/covariate_sd > 0)"segment"/"covariate".experiment_id- set on exposure rows, empty elsewhere.group_id-"control"or"treatment".value- numeric metric value (NaN for exposures; the segment index or covariate draw for those two observable rows).
SwitchbackScenario
Section titled “SwitchbackScenario”SwitchbackScenarioSynthetic fixed-horizon switchback panel controls.
Each unit receives an independent CT or TC order in every cycle, unless
shared_schedule is set: then one order is drawn per cycle and every
unit in that cycle realizes it (matching SharedScheduleOrder). The
supported estimand assumes carryover has decayed before admitted steps.
true_carryover_order names the number of post-washout observation
steps that actually still carry treatment contamination (a finite
history), and carryover_amplitude is that contamination’s size.
declared_carryover_order is passed to SwitchbackWindow.carryover_order
by the evaluator. Nonzero contamination remains an assumption violation
when the true order exceeds the declared order. treatment_effect is
the additive effect over all observation steps; evaluation targets its
retained fraction after discarding the declared history.
noise_sd is the per-step treatment-potential error SD; control errors
are zero. Innovations have mean zero and variance one: N(0,1),
(exp(N(0,1))-exp(1/2))/sqrt(exp(1)(exp(1)-1)), or
(Gamma(shape=2,scale=1)-2)/sqrt(2). Independently for each unit, with
probability within_unit_correlation reuse one innovation for every
cycle/period/step; otherwise draw independent innovations. This mixture
preserves the exact declared marginal, with Cov(e_j,e_k)=rhonoise_sd^2
for distinct treatment-potential observations in a unit. Units and order
draws are independent. Treatment loading prevents paired cancellation.
This is exchangeable mixture dependence, not a Gaussian copula.
Noise uses a separate seed stream and consumes no draws when noise_sd=0. Centered unit-period trends and opposite treatment-period effects permit heterogeneity while preserving the mean-unit retained-window target.
simulate_switchback_panel
Section titled “simulate_switchback_panel”simulate_switchback_panel(scenario)Generate a seeded panel under the scenario’s explicit potential-outcome law.
simulate_logged_run
Section titled “simulate_logged_run”simulate_logged_run(logger, n_units, horizon, seed, epsilon, batch_size, reward_effect, context_dependence)Simulate a complete-horizon trace under one batched adaptive logger.
Decisions run time-major: every unit decides at period t (at
START + (t - 1) * PERIOD) before any unit decides at t + 1. A
new policy version is fitted after every batch_size decisions from
the rewards whose boundary (decision_time + REWARD_DELAY) closed
before the next decision; an update after the final decision is skipped.
fixed_random never updates and stays at fixed-random/v1. The
random stream draws, per decision, the context, the action, and the
reward, in that order.
simulate_logged_trace
Section titled “simulate_logged_trace”simulate_logged_trace(logger, n_units, horizon, seed, epsilon, batch_size, reward_effect, context_dependence)The admitted trace from :func:simulate_logged_run with the same arguments.
LoggedRun
Section titled “LoggedRun”LoggedRun(trace, registry, reward_model)A simulated trace with the registry that reproduces its logging law.
RewardModel
Section titled “RewardModel”RewardModelBernoulli reward with mean base[x] + sign[x] * effect * 1[action == "B"].
sign is +1 at x = 0 and -1 at x = 1, so action B
helps in one context and hurts in the other; a context-aware target
policy therefore beats the uniform reference by 0.3 * effect while
a context-blind logger sees the two actions as equivalent on average.
The first context is Bernoulli(context_probability). Later contexts
follow the previous action: P(x_t = 1 | a_{t-1}) = clip(0.5 + 0.5 * context_dependence * 1[a_{t-1} == "B"], 0.05, 0.95), so B pushes
the next context toward x = 1 and A leaves it uniform. With
context_dependence = 0 contexts are independent draws and every
policy value is stationary in t; above zero, later contexts depend
on earlier actions, the context marginal under the target policy
diverges from the logged one from t = 3 on, and only the cumulative
likelihood ratio identifies V_t for t >= 2.
true_policy_value
Section titled “true_policy_value”true_policy_value(policy, reward_model, horizon)Exact V_T(pi) for a policy that reads only x.
The context path is a two-state Markov chain with kernel
K[x, x'] = sum_a pi(a | x) P(x' | a); V_T = (1/T) sum_t sum_x P(x_t = x) sum_a pi(a | x) mu(a, x) with P(x_1) the initial
distribution and P(x_{t+1}) = P(x_t) K. When both
context_dependence = 0 and context_probability = 0.5, every row of
K equals the initial distribution and the value is horizon-invariant.
run_end_to_end
Section titled “run_end_to_end”run_end_to_end(scenario, replications)Run the full increment pipeline on synthetic data across
replications independent Monte Carlo replications.
Returns, for every core metric key and (when the scenario declares
n_segments > 1) every “{metric}:{segment}” breakout key, coherent
attempted/point_estimable/interval_estimable/excluded/failed counts
plus nullable bias/coverage aggregates and their Monte Carlo SE (see
EvalResult); the SRM detection rate across successful
replications; and, when the scenario declares covariate_sd > 0,
the fitted CATE summary — all exercised end-to-end through this one
entry point.
A whole-replication failure (any coded refusal anywhere in that
replication’s pipeline) is caught and counted as failed for every
attempted key rather than aborting the entire run.
EvalResult
Section titled “EvalResult”EvalResultAggregated metrics from a simulation run.
Every per-key numeric aggregate (bias/bias_mcse/
coverage_conditional/coverage_conditional_mcse/
coverage_unconditional/coverage_unconditional_mcse/
set_coverage_conditional/set_coverage_conditional_mcse/
set_coverage_unconditional/set_coverage_unconditional_mcse, and
their breakout_ mirrors) is nullable. None normally means the
underlying population is undefined (e.g. bias with zero finite points,
or conditional coverage with zero available intervals). Bias may also
be None when point_estimable is positive but its finite
point-minus-truth mean is outside the finite float range. Numeric
absence is never NaN or a fake zero.
coverage_unconditional/set_coverage_unconditional count a
missing or failed interval/set as a miss, so they are defined (and may
be exactly 0.0) as soon as at least one replication was attempted.
Every per-key count is a real integer, for each prespecified
evaluation key (a core metric name, or — when the scenario declares
n_segments > 1 — a "{metric}:{segment}" breakout cell):
attempted = point_estimable + set_only + excluded + failed and
interval_estimable <= point_estimable <= attempted and
confidence_set_estimable = interval_estimable + set_only hold for
every key. confidence_set_estimable generalizes
interval_estimable. Point-backed rows normally contribute their own
interval as the confidence set, so set_only is 0. Exact-binomial
risk-ratio sets and rank-projected winsor sets can remain available
without a finite point; set_only counts those rows. They contribute
to confidence-set coverage without contributing to point estimability or
bias.
A whole-replication failure (an uncaught coded refusal anywhere in that
replication’s pipeline) counts as failed for every attempted key,
core and breakout alike — not only the core metrics. A breakout cell
absent from a replication’s own output (as opposed to one the
pipeline explicitly excluded) is still counted, as an explicit
exclusion, never silently dropped from the denominator.
failure_reasons/exclusion_reasons/interval_unavailable_reasons
are per-key {reason_code: count} mappings, so exceptions,
exclusions, and degenerate/unavailable uncertainty stay distinguishable.
run_switchback_end_to_end
Section titled “run_switchback_end_to_end”run_switchback_end_to_end(scenario, replications)Evaluate the qualified unit-t approximation on deterministic switchback data.
Bias and coverage target the treatment effect over the retained steps.
A whole-replication failure (any coded refusal building or analyzing
that replication’s panel) is caught and counted as failed rather
than aborting the entire run.
SwitchbackEvalResult
Section titled “SwitchbackEvalResult”SwitchbackEvalResultMonte Carlo summaries for the qualified unit-t switchback approximation.
Retains one-outcome numeric dictionaries (keyed "outcome", the
switchback panel’s sole metric) for consumer compatibility, with the
same nullable bias/coverage semantics as EvalResult.
attempted/point_estimable/interval_estimable/excluded/
failed are scalar (not per-key dicts) because this evaluator
always scores exactly one outcome.