# kminartz/neuralcpm architecture

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

- Interactive diagram: https://gitdiagram.com/kminartz/neuralcpm
- Repository: https://github.com/kminartz/neuralcpm

## Overview

NeuralCPM implements trainable Cellular Potts Models: researchers configure an experiment, run training against real and sampler-generated states, then generate and analyze simulations. The graph also preserves the repository’s synthetic-data generation and model/sampling layers. Several capabilities are documented or indexed but their implementations were not fully sampled, so uncertain internal links are omitted; README-supported workflows are cited there.

Main entry points: [`sampling/samplers.py`](https://github.com/kminartz/neuralcpm/blob/main/sampling/samplers.py) (MCMC sampler), [`models/models.py`](https://github.com/kminartz/neuralcpm/blob/main/models/models.py) (CPM Hamiltonians), [`configs/config_commons.py`](https://github.com/kminartz/neuralcpm/blob/main/configs/config_commons.py) (Shared configs), [`training/trainer.py`](https://github.com/kminartz/neuralcpm/blob/main/training/trainer.py) (Trainer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Experiment workflow"]
  node_train_entry["Training entry<br/>[train_ebm.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
  node_configs_common["Shared configs<br/>[config_commons.py]"]
  node_config_exp0["Experiment 0<br/>[experiment_0.py]"]
  node_config_exp1["Experiment 1<br/>[experiment_1.py]"]
  node_config_exp2["Experiment 2<br/>[experiment_2.py]"]
  node_evaluation["Sample generation"]
  node_analysis["Experiment analysis"]
  node_utils["CPM utilities<br/>[utils.py]"]
end

subgraph group_models["Energy models"]
  node_model_energy["CPM Hamiltonians<br/>[models.py]"]
  node_model_modules["Neural modules<br/>[modules.py]"]
end

subgraph group_sampling["CPM sampling"]
  node_sampler["MCMC sampler<br/>[samplers.py]"]
  node_initializers["State initializers<br/>[initializers.py]"]
  node_kernels["Transition kernels"]
end

subgraph group_data["Data generation"]
  node_cellsort_data["Cellsort data"]
  node_mnist_data["MNIST data"]
end

node_researcher(("Researcher"))
node_morpheus["Morpheus"]

node_researcher -->|"runs training"| node_train_entry
node_train_entry -->|"starts trainer"| node_trainer
node_trainer -->|"samples states"| node_sampler
node_trainer -->|"initializes model"| node_utils
node_configs_common -->|"configures"| node_config_exp0
node_configs_common -->|"configures"| node_config_exp1
node_configs_common -->|"configures"| node_config_exp2
node_config_exp0 -->|"selects sampler"| node_sampler
node_config_exp1 -->|"selects sampler"| node_sampler
node_config_exp2 -->|"selects sampler"| node_sampler
node_config_exp1 -->|"selects model"| node_model_energy
node_config_exp2 -->|"selects model"| node_model_energy
node_model_energy -->|"uses modules"| node_model_modules
node_sampler -->|"initializes chains"| node_initializers
node_sampler -->|"runs transitions"| node_kernels
node_kernels -->|"evaluates energy"| node_model_energy
node_initializers -->|"builds boundary mask"| node_utils
node_researcher -->|"generates simulations"| node_evaluation
node_evaluation -->|"analyzes results"| node_analysis
node_researcher -->|"generates data"| node_cellsort_data
node_researcher -->|"generates data"| node_mnist_data
node_morpheus -.->|"provides simulation"| node_cellsort_data

click node_train_entry "https://github.com/kminartz/neuralcpm/blob/main/train_ebm.py"
click node_trainer "https://github.com/kminartz/neuralcpm/blob/main/training/trainer.py"
click node_configs_common "https://github.com/kminartz/neuralcpm/blob/main/configs/config_commons.py"
click node_config_exp0 "https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_0.py"
click node_config_exp1 "https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_1.py"
click node_config_exp2 "https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_2.py"
click node_evaluation "https://github.com/kminartz/neuralcpm/blob/main/experiments/generate_samples.py"
click node_analysis "https://github.com/kminartz/neuralcpm/tree/main/experiments"
click node_model_energy "https://github.com/kminartz/neuralcpm/blob/main/models/models.py"
click node_model_modules "https://github.com/kminartz/neuralcpm/blob/main/models/modules.py"
click node_sampler "https://github.com/kminartz/neuralcpm/blob/main/sampling/samplers.py"
click node_initializers "https://github.com/kminartz/neuralcpm/blob/main/sampling/initializers.py"
click node_kernels "https://github.com/kminartz/neuralcpm/blob/main/sampling/transition_kernels.py"
click node_cellsort_data "https://github.com/kminartz/neuralcpm/blob/main/data_generation/generate_data_cellsort.py"
click node_mnist_data "https://github.com/kminartz/neuralcpm/blob/main/data_generation/generate_data_mnist.py"
click node_utils "https://github.com/kminartz/neuralcpm/blob/main/utils.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_train_entry,node_trainer,node_configs_common,node_config_exp0,node_config_exp1,node_config_exp2,node_evaluation,node_analysis,node_utils toneBlue
class node_model_energy,node_model_modules toneAmber
class node_sampler,node_initializers,node_kernels toneMint
class node_cellsort_data,node_mnist_data toneRose
class node_researcher,node_morpheus toneIndigo
```

## Components

### Experiment workflow

- [Training entry](https://github.com/kminartz/neuralcpm/blob/main/train_ebm.py): `train_ebm.py`
- [Trainer](https://github.com/kminartz/neuralcpm/blob/main/training/trainer.py): `training/trainer.py`
- [Shared configs](https://github.com/kminartz/neuralcpm/blob/main/configs/config_commons.py): `configs/config_commons.py`
- [Experiment 0](https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_0.py): `configs/experiment_0.py`
- [Experiment 1](https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_1.py): `configs/experiment_1.py`
- [Experiment 2](https://github.com/kminartz/neuralcpm/blob/main/configs/experiment_2.py): `configs/experiment_2.py`
- [Sample generation](https://github.com/kminartz/neuralcpm/blob/main/experiments/generate_samples.py): `experiments/generate_samples.py`
- [Experiment analysis](https://github.com/kminartz/neuralcpm/tree/main/experiments): `experiments`
- [CPM utilities](https://github.com/kminartz/neuralcpm/blob/main/utils.py): `utils.py`

### Energy models

- [CPM Hamiltonians](https://github.com/kminartz/neuralcpm/blob/main/models/models.py): `models/models.py`
- [Neural modules](https://github.com/kminartz/neuralcpm/blob/main/models/modules.py): `models/modules.py`

### CPM sampling

- [MCMC sampler](https://github.com/kminartz/neuralcpm/blob/main/sampling/samplers.py): `sampling/samplers.py`
- [State initializers](https://github.com/kminartz/neuralcpm/blob/main/sampling/initializers.py): `sampling/initializers.py`
- [Transition kernels](https://github.com/kminartz/neuralcpm/blob/main/sampling/transition_kernels.py): `sampling/transition_kernels.py`

### Data generation

- [Cellsort data](https://github.com/kminartz/neuralcpm/blob/main/data_generation/generate_data_cellsort.py): `data_generation/generate_data_cellsort.py`
- [MNIST data](https://github.com/kminartz/neuralcpm/blob/main/data_generation/generate_data_mnist.py): `data_generation/generate_data_mnist.py`

### Other components

- **Researcher**
- **Morpheus**

## Connections

- Researcher → Training entry: runs training (evidence: `README.md`)
- Training entry → Trainer: starts trainer (evidence: `train_ebm.py`)
- Trainer → MCMC sampler: samples states (evidence: `training/trainer.py`)
- Trainer → CPM utilities: initializes model (evidence: `training/trainer.py`)
- Shared configs → Experiment 0: configures (evidence: `configs/experiment_0.py`)
- Shared configs → Experiment 1: configures (evidence: `configs/experiment_1.py`)
- Shared configs → Experiment 2: configures (evidence: `configs/experiment_2.py`)
- Experiment 0 → MCMC sampler: selects sampler (evidence: `configs/experiment_0.py`)
- Experiment 1 → MCMC sampler: selects sampler (evidence: `configs/experiment_1.py`)
- Experiment 2 → MCMC sampler: selects sampler (evidence: `configs/experiment_2.py`)
- Experiment 1 → CPM Hamiltonians: selects model (evidence: `configs/experiment_1.py`)
- Experiment 2 → CPM Hamiltonians: selects model (evidence: `configs/experiment_2.py`)
- CPM Hamiltonians → Neural modules: uses modules (evidence: `models/models.py`)
- MCMC sampler → State initializers: initializes chains (evidence: `sampling/samplers.py`)
- MCMC sampler → Transition kernels: runs transitions (evidence: `sampling/samplers.py`)
- Transition kernels → CPM Hamiltonians: evaluates energy (evidence: `sampling/transition_kernels.py`)
- State initializers → CPM utilities: builds boundary mask (evidence: `sampling/initializers.py`)
- Researcher → Sample generation: generates simulations (evidence: `README.md`)
- Sample generation → Experiment analysis: analyzes results (evidence: `README.md`)
- Researcher → Cellsort data: generates data (evidence: `README.md`)
- Researcher → MNIST data: generates data (evidence: `README.md`)
- Morpheus → Cellsort data: provides simulation (evidence: `README.md`)
