A research-oriented simulator for cortical folding with end-to-end differentiability in JAX.
The project supports:
- Forward simulation (
growth parameters -> folded trajectories). - Inverse optimization (
target morphology -> recovered growth field).
This repository is designed as a high-quality computational mechanics project with:
- Differentiable physics for optimization and learning workflows.
- Config-driven benchmarking and validation gates.
- Reproducibility-focused artifact generation (CSV/JSON summaries, manifests, config hashes).
- Deterministic visualization and reporting pipelines for technical communication.
- Mesh-based mechanics with elastic and bending forces.
- Growth modeling with isotropic and directional controls.
- Constraint handling for skull interaction and self-collision.
- Stable integration with numerical safety rails and fail-fast checks.
- Metric reporting for morphology, curvature, penetration, and runtime.
- Programmatic figure/animation generation and evidence indexing.
| Area | Tools |
|---|---|
| Language | Python 3.11+ |
| Differentiable compute | JAX |
| NN components | Equinox, Optax |
| Numerics | NumPy |
| Visualization | Matplotlib |
| Testing | Pytest |
python3.11 -m pip install -e ".[dev]"python3.11 -m pytest tests -qMPLBACKEND=Agg python3.11 scripts/demo_sphere.py
MPLBACKEND=Agg python3.11 scripts/run_forward.py
MPLBACKEND=Agg python3.11 scripts/train_inverse.py
MPLBACKEND=Agg python3.11 scripts/animate_forward.py --output docs/assets/forward_simulation.gif --rotateMPLBACKEND=Agg python3.11 scripts/run_forward_sweep.py \
--config-path configs/forward_sweep_baseline.json \
--n-steps 200 \
--output-csv results/forward_sweep.csv \
--output-summary results/forward_sweep_summary.json \
--output-manifest results/forward_sweep_manifest.jsonpython3.11 scripts/check_forward_sweep_gates.py \
--input-csv results/forward_sweep.csv \
--input-summary results/forward_sweep_summary.json \
--gate-config configs/validation_gates_default.json \
--output-report results/validation_gate_report.json \
--fail-on-failure./scripts/run_validation_quick.sh
./scripts/run_validation_full.shMPLBACKEND=Agg python3.11 scripts/run_forward_sweep.py \
--mode high_fidelity \
--config-path configs/high_fidelity_forward_sweep.json \
--n-steps 120 \
--output-csv results/high_fidelity/forward_sweep.csv \
--output-summary results/high_fidelity/forward_sweep_summary.json \
--output-manifest results/high_fidelity/forward_sweep_manifest.jsonMPLBACKEND=Agg python3.11 scripts/generate_high_fidelity_publication_render.py \
--config-path configs/high_fidelity_publication_render.json \
--n-steps 180 \
--with-metric-overlays \
--output-gif docs/assets/high_fidelity/baseline_vs_high_fidelity.gif \
--output-mp4 docs/assets/high_fidelity/baseline_vs_high_fidelity.mp4 \
--output-summary results/high_fidelity/baseline_vs_high_fidelity_summary.json \
--output-manifest results/high_fidelity/baseline_vs_high_fidelity_manifest.jsonpython3.11 scripts/validate_high_fidelity.py \
--output-dir results/high_fidelity \
--n-steps 120The repository includes automated packaging and hardened validation workflows in scripts/ that generate publication-style artifacts, reproducibility manifests, and gate reports.
results/forward_sweep.csvresults/forward_sweep_summary.jsonresults/forward_sweep_manifest.jsonresults/validation_gate_report.jsondocs/results_index.mddocs/assets/forward_simulation.gif
| Forward Folding | Growth Field |
|---|---|
![]() |
![]() |
| Inverse Training Loss | Growth Comparison |
|---|---|
![]() |
![]() |
- Deterministic checks are enforced for seeded paths with strict tolerances.
- Validation gates include stability and safety metrics with explicit thresholds.
- Runtime-budget and regression checks are tracked in machine-readable reports.
- Output manifests map metrics and visuals back to configs and source runs.
.
├── src/cortical_folding/
│ ├── mesh.py
│ ├── physics.py
│ ├── constraints.py
│ ├── solver.py
│ ├── growth_net.py
│ ├── losses.py
│ ├── synthetic.py
│ └── viz.py
├── scripts/
├── tests/
├── configs/
├── docs/
└── results/
Current automated tests cover:
- Mesh and geometry operations.
- Physics and solver behavior.
- Validation and reproducibility utilities.
- Pipeline and manifest generation scripts.
Run:
python3.11 -m pytest tests -qOptional negative smoke test (expected failure path):
python3.11 scripts/check_forward_sweep_gates.py \
--input-csv results/forward_sweep.csv \
--input-summary results/forward_sweep_summary.json \
--gate-config configs/validation_gates_failcase.json \
--output-report results/validation_gate_report_failcase.json \
--fail-on-failure- This is a research and engineering prototype for computational modeling.
- Results are synthetic-data validated and reproducibility-focused.
- The project is not a clinical diagnostic tool.
- Nie, J., Li, G., and Shen, D. (2010). A computational model of cerebral cortex folding. Journal of Theoretical Biology.
- Tallinen, T. et al. (2014). Gyrification from constrained cortical expansion. PNAS.
- Budday, S. et al. (2014). A mechanical model predicts morphological abnormalities in the developing human brain. Scientific Reports.
If you use this repository, cite it as software and include a commit hash.
@software{cortical_folding_sim,
title = {Differentiable Cortical Folding Simulator},
author = {Sakeeb and Contributors},
year = {2026},
url = {https://github.com/Sakeeb91/cortical-folding-sim},
note = {Commit: <insert-commit-hash>}
}



