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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: hallmodel-2026.6.19.7.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.7.tar.gz
Algorithm Hash digest
SHA256 81f720e705f3eb36734db073cba048887e664430e1c3b5078a84e9e116646f5a
MD5 12f264e984d7671e27a5998a24a45a65
BLAKE2b-256 10cf76d1e43efc0e0e6e581107b32125a49d3f94c133a064fb31d6ba0e183487

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bc450c0be9b1844e681c5362b9e060af2e7890096c38f1cbd61bae16aaa1819f
MD5 115bf0b6ed71f04c2f26dae21b81924f
BLAKE2b-256 d7cf7f54eb1c90dc8066dfa23307e853479dcc878fe2d8d3238d4878f67ff831

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e721e573d7c848a0885b87c2030cb79ff3dab06d4c133aed96d7fcc03f21705
MD5 c190ec754bb1fdbba9d0edb22a914fe5
BLAKE2b-256 49859d8e8ccdb38d76ff60d7cd3ce42ff257dbc150efcfc034f081eec7d5df7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1abd5fb78379fb353f93a3c18d7c2721ffc124ffc663af6a386706e9d79c2b34
MD5 d0604a4eb390c86d6e661747d55763ce
BLAKE2b-256 0a41b0bd3182b65a5424790f43bd309da13f22265d9ec49315bf386e0e89038b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f1aacb1ab541ed102aa93985278c7280d18d200d4a5bdc83811b4462609d28d0
MD5 016634ac8a4e25739377caae0ebbc0c0
BLAKE2b-256 360aa735541b490d2caba5f95418217ba4f4bfc89ce7bc515db76aec98d41e49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de84290ba1ffa2157ffac3da5fa1e0b0bf424957352a43504b0056a5a65c9547
MD5 09683bff0f423b94fa97805c3b789a53
BLAKE2b-256 6b15da0d60a086e6e40577d2de9a4210d1206ddf8ddaad1c22a57b2754ae95e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a3bc65ef788e2e641dec8574360e9e42874720ed7e2e56aae8577864fe9d6bb
MD5 fe3ec6d6d4586741f6c4194da7620aea
BLAKE2b-256 daaa072fe2fd7eec1b9955ccde603a788e2f1611d162d4e7b09f1a73548815a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 39879bab32d6bc5e31c7e5c6967f4e3e38cd57b55fefae0a6ef3bcde1b1b044b
MD5 6272e642f952d52fdb9a5f0488cb208a
BLAKE2b-256 22131d480f1c6736fd990ff64415e2bbc0b8e7f2f7478918ab2b829ced5539b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a45531ec2e9a080eb543327097c090303ea3bc0db2e961d1c6ceb9fb514cdf08
MD5 793c79933f1abdfb5615102afb96b73b
BLAKE2b-256 75edebbb36f66607148d46c555c14ee072115e1a20783e0d83925b62833c91ae

See more details on using hashes here.

Provenance

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