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.13.tar.gz (29.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.13-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (164.5 kB view details)

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

hallmodel-2026.6.19.13-cp314-cp314-macosx_11_0_arm64.whl (138.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

hallmodel-2026.6.19.13-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (164.4 kB view details)

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

hallmodel-2026.6.19.13-cp313-cp313-macosx_11_0_arm64.whl (138.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.13-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (164.3 kB view details)

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

hallmodel-2026.6.19.13-cp312-cp312-macosx_11_0_arm64.whl (138.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.13-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (161.5 kB view details)

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

hallmodel-2026.6.19.13-cp311-cp311-macosx_11_0_arm64.whl (136.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.13-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (160.6 kB view details)

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

hallmodel-2026.6.19.13-cp310-cp310-macosx_11_0_arm64.whl (135.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: hallmodel-2026.6.19.13.tar.gz
  • Upload date:
  • Size: 29.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.13.tar.gz
Algorithm Hash digest
SHA256 e25b163adc2615dab68d3a21bb29b1171d014c71ea29b1801af5aad244b60fae
MD5 d25101c56e30a35526f12e0f455c1052
BLAKE2b-256 26931d8b488e9b9bb75a153effeb1bb1ea3b16abc3af3adc702d9338656aba5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ce9dab742b1b2e826eb92e8f1b1c587bbaf25463b34e7319f96e71b05eea6d3
MD5 0e740cacf42c5d26519e70039b6a94c9
BLAKE2b-256 7cf72363eddccd7d05e511462e40555569ff1cb4883d27d11964b34885316684

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6fca6034665f04429c0bb45ac5b57aaa41bcf0e8c8a58c7b3686a270b7f57575
MD5 619ff7216777e92d15b888434a8cb117
BLAKE2b-256 7c0fbe648b03dc71b1d781e7392c1456e91a35b03f2ab91ab37f5fbf6b4448a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 886db598047f21207dc7d64da932a1d63c49c3b6abecbcd6aec9cae849c1f082
MD5 ea624af6a8912f492c5522e9a5f35c50
BLAKE2b-256 72b3bf15d8be5175bdba3b3ab5c366e4db0310a945fba65374a88ae2ab6ed726

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 531288638208843c61dc0be81176b8e97b1aa4d5f853f2fadf5ff0a0ace5bb29
MD5 ce1ab14e02e921c71147b9a8e2d7e0ac
BLAKE2b-256 43cc68515273e22a1f051373bdbaab3e68e17d6aa2304745d2220d2e269e3d72

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d67bdd067fca44d8c618ecfad23fcaf6b57a3867a8c47fcb541e0b9aaeb2131
MD5 fa880034e6e14742ccbf3acc52e63824
BLAKE2b-256 96e64fdaf381eeb5aef14af985cc5715552a76597b240aa68abcf8b7fd052dc0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fdeee25fee9ee6ab57048c48ff5c66882bdea7f3f42cbc43248c53433d53e21d
MD5 d41b384502f6f65c740bae43b4659c7a
BLAKE2b-256 7872bc8b6c9691323649fda157d7abbf9ba9335bce8f4d975be4f4a2949733ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df655db00bb9bcbeb4044ddae94e7c5ba3069c5fdab4f866258592a9bde0047e
MD5 23a7f520b871661eb9f36199e5b8b1dc
BLAKE2b-256 50ac44b87e9c2af2a9d85ba5ed31391ea6e7bbe048fa3c3f0fd8e2daa72d6c80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e20c17ee26f3c651ceaf0c8423ba713c8e6de88cb1242e1b20eab8a72e0ed9d2
MD5 220a7aef1b4412dc6cd81610cb7c299b
BLAKE2b-256 2cb871efd4c60547ad6fbaead571df4f8a8c14a5ee6e01570a8b9147e9f102e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6faeca6538afc5e302d690dcf8606af94c0be0cb56ce513eb1befdef2bf0a20
MD5 dc0f94bd785a9d52e4a797fc271b1945
BLAKE2b-256 be969e0a37b88d1aa594ce06331c812bbd1989d3a09112ae84b75fca1212acca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 326bc5a5c9514c6d0c3dc0e172bb54bfb8fb5da81a33d393d37b64cc854dd806
MD5 9a25f06ec20a85b1f42bf2639b33dd58
BLAKE2b-256 afb145006601591a46cccd8c06107b708558e0c2f35f4969e87f5e9a10ea30fb

See more details on using hashes here.

Provenance

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