# uzairakbar/symmetry4causalbounds architecture

> Architecture diagram of the GitHub repository uzairakbar/symmetry4causalbounds, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uzairakbar/symmetry4causalbounds
- Repository: https://github.com/uzairakbar/symmetry4causalbounds

## Overview

#### Purpose and execution
This repository implements experiments for symmetry-constrained causal partial identification: estimating causal-effect bounds by combining structural causal models, data augmentations encoding symmetries, and sensitivity/regression methods. The main batch entry point is `src/main.py`, which reads experiment selection and parameters from `config.yaml`; outputs are intended for `artifacts/`.

#### Experiment orchestration
`src/experiments/generic_runner.py` provides the common execution path, with experiment-specific runners for digit, optical-device, and synthetic simulation settings:
- `src/experiments/do_mnist.py`
- `src/experiments/optical_device.py`
- `src/experiments/simulation.py`

Shared lifecycle/configuration abstractions reside in `src/experiments/base.py` and `src/experiments/configs.py`. These form the boundary between declarative experiment configuration and model/data/method execution.

#### Structural causal environments
The `sem` package defines the data-generating causal environments used to evaluate identification bounds. `src/sem/abstract.py` establishes the common SEM interface; concrete implementations encode domain-specific causal mechanisms:
- `src/sem/do_mnist.py`
- `src/sem/optical_device.py`
- `src/sem/simulation.py`

`src/sem/cmnist.py` supplies a colored-MNIST-style environment. These modules are the source of observational/interventional or simulated causal data consumed downstream.

#### Symmetry and augmentation layer
`src/data_augmentors/abstract.py` defines augmentation behavior that operationalizes domain symmetries. Concrete augmentors align with experimental domains:
- `src/data_augmentors/do_mnist.py`
- `src/data_augmentors/optical_device.py`
- `src/data_augmentors/simulation.py`

This layer sits between raw SEM/domain data and learning methods, producing symmetry-related samples or transformations used to constrain causal partial identification.

#### Causal-bound methods
`src/methods/abstract.py` defines the method contract. The principal implementation appears to be CoPSens, with both standard and JAX-backed variants:
- `src/methods/copsens.py`
- `src/methods/copsens_jax.py`

Regression and sensitivity-model components support fitting and bound computation:
- `src/methods/regression.py`
- `src/methods/sensitivity_models.py`
- `src/methods/nets.py`

The key control flow is experiment runner → SEM/data and augmentation construction → method fitting/optimization → estimated causal bounds and diagnostics.

#### Oracle and evaluation boundary
`src/oracle.py` provides a distinct oracle layer, likely used where ground-truth causal quantities are available from the simulated SEMs. Experiment utilities handle data operations, fitting, metrics, panel construction, and plotting:
- `src/experiments/utils/model_fitting.py`
- `src/experiments/utils/metrics.py`
- `src/experiments/utils/plotting.py`

This separates learned partial-identification outputs from oracle comparison and report generation.

#### Runtime and infrastructure
The project is Python-based, with package/dependency metadata in `pyproject.toml`. It supports local Python environments and containerized execution through `Dockerfile`. PyTorch is a material runtime, while `src/methods/copsens_jax.py` indicates JAX is also used for an alternate computational backend. Docker mounts `data/` and `artifacts/`, preserving datasets and generated figures/results outside the container.

