Skip to main content

Python bindings for GRHayL (EOS-first preview)

Project description

pyghl

Python bindings and neural-network tooling for GRHayL.

pyghl packages a pinned GRHayL build together with a CPython extension and Python utilities for tabulated equations of state, conservative-to-primitive experiments, and neural-network initial guesses.

Warning

While revised by humans, the majority of the code in this repository has leveraged AI assistance. Users should review results carefully and use this package at their own risk.

At a high level:

  • pyghl exposes selected GRHayL C structs and routines to Python.
  • pyghl.eos provides tabulated-EOS loading and interpolation helpers.
  • pyghl.nn provides neural-network con2prim data, training, export, and EOS embedding helpers.
  • pyghl train trains a neural-network model for an EOS table.
  • pyghl append embeds a trained model into an EOS HDF5 file.

Installation

For end users installing from PyPI:

python -m pip install pyghl

Check the installed package:

pyghl --version

For contributors working from a clone of this repository:

git clone https://github.com/GRHayL/pyghl.git
cd pyghl
git submodule update --init --recursive
python -m pip install -e .

The local build compiles the pinned GRHayL submodule in extern/GRHayL and then builds the Python extension against the resulting libghl.

If you need to build against a different local GRHayL checkout:

GRHAYL_DIR=/path/to/GRHayL python -m pip install -e .

Prerequisites by Workflow

python -m pip install pyghl should install a prebuilt wheel on supported platforms. Source builds need additional system tools:

  • Local extension builds: a C compiler, make, HDF5, and Python build tooling.
  • Editable contributor installs: initialized extern/GRHayL submodule.
  • Neural-network training: torch, numpy, and h5py from package dependencies.
  • EOS workflows: a GRHayL-compatible tabulated EOS HDF5 file.

Current CI builds wheels for Linux x86_64 and macOS arm64.

Basic EOS Neural-Network Workflow

The quickest useful workflow is to make sure the EOS file itself contains the neural-network data that GRHayL loads when enable_neural_net_c2p=True.

1. Try the installed model cache first

pyghl append path/to/eos_table.h5

This looks for an installed neural-network model whose recorded EOS hash matches the EOS file, then embeds it into the EOS under the grhayl_nn_c2p group. This is the preferred first command because it is fast and avoids retraining known EOS tables.

2. Train if the EOS is unknown

pyghl train path/to/eos_table.h5

If no installed model matches, pyghl train creates training data when no dataset is supplied, trains a small neural network, writes model artifacts such as tiny_mlp_model.h5, registers the model by the EOS canonical MD5 hash, and embeds the result into the EOS file by default.

To train from an existing dataset:

pyghl train path/to/eos_table.h5 path/to/nn_training_dataset.bin

3. Retrain a known EOS deliberately

pyghl train path/to/eos_table.h5 --force_retrain

Use this when the EOS is already known but you want to replace the installed model artifacts with a fresh training run. If the EOS already contains embedded neural-network data and you want to replace it too, add --overwrite_eos.

Other Useful Commands

Inspect whether an EOS file already contains embedded neural-network data:

pyghl check-eos path/to/eos_table.h5

List installed models that can be matched by EOS hash:

pyghl list-models

Append a specific model file instead of using the installed model cache:

pyghl append path/to/eos_table.h5 path/to/tiny_mlp_model.h5

Remove embedded neural-network data from an EOS file:

pyghl remove-eos-nn path/to/eos_table.h5

Python API Example

import pyghl as ghl

params = ghl.initialize_params()
eos = ghl.eos.initialize_tabulated_eos_functions_and_params(
    params,
    "path/to/eos_table.h5",
)

rho = 1.0e-12
Y_e = 0.05
T = 1.0e2

rho, Y_e, T = eos.tabulated_enforce_bounds_rho_Ye_T(rho, Y_e, T)
pressure = eos.tabulated_compute_P_from_T(rho, Y_e, T)
print(pressure)

Command-Line Tools

Primary commands:

pyghl train <eos-file> [dataset]
pyghl append <eos-file> [nn-hdf5]
pyghl check-eos <eos-file>
pyghl list-models
pyghl remove-eos-nn <eos-file>
pyghl --version

What Is Exposed?

