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.11.tar.gz (24.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.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.8 kB view details)

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

hallmodel-2026.6.19.11-cp313-cp313-macosx_11_0_arm64.whl (138.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

hallmodel-2026.6.19.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (163.7 kB view details)

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

hallmodel-2026.6.19.11-cp312-cp312-macosx_11_0_arm64.whl (138.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

hallmodel-2026.6.19.11-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (160.8 kB view details)

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

hallmodel-2026.6.19.11-cp311-cp311-macosx_11_0_arm64.whl (135.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

hallmodel-2026.6.19.11-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (160.0 kB view details)

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

hallmodel-2026.6.19.11-cp310-cp310-macosx_11_0_arm64.whl (134.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: hallmodel-2026.6.19.11.tar.gz
  • Upload date:
  • Size: 24.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.11.tar.gz
Algorithm Hash digest
SHA256 4ca102eb546f6c230e39185b01322c5a8cb59650712f91f06e1d92a19e4ad2be
MD5 6d2723b90cb31e306b0ce53845b24ef5
BLAKE2b-256 49e907ca5c245a546c64815742f16c9ce65c87c39ccc20211de46f958bea83f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fa55812a9163cf93b3cbf03ca85f6134a911173288f26c7665c55d8ed014dcc2
MD5 1cc44331361a240e335544acf903ea79
BLAKE2b-256 0eb5fc1a84c4922d679cc28c491bd9d167426e79b421d88b9dbfdaf1decdf2fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1104bcbab710cbbd18f15ae38af8302518ba1ec17f32afb6808e67d58125d7c3
MD5 928e4fb1a5fce13a16171a4b8b0b575c
BLAKE2b-256 d297837afbbe74f6df9608867051d9e11fcf6f5ce6e39b93d9f67dadd3c9581f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3021c27ed8a92414bc6212fead66e7df09595c7d62d53a365d96a4b678e3e232
MD5 5ff9530e689fa1cc3aa307adb36a4e7f
BLAKE2b-256 f8e6301cdb5f4470e561512f94f78562e293857ee54498f67511d630a14825b2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1cfa0c89c33b20a57e1ee34b603a76deb2fc332dd6b5d2b570efd26330e097c5
MD5 935aa774b41f9d6c5ecea027cc697b10
BLAKE2b-256 a60688bb28ec19b9c1e4d60a96ae99f864fd6111a1b32027b35842b27fe88ed6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d00640a230a6e7a1a92e3b1cd87a2d812c8f2359ff7cf36c6afa2400afaf946
MD5 9ecc07b946370cd7cc65127b559b2956
BLAKE2b-256 3ab5127b969202255e8e414e89ec961383f1cf3524b0d53648bae5c7d97dfec4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2fd3464a5c17ce9fb62e83e5af01a7beca6feec968342f103067d4732733d51b
MD5 9613829994069e58f35a40bcba23e187
BLAKE2b-256 4e6cf8593308d1c84a7e4f8b864285ee0561adc1d33b17f8a35e24ba5f787be2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e8e52974afdc502f2056db6ac27785f9c40c3dc13c5ff3a88a41a7430e90d87d
MD5 8a2886a8c1192abd4206244ff94c52a2
BLAKE2b-256 2971cb78fbec569fbc75855e98aeb4901c833e6a5f19848f2668ee693e05def9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hallmodel-2026.6.19.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35be86384440c63f3db2bf69c6677995a1bb8a987decb3f2af1bec1dd740acda
MD5 8aecb65412e5947c4d15ce7941a21f36
BLAKE2b-256 e6cac1b154f4540939d191506bc21ffc481a206b930bc5d9af21370a309b5bf1

See more details on using hashes here.

Provenance

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