Main entry points: [`src/experiments/generic_runner.py`](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/generic_runner.py) (Generic runner), [`src/methods/copsens.py`](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/copsens.py) (CoPSens), [`src/sem/do_mnist.py`](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/do_mnist.py) (Domain SEMs), [`src/experiments/utils/metrics.py`](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/utils/metrics.py) (Metrics and fitting utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Execution"]
  node_main["Batch entry point<br/>Python CLI<br/>[main.py]"]
  node_config["Experiment config<br/>YAML<br/>[config.yaml]"]
end

subgraph group_experiments["Experiment orchestration"]
  node_base_configs["Lifecycle and configs<br/>experiment abstractions<br/>[base.py]"]
  node_runner["Generic runner<br/>execution pipeline<br/>[generic_runner.py]"]
  node_domain_runners["Domain runners<br/>digit, optical, simulation<br/>[do_mnist.py]"]
end

subgraph group_causal["Causal environments"]
  node_sem_interface["SEM interface<br/>causal environment contract<br/>[abstract.py]"]
  node_domain_sems["Domain SEMs<br/>causal generators<br/>[do_mnist.py]"]
  node_cmnist_sem["Colored-MNIST SEM<br/>causal generator<br/>[cmnist.py]"]
end

subgraph group_learning["Symmetry and bounds"]
  node_augmentor_interface["Augmentation interface<br/>symmetry contract<br/>[abstract.py]"]
  node_domain_augmentors["Domain augmentors<br/>symmetry transforms<br/>[do_mnist.py]"]
  node_method_interface["Method interface<br/>bound method contract<br/>[abstract.py]"]
  node_copsens["CoPSens<br/>causal-bound optimizer<br/>[copsens.py]"]
  node_jax_backend["JAX CoPSens<br/>alternate compute backend<br/>[copsens_jax.py]"]
  node_model_components["Regression and sensitivity models<br/>fitting components<br/>[regression.py]"]
end

subgraph group_evaluation["Evaluation and outputs"]
  node_oracle["Oracle<br/>ground-truth causal quantities<br/>[oracle.py]"]
  node_metrics["Metrics and fitting utilities<br/>evaluation utilities<br/>[metrics.py]"]
  node_plotting["Plots and reports<br/>report generation<br/>[plotting.py]"]
  node_artifacts["Artifacts<br/>results and figures"]
end

node_config -->|"parameters"| node_main
node_main -->|"dispatches"| node_runner
node_main -->|"selects domain"| node_domain_runners
node_base_configs -->|"lifecycle contract"| node_runner
node_domain_runners -->|"uses common path"| node_runner
node_runner -->|"constructs"| node_sem_interface
node_sem_interface -->|"implemented by"| node_domain_sems
node_sem_interface -->|"implemented by"| node_cmnist_sem
node_runner -->|"constructs"| node_augmentor_interface
node_augmentor_interface -->|"implemented by"| node_domain_augmentors
node_domain_sems -->|"raw causal data"| node_domain_augmentors
node_runner -->|"selects method"| node_method_interface
node_method_interface -->|"implemented by"| node_copsens
node_copsens -.->|"alternate backend"| node_jax_backend
node_model_components -->|"regression and sensitivity fitting"| node_copsens
node_domain_augmentors -->|"symmetry samples"| node_copsens
node_domain_sems -->|"causal data"| node_copsens
node_domain_sems -->|"ground truth"| node_oracle
node_copsens -->|"estimated bounds and diagnostics"| node_metrics
node_oracle -->|"comparison targets"| node_metrics
node_metrics -->|"evaluation results"| node_plotting
node_plotting -->|"figures and reports"| node_artifacts
node_metrics -->|"results"| node_artifacts

click node_main "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/main.py"
click node_config "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/config.yaml"
click node_base_configs "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/base.py"
click node_runner "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/generic_runner.py"
click node_domain_runners "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/do_mnist.py"
click node_sem_interface "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/abstract.py"
click node_domain_sems "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/do_mnist.py"
click node_cmnist_sem "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/cmnist.py"
click node_augmentor_interface "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/data_augmentors/abstract.py"
click node_domain_augmentors "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/data_augmentors/do_mnist.py"
click node_method_interface "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/abstract.py"
click node_copsens "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/copsens.py"
click node_jax_backend "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/copsens_jax.py"
click node_model_components "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/regression.py"
click node_oracle "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/oracle.py"
click node_metrics "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/utils/metrics.py"
click node_plotting "https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/utils/plotting.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_config toneBlue
class node_base_configs,node_runner,node_domain_runners toneAmber
class node_sem_interface,node_domain_sems,node_cmnist_sem toneMint
class node_augmentor_interface,node_domain_augmentors,node_method_interface,node_copsens,node_jax_backend,node_model_components toneRose
class node_oracle,node_metrics,node_plotting,node_artifacts toneIndigo
```

## Components

### Execution

- [Batch entry point](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/main.py): Python CLI · Selects and parameterizes experiments. · `src/main.py`
- [Experiment config](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/config.yaml): YAML · `config.yaml`

### Experiment orchestration

- [Lifecycle and configs](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/base.py): experiment abstractions · `src/experiments/base.py`
- [Generic runner](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/generic_runner.py): execution pipeline · Builds domain components and runs the common experiment lifecycle. · `src/experiments/generic_runner.py`
- [Domain runners](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/do_mnist.py): digit, optical, simulation · `src/experiments/do_mnist.py`

### Causal environments

- [SEM interface](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/abstract.py): causal environment contract · `src/sem/abstract.py`
- [Domain SEMs](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/do_mnist.py): causal generators · Generate observational, interventional, or simulated causal data. · `src/sem/do_mnist.py`
- [Colored-MNIST SEM](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/sem/cmnist.py): causal generator · `src/sem/cmnist.py`

### Symmetry and bounds

- [Augmentation interface](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/data_augmentors/abstract.py): symmetry contract · `src/data_augmentors/abstract.py`
- [Domain augmentors](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/data_augmentors/do_mnist.py): symmetry transforms · Produce symmetry-related samples for identification constraints. · `src/data_augmentors/do_mnist.py`
- [Method interface](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/abstract.py): bound method contract · `src/methods/abstract.py`
- [CoPSens](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/copsens.py): causal-bound optimizer · Fits symmetry-constrained partial-identification bounds. · `src/methods/copsens.py`
- [JAX CoPSens](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/copsens_jax.py): alternate compute backend · `src/methods/copsens_jax.py`
- [Regression and sensitivity models](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/methods/regression.py): fitting components · `src/methods/regression.py`

### Evaluation and outputs

- [Oracle](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/oracle.py): ground-truth causal quantities · `src/oracle.py`
- [Metrics and fitting utilities](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/utils/metrics.py): evaluation utilities · `src/experiments/utils/metrics.py`
- [Plots and reports](https://github.com/uzairakbar/symmetry4causalbounds/blob/main/src/experiments/utils/plotting.py): report generation · `src/experiments/utils/plotting.py`
- **Artifacts**: results and figures · Mounted output directory for experiment results.

## Connections

- Experiment config → Batch entry point: parameters
- Batch entry point → Generic runner: dispatches
- Batch entry point → Domain runners: selects domain
- Lifecycle and configs → Generic runner: lifecycle contract
- Domain runners → Generic runner: uses common path
- Generic runner → SEM interface: constructs
- SEM interface → Domain SEMs: implemented by
- SEM interface → Colored-MNIST SEM: implemented by
- Generic runner → Augmentation interface: constructs
- Augmentation interface → Domain augmentors: implemented by
- Domain SEMs → Domain augmentors: raw causal data
- Generic runner → Method interface: selects method
- Method interface → CoPSens: implemented by
- CoPSens → JAX CoPSens: alternate backend
- Regression and sensitivity models → CoPSens: regression and sensitivity fitting
- Domain augmentors → CoPSens: symmetry samples
- Domain SEMs → CoPSens: causal data
- Domain SEMs → Oracle: ground truth
- CoPSens → Metrics and fitting utilities: estimated bounds and diagnostics
- Oracle → Metrics and fitting utilities: comparison targets
- Metrics and fitting utilities → Plots and reports: evaluation results
- Plots and reports → Artifacts: figures and reports
- Metrics and fitting utilities → Artifacts: results
