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.6.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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

hallmodel-2026.6.19.6-cp313-cp313-macosx_11_0_arm64.whl (136.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (178.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (176.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (175.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

hallmodel-2026.6.19.6-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.6.tar.gz.

File metadata

  • Download URL: hallmodel-2026.6.19.6.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.6.tar.gz
Algorithm Hash digest
SHA256 de7faf6dcdbf9933cbfdb5528098db4e5e8ab302ae277d88efc0878b09c74c11
MD5 bd77de80c713f51477af592155ea8836
BLAKE2b-256 e64a0722d76f327adda4ea81a3ac6507b27558490b0cbeaf62365d7a310cf90a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6.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.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03e50821365f2819309bc10924b288b26995dafefd7c5f96187d92f26b9abf8f
MD5 97fccc3392b49fb17c11620c37129336
BLAKE2b-256 d2d50d1df796a5c4cd7992dd5111adfe1db465d67bc1dc0e487580bc3d775a34

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_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.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f5b44d45c3da8dc99c434ac2802750c69ff5380fe31172fc25f8413bedecf50
MD5 a171c1110b2d8bbcaa86031e78f020f4
BLAKE2b-256 5baf23f020431650d9d989a04c7347d2bd6021762d81127f5b3287fedce8807a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-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.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c6d36a189c3f6a1fa8fc5d21f40bf715956312bcb1ca3260aa0964c3e8cfb7d
MD5 2af79b4a03be494ac6ed7da09def740c
BLAKE2b-256 60ddfe69bfc9b95d19af41ea8b62b6dc02277c6c0cc919784b85404f883e4c95

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_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.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4390ba654e35b0e0497f978e553f6546d1a40232e989c6243b1a0c6b9ca1b6e5
MD5 bd8601fd0415169d2305cf13cfae2d80
BLAKE2b-256 84928634f370ab99dae0094709dff42ab151ccce62910c4ee7c66f944405caa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-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.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 048854e38bec3fbe968e966dc4460ad57a26201e0afc0e738ec857f4c62b910e
MD5 7921ba804ebca3c880bc7df8879137ca
BLAKE2b-256 28ede330c456b6805d137eb99f596dc0a1972c29c84273f3b78218ffec272ec3

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_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.6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce586b11176fe627c182cb393a00263b4fa5dfbb549a145d5d81c31517adfb18
MD5 fdf5843e84021f3899e78c88cdf46178
BLAKE2b-256 e645c17b8a47337f5a73cdc4259346389224abf083145bed5e01132372a06335

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-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.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 236138d3c379f41a8a2c0ccc7d082d3f6a58fa91e0e3d55acba409a0f88b7dea
MD5 a60c5ad1a8d65baa346db9926f3b68aa
BLAKE2b-256 491fe8a23ffd7c5f94d61942601aa15f86d0bc17840e5587618f7f383c027050

See more details on using hashes here.

Provenance

The following attestation bundles were made for hallmodel-2026.6.19.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_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.6-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hallmodel-2026.6.19.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6f42e75547019755d9e478a9b3f10f6f48ab1b0a8ab21a8662a0a5fbc4b60ce
MD5 98de7d7a6b76cdf77ebd6a09ccf970e6
BLAKE2b-256 7195078291bc9591a22d8285dd23834eb4378db34d17283022fa4ffd1dbf2bae

See more details on using hashes here.

Provenance

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