Skip to main content

Python interface to the Hall body-weight dynamics models, backed by the hallmodel-core C++ kernel.

Project description

hallmodel-py

Python interface to the Hall adult- and child- body-weight dynamics models, backed by the C++ kernel in hallmodel-core (vendored here as a git submodule).

The kernel is the same math the R package INSP-RH/bw compiles. Compiled in matched toolchains with -ffp-contract=off, the outputs are byte-for-byte reproducible against the upstream parity contract; under the contract's published tolerance (rtol=1e-9, atol=1e-12), all 18 contract cases pass.

This is the first reference consumer of hallmodel-core — it is also the worked example for "here is how you write a new language binding against the core."


Install

git clone --recurse-submodules <repo-url> hallmodel-py
cd hallmodel-py
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

Build needs a C++17 compiler and pybind11 (declared in pyproject.toml).

If you cloned without --recurse-submodules:

git submodule update --init --recursive

Use

import bw_cpp

# Adult model — single individual, baseline EI from Mifflin-St Jeor
res = bw_cpp.adult_weight(bw=76, ht=1.73, age=36, sex="male")
print(res["Body_Weight"].shape)       # (1, 366)

# Adult with a 500-kcal deficit over 365 days
import numpy as np
res = bw_cpp.adult_weight(
    bw=90, ht=1.80, age=40, sex="male",
    EIchange=np.full((1, 365), -500.0),
)

# Child model — auto FFM/FM/EI defaults from age + sex
res = bw_cpp.child_weight(age=6, sex="male", days=365)

# Energy interpolation
out = bw_cpp.EnergyBuilder().build(
    energy=np.array([[2000, 2200, 1800]]),
    time=np.array([0, 5, 10]),
    method="Linear",
)

See the docstrings in bw_cpp/__init__.py for the full API, and the upstream R wrappers for the semantics of each parameter — they are the same.

Parity proof

./proof/verify.sh builds the binding against the pinned hallmodel-core submodule, drives all 18 contract cases through bw_cpp, and asserts the contract's tolerance via contract/compare.py. Exit 0 = parity holds.

./proof/verify.sh

The committed proof/last_run.log and proof/outputs/ are the frozen evidence of the most recent green run. CI re-runs them on every PR. The pinned submodule sha is the version contract: bumping it triggers a re-verify.

The one excluded field is BMI_Category — the contract's generate.R coerces character matrices through as.numeric(), producing a column of literal "NA" strings in every adult golden. See hallmodel-core/proof/verify.sh for the full explanation.

How this maps to upstream

upstream R here
INSP-RH/bw::adult_weight() bw_cpp.adult_weight()
INSP-RH/bw::child_weight() bw_cpp.child_weight()
INSP-RH/bw::child_reference_EI() bw_cpp.child_reference_EI()
INSP-RH/bw::child_reference_FFMandFM() bw_cpp.child_reference_FFMandFM()
INSP-RH/bw::EnergyBuilder() bw_cpp.EnergyBuilder().build()

Argument names, semantics, and defaults all match INSP-RH/bw's R wrappers because this Python shim was deliberately written as a direct port of those wrappers. The contract gate enforces it.

License

MIT, carried forward from INSP-RH/bw.

Citing

Cite the original bw package and Hall et al.'s underlying papers. See the README of INSP-RH/bw and hallmodel-core/docs/ATTRIBUTION.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hallmodel-2026.6.19.10.tar.gz (22.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hallmodel-2026.6.19.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (162.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

hallmodel-2026.6.19.10-cp313-cp313-macosx_11_0_arm64.whl (137.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (162.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

hallmodel-2026.6.19.10-cp312-cp312-macosx_11_0_arm64.whl (136.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (159.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

hallmodel-2026.6.19.10-cp311-cp311-macosx_11_0_arm64.whl (134.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (158.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

hallmodel-2026.6.19.10-cp310-cp310-macosx_11_0_arm64.whl (133.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file hallmodel-2026.6.19.10.tar.gz.

File metadata

  • Download URL: hallmodel-2026.6.19.10.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hallmodel-2026.6.19.10.tar.gz
Algorithm Hash digest
SHA256 d70b1c5ce39c2dfb3d4ba893d63df1414953426863fa56cc91a9b3b4283bad5e
MD5 b198a5c0a1f2c8bcf15bbf94a192a5cf
BLAKE2b-256 e07c49f667d1f518abd5a71c8923139d21f96bb8b5b2afde1d3365630fa4e41f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10.tar.gz:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b92d16993c3e22a22d5f6ac383c273fe1e3bab7790bbb93656a7120dc6a2b4d0
MD5 3d7acaad8619bd871475501f2a190c35
BLAKE2b-256 d4666a3a37d1420444c9f0bf9caa98e359c1b8f03a27a3d6c2cd8b79ffbadb51

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cdf94fe68e67d7814369873064933d79ea2103356a900c6a259e0179f469122b
MD5 835ccf8f5e1ac4dd73d8166457b1f1e9
BLAKE2b-256 41a2f514005e90f12ee4cb6012a95d685c5662f2571307b63fbd17994ec19dca

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 130ac44ed3e798dc0acd8172639ceb63e60c4c6b634fc210aab767c9f4ea5a0b
MD5 dd426990b29292da7ef2c914bb3313ad
BLAKE2b-256 69bd7e73fc9397e30c2b167f409edb77c9cf5cd9ce51e7399840caeb462afb0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f325be6aa180293cd9e92881be481a8191d19cbf6b90b8186779051d3e5ec395
MD5 92439de4334cfef932c4d49e09a60a5b
BLAKE2b-256 3fb3557e53ba492f49dc3dc0ebc3e60b705522638f433adf52d1b4c60ba0f387

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79d60d7641e433372f2823777cd147b56d61ba8f1e692913c57f57b1d78839f0
MD5 9131796899f00d8a157209e762e82653
BLAKE2b-256 18388a2239dd3b2ac0966fca5f5c58ec4df452cf7b6c300a6249652851abfa14

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 81dd374e933ded238997d100a30f7d4d6c71741001800939ff30ea73460cdbfd
MD5 329751ec35c8abe2c542acbd0322a70f
BLAKE2b-256 74f4310fdcdff1b34c53782e4c5ba90643abc06591bec6384ec22d824d58b038

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 88df4c55e5bca89471f322fbeb78bfad764e89b59e1f79fac56d1aa2a3749e7d
MD5 10e333dff7f38473488a88e25b65815a
BLAKE2b-256 9d88ee5edf2f44a3eb1726d8265c82a10d660b9f784ea30dc644777be165d518

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hallmodel-2026.6.19.10-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 896a853bddc26565d46433922786eee92d192fdadbf7c7e32c0c4c912581bf1c
MD5 246df2fd8087323998bba6071fb16050
BLAKE2b-256 ea0b9994cd48f40653be998de1e63bf0db95f0f0201dfc6f642ffc22ed211dc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.10-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on ChocoTonic/hallmodel-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page