Skip to main content

dagsampler

PyPI version Python versions License: MIT Documentation

Configurable causal DAG simulator for synthetic mixed-type data and CI test benchmarks.

Documentation · Changelog

What it provides

  • CausalDataGenerator class for configurable simulation
  • Support for custom and random DAGs
  • Mixed continuous/binary/categorical nodes (configurable categorical cardinality)
  • Structural forms: linear, polynomial, interaction, sigmoid, cos, sin, stratum_means
  • Optional element-wise post_transform (tanh, sin, cos, exp_neg_abs, sqrt_abs, relu, sign)
  • Cross-type mechanisms:
    • continuous -> categorical (categorical_model.name = "threshold"), with an opt-in standardized (design-A) threshold mode (threshold_standardized) that discretizes a unit-variance linear-Gaussian latent at equal-probability cutpoints
    • categorical -> continuous (functional_form.name = "stratum_means", including mixed-parent cases with metric_weights)
  • Opt-in spread-controlled softmax/logistic weights (softmax_weight_mode = "spread") for a detectable, balance-preserving logit contrast (default "gaussian" preserves legacy behaviour)
  • Noise models:
    • additive (gaussian, student_t, gamma, exponential, laplace, cauchy, uniform)
    • multiplicative (gaussian, student_t, gamma, exponential)
    • heteroskedastic (abs_first_parent, abs_parent_plus_const, mean_abs_plus_const); base distribution selectable via dist (gaussian default, student_t, laplace, uniform, gamma, exponential)
    • shape / tail-shape (skew_first_parent, skew_tanh_first_parent, skew_mean_parents) — a parent drives the noise skewness with mean and variance held fixed (a higher-moment edge)
  • Random weight sampling controls (including exclusion band around zero)
  • force_uniform_marginals for balanced exogenous binary / categorical draws
  • Template helpers (chain_config, fork_config, collider_config, independence_config)
  • Reproducibility via seed_structure and seed_data (or single seed)
  • Optional d-separation CI oracle output (store_ci_oracle=true)
  • Time-series (stationary SVAR) support with latent confounders: TimeSeriesSpec / random_ts_spec, a lagged d-separation oracle (LaggedDSeparationOracle), and mixed-type simulate_svar (see How-to: time series)

Installation

From PyPI:

pip install dagsampler

Or with uv:

uv venv
source .venv/bin/activate
uv pip install dagsampler

From GitHub (latest main):

uv pip install "dagsampler @ git+https://github.com/averinpa/dagsampler.git"

Quick start (Python API)

from dagsampler import CausalDataGenerator

config = {
    "simulation_params": {"n_samples": 200, "seed": 42},
    "graph_params": {
        "type": "custom",
        "nodes": ["X", "Y", "Z1"],
        "edges": [["X", "Z1"], ["Y", "Z1"]],
    },
}

result = CausalDataGenerator(config).simulate()
data = result["data"]
dag = result["dag"]
params = result["parametrization"]

CLI

The package exposes dagsampler-generate.

dagsampler-generate \
  --config config.json \
  --output dataset.csv \
  --params-out params.json \
  --edges-out edges.json

config.json must contain the same structure used by CausalDataGenerator.

Learn more

Development

uv pip install -e ".[dev]"
pytest -q

Metadata

Release files for dagsampler 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dagsampler 0.5.0
File Size Uploaded Provenance Actions
dagsampler-0.5.0.tar.gz 43.0 kB With provenance Details for dagsampler-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dagsampler 0.5.0
File Interpreter ABI Platform Actions
dagsampler-0.5.0-py3-none-any.whl Python 3 none any Details for dagsampler-0.5.0-py3-none-any.whl

Total release size: 74.0 kB

Release files / dagsampler-0.5.0.tar.gz

Download URL dagsampler-0.5.0.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
556cd88a0d5df2e640616fa8cf5b6883f012fde4bd20334a8ac2279bf3d8d853
BLAKE2b-256 checksum
How to use checksums
8ac89dce1c6f9ef493472dcd7ef11194a36b6ce123e0fa05ef68dffffd703637
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

Release files / dagsampler-0.5.0-py3-none-any.whl

Download URL dagsampler-0.5.0-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
176b84814ae60a70503092f66289f5ab65e0c1f85eefd65f950c3843bd19d6cd
BLAKE2b-256 checksum
How to use checksums
24317153300bc0526fca93be4f526bbcf22daa1ca629936ee7b90b2ed9034016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

Security for dagsampler 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dagsampler-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page