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.14.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.14-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.14-cp314-cp314-macosx_11_0_arm64.whl (138.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

hallmodel-2026.6.19.14-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.14-cp313-cp313-macosx_11_0_arm64.whl (138.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.14-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.14-cp312-cp312-macosx_11_0_arm64.whl (138.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.14-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.14-cp311-cp311-macosx_11_0_arm64.whl (136.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

File metadata

  • Download URL: hallmodel-2026.6.19.14.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.14.tar.gz
Algorithm Hash digest
SHA256 bbb8b5493c0344c1885a9659588f2a1fc3fc8638b610f6f9749d44b76afea03a
MD5 21d5dd83e50d2d327333d48c5d482d9f
BLAKE2b-256 2858f76dd8f4113c6a99c6f4b7743366bf2f412b01ec98bd4aec441ea073c65f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52f8c1fa3704d8c73d1aff85d8f82ae09a164a1caee7cc6304d01087888a6639
MD5 fc09945599b7f5316f57d6a02d7697c3
BLAKE2b-256 ea29fef8dae1f3476188657446dd2f933f8f46a33e212606f52ba7df1e15b92f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f57aa38ba3ebcef0f7ed18bc5f80895969783532a51670d3255e59ab019d41b9
MD5 d1e405537642642c760c8bc188280ca8
BLAKE2b-256 d6bf296a4504703bbd0668289d6b6730d0298b70b1f3bd952d2ff487297866c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb54de609dece15cb9dbf3ede5902cfb6d129c939b598169f50c884efaa658ce
MD5 9d50a62a15876e6e51f646ef37a67c7f
BLAKE2b-256 96a9df00649206695b997b56fddb5be8ebf8d8737e2d71fb2c6960208a29349c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58943163adf068e28c892be902989c46433b0468780e2b152043fc8866f5c12e
MD5 c322bfc1678134859c0b7deb61649490
BLAKE2b-256 615df7ac8d16d29183bdf2c1280070b22117d7c1e94657198768aaa23b60855b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55125509045bd5a8185ebd4f4d90d68ee1731559a46317d8979344d4c99d142c
MD5 48b70f22dab23beae15c2b0b502908c7
BLAKE2b-256 b9ce11bf523390fc9f232ce82a48c4a4e6c74dfb92c5c946d9ccb21aaed8667c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2587899754e3c8c7e07bb418d13982f19dc493e71ddbf424035c0d60247ba7d0
MD5 182bd2e31fa2e3f43b9a1683740ce2a4
BLAKE2b-256 07a475ac64c3ba07c419f4d1df30668611aadc680e5498c7a2a02a193f05ca78

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9d7faa74e4917c2760e37e2ab5d8f18d22ae94688c1f04f45b28eb156b8bb7ff
MD5 4fb77f30b427b0b561bb6ffa0f154cea
BLAKE2b-256 237f441978e0b1aaed862d51eb99c21706ce81156373b03acb7af37001650da9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13077723c5632e4ce0563ef5807c1e0605aedfa5309ddd330824327950673a75
MD5 d37f742b4da181303bada51cf8175a83
BLAKE2b-256 6c54449d05c7505512c7f13b386c5c179e221475dd950c2aa24eb06fbd31af40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 490edc2d6bda93c4b239309e731f79d61de1a4df4bc25e93335a57749594caa9
MD5 4da909db5dc713dd4ab20066f8378bcc
BLAKE2b-256 1228c13869f8eae13d04aa91740256ca4f4e7e5f1c0f4cb683f48f3e819992af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92471258d68b086afed4252109f8139f07e00ed43227c85c0b34938748614bc3
MD5 ee07565f8848c9acba177912681e6736
BLAKE2b-256 859184b23cf21942ec136b09fe631fbbcf3bc781ebd1dc86c694cac234db83d8

See more details on using hashes here.

Provenance

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