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.9.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.9-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.9-cp313-cp313-macosx_11_0_arm64.whl (136.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.9-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.9-cp312-cp312-macosx_11_0_arm64.whl (136.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.9-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.9-cp311-cp311-macosx_11_0_arm64.whl (134.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.9-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.9-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.9.tar.gz.

File metadata

  • Download URL: hallmodel-2026.6.19.9.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.9.tar.gz
Algorithm Hash digest
SHA256 71dc8834acf0dc5fcfb79c063e94751c875f99e904d3e91be607f5d753f512cb
MD5 508637d6f0994d2c24eee8c5f99d93c0
BLAKE2b-256 4091c60d8472238b9ba15ca4983a1cfc043e535de8a0f458bbaf676081b67297

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c5e8f8d7f631332a07573d376a28f4ea93b07d04a456b7a5d790b53009c8327
MD5 ce0dd83a91f43fc8067bba8cd4fb2ce6
BLAKE2b-256 e070f4743127d4beb317cab31be24bf2155ab4a208545bf97e13d2ccdfdd00b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f0eec5f4804ebe8adf6b6b06d9d8ac4658e369a055302533e378f1f2309917b
MD5 26a302c3eaecff8c54a8145cace2c60f
BLAKE2b-256 2f530da756c78a6d2d40289acbd3f91383935d973b345fd5060fe31e1111bcc8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99cae59852650a8df6e8ab9465b4846a45b73c48e31b0d82da4cfa19adc3c1c2
MD5 b9dbf9899f027bb5a275822d13a54513
BLAKE2b-256 4d8147af086c672c0402b942c928a633fc5451bca7c4f0acd0c069ab29838348

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af65eac1aff108a55907d37c56effefd8458a37888624b198d838dc8f21096b9
MD5 65815157578fb4b8d7956b9156778c18
BLAKE2b-256 0ce3b8e8243b6fa2c91e8ae62a6744c2df9846a9899e29f2fbdd69c2cc0c116b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73598f23d480fe158771e55d0429e21e7fb604ee517d890819bbb09c5e8ad211
MD5 224799370d9940881dfb51fdfb6ce3ef
BLAKE2b-256 6d20061c001ff44768b72a28036b674b3420a74c4b5016c611f1f622063d0d98

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3127f6a89d9f889d1fa3d8cb16084001d9d9b1b77a02acb22de86ec62676ca8
MD5 a85f314214d6b038b6f0b1dbb7bcf077
BLAKE2b-256 adfa540b66485428c643b4eda30487ac48def9fc80bab3c19e5278328b62cff7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 96ebcd8785f8fa23950ff5fd0dd893505d626f845e64de0a7e251209e5a41a6d
MD5 5db9f1d6a32a60f7fe693e4a3e7970cd
BLAKE2b-256 249ef3f99c045141c78b2f11528256a2a8d799fd2d01371d4e28e32d351004a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 946d012e936268d8ab46d730990f36d49f7b7f97c0728a8bd768afbf3051898d
MD5 49b04e1f646c92c7da3be546727f5d64
BLAKE2b-256 65cf3e310f39fdfee1bb6aa7a9fa4c91ed8825273d783a030dbded5b3b15fbda

See more details on using hashes here.

Provenance

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