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-eos 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.

First Successful Run

The quickest useful workflow is to train a small model for an EOS table and append the result back into that EOS file.

1. Train a model

pyghl train path/to/eos_table.h5

This creates training data if no dataset is supplied, trains a small neural network, writes model artifacts such as tiny_mlp_model.h5, and registers the installed model by the EOS canonical MD5 hash.

To train from an existing dataset:

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

2. Append a model to an EOS file

Append an explicit model:

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

Or append the installed model matching the EOS canonical MD5 hash:

pyghl append-eos path/to/eos_table.h5

3. Inspect installed models

python -m pyghl.nn_c2p.list_installed_models

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 <eos-file> [nn-hdf5]
pyghl --version

Additional module entry points:

python -m pyghl.nn_c2p.nn_c2p_generate_dataset ...
python -m pyghl.nn_c2p.nn_c2p_train ...
python -m pyghl.nn_c2p.nn_c2p_test ...
python -m pyghl.nn_c2p.append_eos_file ...
python -m pyghl.nn_c2p.check_eos ...
python -m pyghl.nn_c2p.list_installed_models
python -m pyghl.nn_c2p.remove_eos_nn ...

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

If editable installs are not available in your environment, many Python-only checks can be run from the repository root with:

PYTHONPATH=src python -m pyghl.nn_c2p.list_installed_models

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.0-cp313-cp313-manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

pyghl-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

pyghl-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

pyghl-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyghl-0.3.0-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.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf4c47735c6906a08b9e5a457c9d99a974f7d86e2c0fcf730f4bf34e4a84b26b
MD5 82219d42690a8bdcbf2e2a5307d1cc2e
BLAKE2b-256 1cae0eb2e3d6586ad301065ae6f6a1af14b9c738cd5cbd12f1b75e902a1afb8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 90600190146f55b3aa96f0624c422913c4c536b4c8f5848250fa9f60dd1d06c1
MD5 b735279a343bd2a3f7c7a9d4d0963ab7
BLAKE2b-256 25752b6a7236437cae9e2314e2065b0f20e31c4a021c33ab836dfc0cb6b10570

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99208337a44e88c8bd66c903f491ccdf04357b5f26a0db7cf297025a2790672d
MD5 e59ea32a92f12c0d2ac8aea25bd8de80
BLAKE2b-256 5c2960ee8fba1a2eceb04b34bb6cb4a78e1b53fefd02269d8e643a691b26e28f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 92f4860e208fbb2fbb797d9af96d4de478195f5806cc595b5be2f501147eec9b
MD5 6d3970f3c0cb8cd0b818c56ea35d2f3f
BLAKE2b-256 0066a2ce6f1b059af2f6a49c4ab509833af4318ecfd6f1415621155ff9a02167

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9a0132d87e8d677f458416e0f45e0263221083989fc980111438fd3a78a750f
MD5 2debd2be8a72752fbd471fd413960026
BLAKE2b-256 3ea82fac024013aaafbb93dff454741b316d05f39e360a880fbbc77ca7591a49

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c6c31a874238dc2f0b229aad2034c3a8e2c178574d028bb431c1debcf3c0fe99
MD5 ebbed7fde5010f316e55c9a3be90c580
BLAKE2b-256 8ffd24303a5a323c1b69aa6444c3b7238212ed929a4c28eb40f086594e6aa3de

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 431087afec96e73da02024b536e8d983dba778c0d954267ff160fa383497b5d7
MD5 f74a7313a0e5b9015050e860676db084
BLAKE2b-256 bd10b12903983e5dd415631464a7612342b9ad4072137bf4603004b82e0f005b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 31df68e2e2ebf68ce99578242474745467f7be6d19cc31f0f568249035f4aaa6
MD5 728f09ba66fb26dde15101e80a0731c5
BLAKE2b-256 ef87ca11d29c8df0989465153527710e695dd971af95e8d323746c2e7b3dd686

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyghl-0.3.0-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