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.12.tar.gz (24.9 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.12-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.8 kB view details)

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

hallmodel-2026.6.19.12-cp314-cp314-macosx_11_0_arm64.whl (137.9 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

hallmodel-2026.6.19.12-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.8 kB view details)

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

hallmodel-2026.6.19.12-cp313-cp313-macosx_11_0_arm64.whl (138.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.12-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.7 kB view details)

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

hallmodel-2026.6.19.12-cp312-cp312-macosx_11_0_arm64.whl (138.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.12-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (160.8 kB view details)

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

hallmodel-2026.6.19.12-cp311-cp311-macosx_11_0_arm64.whl (135.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.12-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (160.0 kB view details)

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

hallmodel-2026.6.19.12-cp310-cp310-macosx_11_0_arm64.whl (134.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: hallmodel-2026.6.19.12.tar.gz
  • Upload date:
  • Size: 24.9 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.12.tar.gz
Algorithm Hash digest
SHA256 a16f328ee6ea124cf206eec0c4047da7ac64e8ffc3d4f467871f39c95b206f67
MD5 df75d9d3b7b96af0ef1e32023e36bb1b
BLAKE2b-256 54bd5712c4d97d5c85602e4c0865da231b96579007cc1cd78ea3f3bed1c5fc62

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12.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.12-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f864c6e198939fa0eb95f6afbebfafe3d4608e07e3c856d6b1b8782ad119a89
MD5 52ba4dcb47de9b0d2409461042f0d65b
BLAKE2b-256 743f6705c0cc5473d91552bfbe195bfbefa808093de29087060da7767a436a1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-cp314-cp314-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.12-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f8ffe10b275e5c5b456a981a97666a404cc1c76c9645f91857bd3483c74278c
MD5 2730a726cb44afaf230cccdd4f10b616
BLAKE2b-256 b5444daa67601205e757b16a72b2d0d193443f4b22d6bd05bf7de5c902576050

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-cp314-cp314-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.12-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d7c53e905260ac849074d11ed3879299c5214a6bff3b94da9f951f344a24579
MD5 7687598a7629085762a53fc667d473ad
BLAKE2b-256 2294470b3c8c7bc15cc167c29325689e69e1637dc54430f6ceed3d2a51956e23

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3ca7dc382eaa9f243356a20887bba4a394369dd184c82253d8df5a7bc1180cb
MD5 240e77a866117be9c316c520f15d827c
BLAKE2b-256 c2e6ed39dd6c950be4fc489fe545a88840e7bb47c768ac2ffc043530962b88f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 94a5c4cd84238241968f22e2816abdf70206cc8e940748a99e5d9318cddae43e
MD5 23795fafb38677a725de1ef9de00bc26
BLAKE2b-256 7abcf04bd92f92968b47852db82bc0f2d3f2ab1a096eeaf7ab424cc94d5df2b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d700aef48847e344b6ac2ae55907c182418ff8c3e7ca6f5575fbbca9d89f296
MD5 95e4688d1388349174a19722435f37f4
BLAKE2b-256 dce53ab289a3cb0bfffeed9d0e19c6652964507caf1b7810c530ad653e56fdd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54174b9c15e66af530ff800eb40af16584811662bf6d475607f0bec5e522bded
MD5 04544199491276425eaf0c2fb9474442
BLAKE2b-256 2920aed50a118bc3bf0488f5877be763988658e189094c5973c166915a007c2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2e052f66351b1d3d1dcd522125a6ca01ab82b8a1a6cd2831ef5529329f2bd3a
MD5 d195b5314470f81ee1f021ed9d6beba9
BLAKE2b-256 b7e7cdf9042e82c7217a96b31f9fbbd14f61fc2e90c234c06065b9c88f9b2e98

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 142a4d922f3e975fa5c82ea713ff3119c3d33b8e3f56d411c70aad6379b1f3af
MD5 510d0d143ec6121cdb74464e7db8c81e
BLAKE2b-256 940f485b0702e5046bb35769bbe710acf2ce000585b99e1f7609cd254b4efb72

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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.12-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c8191608c72f5b36f0c2186837df4d90905509d08694a6bb118821d29796ec37
MD5 b926c9648bb7baf55d4e348059e3398d
BLAKE2b-256 93ef7ab6e29f582367ac665726c608e74232be989b740cd1d1afe1a43890e4ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.12-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