pytyche.generators.api

v2 data generator — typed output via CalibrationBundle.

Adapts the v1 segment experiment generator (simulation.core) to produce v2 typed contracts. Key differences from v1:

  • converted column is bool (not int).

  • Returns CalibrationBundle(observed, truth) instead of ExperimentData with an untyped ground_truth dict.

  • CalibrationTruth.metric_family is a typed MetricFamily enum — no dependency on v1 get_metric_spec().

  • validate_observed_data() runs before return — fail-closed.

Functions

generate(n_visitors, segments[, metric, ...])

Generate segment-aware experiment data with typed v2 output.

pytyche.generators.api.generate(n_visitors, segments, metric='conversion_rate', seed=42, experiment_id='sim-exp')[source]

Generate segment-aware experiment data with typed v2 output.

Statistical model is identical to v1 generate_segment_experiment: segment assignment via weighted rng.choice, per-segment Bernoulli conversion, per-segment LogNormal revenue for converters. Ground truth is computed analytically from planted parameters.

Parameters:
  • n_visitors (int) – Total visitors, split evenly between control and treatment.

  • segments (dict[str, dict]) – Mapping of segment name to config dict. Each config must have: pct, base_conv, treatment_effect. For revenue_per_visitor: also aov_mu, aov_sigma, and optionally treatment_aov_mu_shift.

  • metric (str) – "conversion_rate" or "revenue_per_visitor".

  • seed (int) – Random seed for reproducibility.

  • experiment_id (str) – Identifier stored on the returned data.

Returns:

(observed, truth) — observed data validated via validate_observed_data before return.

Return type:

CalibrationBundle