Selected top-level bindings include:

  • initialize_params
  • initialize_metric
  • compute_ADM_auxiliaries
  • initialize_primitives
  • initialize_diagnostics
  • compute_conservs
  • undensitize_conservatives
  • compute_SU_Bsq_Ssq_BdotS
  • limit_v_and_compute_u0
  • limit_utilde_and_compute_v
  • guess_primitives
  • tabulated_Palenzuela1D_energy
  • tabulated_con2prim_multi_method
  • nn_c2p_guess
  • nn_c2p_guess_x

Struct wrappers include:

  • Primitive
  • Conservative
  • Metric
  • ADMAux
  • Diagnostics
  • Params
  • TabulatedEOS

Repository Map

  • csrc/: CPython extension source.
  • src/pyghl/: Python package.
  • src/pyghl/nn_c2p/: command-line neural-network workflows.
  • examples/: direct example scripts.
  • extern/GRHayL/: pinned GRHayL submodule used for builds.
  • .github/workflows/: wheel and PyPI publishing automation.
  • PUBLISHING.md: release and PyPI publishing checklist.

Contributor Setup

Recommended local workflow:

git submodule update --init --recursive
python -m pip install -e .
python -m compileall -q src setup.py

Build a local wheel:

python -m pip wheel . -w /tmp/pyghl-wheel --no-deps --no-build-isolation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyghl-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyghl-0.3.1-cp313-cp313-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

pyghl-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyghl-0.3.1-cp312-cp312-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pyghl-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyghl-0.3.1-cp311-cp311-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pyghl-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyghl-0.3.1-cp310-cp310-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file pyghl-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d7eddf36ae60e04e185fddd7beeec0ce79e2baddff70b3568c4a1b8421043916
MD5 c10a506cd7eb0ad11d2c388cd986c5b5
BLAKE2b-256 cc7c4b9561b10a2bb85c73f74d3b229059bb8dae52a8aa33fd6a62d8d2b04d8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d6b4a8a2c90002f2ae2625c5127b9884e6c573e88cf4c628991477920ec98515
MD5 12be1ff5d60d0b18c41256004bb0d59e
BLAKE2b-256 426532a8c9c0cca18137ad05253f1ec5c7096fcf5298b4011241e1d60e37ec87

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cb2c27369167fdd7a234ab15ac43005764714252f5ff900cb7c63cd143b5aa77
MD5 cb54a2264917a11addedaaced8b469e1
BLAKE2b-256 564b057b5dbce58ae2bd8c3309b602ec3779f6c98eb79ba9d8fa629e22e8e04a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 29b2a3668a68ecfabdb134f79e6c6bcf13c3f7557c93d51e9f28146fccbd26ad
MD5 4821d64b23160bf9ece9acfe54fef9a1
BLAKE2b-256 197cae81ed282035a990b033880225d334c0bee9b11111965f21927619aec01b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb3d618ae5b7f61907caf9c039d0e66022a00fa1a8a71e7acee15a6220ec50d9
MD5 9b0373f034194840a92c90d182c4e2ae
BLAKE2b-256 f6fcb20cf0e98a59be9ea15e3f4fc02818a1d1484baa84fde55205fe443511a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 693781ecf0b8f909621395679e4b3fc5042125c94dd2a5bbeafe5f1bb16830c3
MD5 6da70d76bd1d3ce02ef963ac0b971e28
BLAKE2b-256 c42e6e336fc35b652c9fa7f74479ccae1c5dcb61787e12afc528f8e6cc590c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14cd9f8a9825c8885bf1907f7b861cc454d7a4424d16ea51ce5623812e127151
MD5 ec78bbec31b58fa222a6e1486528db36
BLAKE2b-256 6a3a625861bbe1a840a4df88172fc55fa3851c3c11c598150432dd17403d8d1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on GRHayL/pyghl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyghl-0.3.1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 35cd8759314156a76fd14739302e1200ac867861b8b2edd0c7a29dabbfc07297
MD5 fedfd0ade355c77ab7dd6d56cdcce20d
BLAKE2b-256 a42fc3d0fb364b76e73344802ceced41918b04d9c3c042e535db0d07dfd33770

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.1-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: publish.yml on GRHayL/pyghl

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