Metadata-Version: 2.4
Name: synthpopcan
Version: 0.9.0
Summary: Build, inspect, and validate modelled Canadian households and people for reproducible research.
Project-URL: Homepage, https://github.com/dlq/synthpopcan
Project-URL: Documentation, https://synthpopcan.readthedocs.io/
Project-URL: Source, https://github.com/dlq/synthpopcan
Project-URL: Issues, https://github.com/dlq/synthpopcan/issues
Author-email: Darcy Quesnel <darcy.quesnel@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Darcy Quesnel
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: census,ipf,statistics canada,synthetic population
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.11
Requires-Dist: click>=8.4.1
Requires-Dist: fastapi>=0.141.1
Requires-Dist: numpy>=1.26
Requires-Dist: pandas>=2.0
Requires-Dist: pydantic>=2.12
Requires-Dist: pyshp>=3.1.3
Requires-Dist: rich>=15.0.0
Requires-Dist: uvicorn>=0.52.0
Provides-Extra: model-build
Requires-Dist: scikit-learn>=1.9.0; extra == 'model-build'
Description-Content-Type: text/markdown

# SynthPopCan

[![CI](https://github.com/dlq/synthpopcan/actions/workflows/ci.yml/badge.svg)](https://github.com/dlq/synthpopcan/actions/workflows/ci.yml)
[![Extended correctness](https://github.com/dlq/synthpopcan/actions/workflows/correctness.yml/badge.svg)](https://github.com/dlq/synthpopcan/actions/workflows/correctness.yml)
[![Documentation Status](https://readthedocs.org/projects/synthpopcan/badge/?version=latest)](https://synthpopcan.readthedocs.io/en/latest/)
[![PyPI](https://img.shields.io/pypi/v/synthpopcan.svg)](https://pypi.org/project/synthpopcan/)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21461463.svg)](https://doi.org/10.5281/zenodo.21461463)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

<p align="center">
  <img src="assets/branding/logo/synthpopcan-logo-512.png" alt="SynthPopCan logo" width="220">
</p>

SynthPopCan helps researchers create, inspect, and validate modelled Canadian
households and people from Census-derived data. It supports reproducible work
without requiring researchers to expose private source data or become software
developers first.

SynthPopCan is an independent research-software project. It is not affiliated
with, endorsed by, or sponsored by Statistics Canada or the Government of
Canada.

Near-term goals:

1. Provide a Python library and CLI that can create synthetic populations through IPF from Statistics Canada margin/control tables.
1. Maintain explicit 2016 and 2021 Census microdata workflows for household-
   and person-level synthetic populations using tree-based generation plus
   calibration, while keeping source adapters and metadata appropriately
   census-vintage-specific.
1. Maintain a local web app for configuring runs, inspecting controls, generating from prepared models, validating outputs, and downloading results.

The `0.9.0` line adds bounded methodological evidence and versioned small-area
control packs for the 2016 and 2021 Censuses at CSD, CT, ADA, and DA levels.
It keeps public Census counts separate from reusable control definitions,
requires source and private-household-universe evidence, and reports which
fields were controlled, coarsened, derived, or merely carried through. An
independent calibration oracle, integerization comparison, linked diagnostics,
multi-scale fixtures, and a pinned aggregate Canadian comparison support the
implemented scope without claiming that every model field is locally
representative.

Detailed documentation is published at
<https://synthpopcan.readthedocs.io/>. The source files live under
[`docs/`](docs/); start with [`docs/index.rst`](docs/index.rst) for task-based
navigation to the web app, IPF from StatCan margin tables,
generated-from-model workflows, the beginner Python API, and advanced
microdata/model-training material.

The development branch and the
[`latest` documentation](https://synthpopcan.readthedocs.io/en/latest/) may
describe the next release before it reaches PyPI. The PyPI badge above identifies
what `pip install synthpopcan` currently installs; use the
[`stable` documentation](https://synthpopcan.readthedocs.io/en/stable/) for that
published version. Maintained Can-FED and ODEF adapters are included in `0.7.2`
and later.

Project planning and research notes are tracked separately:

- [`PLANS.md`](PLANS.md): current roadmap, open work, and release sequencing.
- [`adr/`](adr/README.md): accepted architecture decisions, alternatives, and
  consequences.
- [`NOTES.md`](NOTES.md): research synthesis from local materials and external
  literature.
- [`CHANGELOG.md`](CHANGELOG.md): public release notes and completed release
  highlights.
- [`CORRECTNESS.md`](CORRECTNESS.md): tested correctness claims, evidence,
  limitations, and reproducibility commands.

## Quick Start

These commands use a Unix-style shell. Windows readers should first complete
the [WSL setup in the Installation guide](docs/installation.md),
then run the same commands inside the Ubuntu terminal.

Install the published package from PyPI:

**Network required for installation.**

```bash
python3 -m pip install synthpopcan
```

The base installation is enough to generate from portable frequency or CART
models. Starting with `0.7.0`, only researchers training new CART models need
`python3 -m pip install "synthpopcan[model-build]"`.

For a guided first look, start the local browser workbench:

```bash
synthpopcan serve
```

It opens forms, previews, run history, and downloads on this computer only. The
[local web app guide](docs/web-app.md) includes fictional teaching data and
explains what stays on disk. Use the command line below when the work needs to
be scripted or repeated exactly.

Then inspect the command line:

```bash
synthpopcan --help
```

Run a small offline smoke test with the bundled fictional model:

**Runnable teaching example.** Enter both commands in order.

```bash
synthpopcan models generate demo-linked-household-person \
  --households 10 \
  --condition "geo=Demo North" \
  --out synthpopcan-quickstart \
  --random-seed 42
synthpopcan validate linked synthpopcan-quickstart
```

This verifies linked household/person generation, but it does not create a
representative Canadian population. The documentation explains how to choose
research sources, controls, and model packages.

For a one-off command without installing the tool into the current environment,
use `uvx`:

**Network and `uv` required.** See the Installation guide before using this
route if `uvx --version` is not already available.

```bash
uvx synthpopcan --help
uvx synthpopcan guide ipf
uvx synthpopcan guide model
uvx synthpopcan guide small-area
```

From a source checkout for development:

**Source checkout, network, Git, and `uv` required.**

```bash
git clone https://github.com/dlq/synthpopcan.git
cd synthpopcan
uv sync
uv run synthpopcan --help
```

For installation details, see [`docs/installation.md`](docs/installation.md).

## Where To Start

Most readers should start in the Sphinx documentation rather than in this
README:

| Task | Documentation |
| --- | --- |
| Choose a first workflow | [`docs/getting-started.md`](docs/getting-started.md) |
| Start a reproducible command-line workflow | [`docs/command-line.md`](docs/command-line.md) |
| Use the local browser app | [`docs/web-app.md`](docs/web-app.md) |
| Generate with IPF from margin/control tables | [`docs/ipf.md`](docs/ipf.md), [`docs/controls.md`](docs/controls.md), [`docs/statcan.md`](docs/statcan.md) |
| Assign linked households and people to small areas | [`docs/small-area.md`](docs/small-area.md) |
| Fetch verified display-only map boundaries | [`docs/geodata.md`](docs/geodata.md) |
| Attach governed external context as a sidecar layer | [`docs/enrichment.md`](docs/enrichment.md) |
| Hand a validated linked population to another tool | [`docs/exchange.md`](docs/exchange.md) |
| Use the beginner Python API | [`docs/library-getting-started.md`](docs/library-getting-started.md) |
| Work with local data layout and `data doctor` | [`docs/data.md`](docs/data.md) |
| Inspect source files safely | [`docs/data.md`](docs/data.md), [`docs/statcan.md`](docs/statcan.md), [`docs/microdata.md`](docs/microdata.md) |
| Work with census microdata adapters | [`docs/microdata.md`](docs/microdata.md) |
| Train, audit, package, or use tree models | [`docs/tree.md`](docs/tree.md) |
| Validate generated outputs | [`docs/validate.md`](docs/validate.md) |
| Understand correctness evidence and limitations | [`CORRECTNESS.md`](CORRECTNESS.md) |
| Check current plans and implementation notes | [`PLANS.md`](PLANS.md), [`CHANGELOG.md`](CHANGELOG.md) |

Build the documentation locally with:

**Source checkout required.** Contributor setup is documented in
[`CONTRIBUTING.md`](CONTRIBUTING.md).

```bash
uv run sphinx-build -W -b html docs docs/_build/html
```

## Developer Benchmarks

Benchmark fixtures are developer tooling, not normal user workflows:

**Source checkout required.** The province-scale timing run can also require
substantial time and memory.

```bash
uv run python scripts/benchmarks.py ipf
uv run python scripts/benchmarks.py small-area
uv run python scripts/benchmarks.py small-area --province-scale
uv run python scripts/benchmarks.py ipf-backends
```

Use `--seed-records` for smaller or larger IPF runs. The province-scale
small-area timing check is opt-in because it depends on the machine. Optional
SciPy CSR and Polars comparisons remain benchmark probes rather than runtime
backends, and full-data tree-model smoke tests remain outside the default suite.
The CLI, beginner Python API, and local web app call the same Python domain
implementations; IPF also shares its file-backed workflow orchestration.
Browser guidance and durable artifacts do not define a separate computational
tier. Scale limits come from the selected workflow, model, output size, and
available machine resources.

## Data Policy

Large, raw, private, or access-controlled data are not tracked in git.

- `data/raw/` is a local ignored cache for authoritative public inputs,
  organized by provider, product family, and vintage.
- `data/derived/` is a local ignored cache for reproducible conversions,
  subsets, and durable model artifacts; it must not be mistaken for an
  authoritative source.
- `data/work/` is disposable project-local scratch space for model builds,
  experiments, and other restartable intermediate files.
- `data/private/sources/` is a local ignored cache for access-controlled or
  sensitive source datasets; generated artifacts do not belong there.
- `references/` is a local ignored cache for copied papers, proposals, and legacy code references.

Public geography, school, healthcare, road, and environmental layers should generally be fetched from authoritative public sources such as Statistics Canada, open.canada.ca, donneesquebec.ca, and municipal/provincial open-data portals rather than stored in this repository.

Local-only manifests may exist inside ignored data directories to document what is present on a development machine.

## Model Packages

Reviewed model packages may be distributed with the project when they are
explicitly intended as public research artifacts. The installed package should
stay small: only the tiny demo model is bundled. Larger published models are
downloaded on demand with `synthpopcan models fetch MODEL_ID`.

The public catalogue includes parallel 2016 and 2021 linked packages for
Canada, supported provinces, and the five CMAs identified in the hierarchical
PUMF. List the exact IDs with `synthpopcan models list`; for example:

```bash
synthpopcan models fetch quebec-2021-all-fields
synthpopcan models generate quebec-2021-all-fields \
  --households 1000 --out quebec-2021-population/
```

Release assets are gzip-compressed to keep downloads small. The CLI handles
decompression and stores a normal JSON model package in the local cache.

Bundled model packages are not raw Census microdata. They should still be
treated as derived research artifacts with provenance, disclosure-risk checks,
and limitations. A model package being marked as a publishable candidate means
it passed the project's current checks; it is not a claim of official approval,
legal privacy certification, or fitness for every research use.

Before publishing a new model package, review [`docs/data.md`](docs/data.md),
[`docs/tree.md`](docs/tree.md), [`PLANS.md`](PLANS.md), and
[`CONTRIBUTING.md`](CONTRIBUTING.md).

## How To Cite

Releases and prepared model packages are archived on Zenodo, so cite whichever
matches what your work actually depended on.

| You used | Cite | DOI |
| --- | --- | --- |
| SynthPopCan generally | The concept DOI, which always resolves to the newest release | [10.5281/zenodo.21461463](https://doi.org/10.5281/zenodo.21461463) |
| SynthPopCan 0.7.0 | The archived 0.7.0 version DOI | [10.5281/zenodo.21743129](https://doi.org/10.5281/zenodo.21743129) |
| A prepared model package | That package's own DOI, listed on its Zenodo record | one per package |

For reproducibility, prefer the **version** DOI for the release and the model
package DOI for each package you generated from: together they pin the exact
code and the exact artifact, and every model record publishes the checksums
needed to verify the file you downloaded.

Citation metadata lives in [`CITATION.cff`](CITATION.cff), which GitHub renders
as a ready-made citation from the sidebar.

Prepared model packages are derived from Statistics Canada public use microdata
files under the
[Statistics Canada Open Licence](https://www.statcan.gc.ca/en/reference/licence).
Each package carries the attribution notice that licence requires; keep it with
the package and with anything you generate from it. See
[`docs/data.md`](docs/data.md) for the full attribution and licensing terms.

## Development Acknowledgement

Development of SynthPopCan has been supplemented by the use of large language
models for tasks including code generation, review, testing, documentation, and
research assistance. All resulting contributions remain subject to human review
and the project's automated correctness and quality checks. Responsibility for
the project and its releases rests with its maintainer.
