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

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyghl-0.2.1-cp313-cp313-macosx_14_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyghl-0.2.1-cp312-cp312-macosx_14_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyghl-0.2.1-cp311-cp311-macosx_14_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pyghl-0.2.1-cp310-cp310-manylinux_2_28_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyghl-0.2.1-cp310-cp310-macosx_14_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd0a7728d7cca6a8238ca55b7d2c1f0bf5436857f1dddd3c6ce60af07e9f93f8
MD5 f2c007dcedb43fbf3c69026bb29fa25b
BLAKE2b-256 42aa3182ca6283f04ec5e396fff47af09a2e29eec518a091d57dffea1a79bdfb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 78b9fff33bbf198c55f5e2e68c3e7273723cceedc60dc0f1b1fc57c40ef3c474
MD5 08fc946584caafdfac40e89a060ce32d
BLAKE2b-256 636fff64973b8c5a5062a9d0d8efa887676546104e07d5417ab7559c2386e958

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7d984e155864280830a213ed044018f2ae0740fb624fed6c40f7376cf250f027
MD5 4d9b1ac6ac8d11e334b6ba1b27f189c0
BLAKE2b-256 b014bbab1aa1d28543898e11fd0cf908bf21b1027f9618cdc450c3805179d79d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2658d1528718b446d015df7e1ec38d98666ccb92c40e79f5ac6b0e7f64832af6
MD5 9e9fe9bcc4aabe529e05bcece6ea7fee
BLAKE2b-256 aa6a6708767f5704adb8dc80198c3e951d6598a075f1200ec98330e497841b7c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5a868505247ab6140ee0ea7c5953bd1b07fe4048eebd547633ba4b59f5f5747
MD5 45bb69374dc92bb14417b29d396f8cd2
BLAKE2b-256 6b93d8eaebbad59470766c4763cfd797010f1b907e16675d5a926ba43f2f54a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9696f8b33e611917737dc04d3d4ffce2aab4d884f076f6aeaafac074528edf0e
MD5 856ff849ee8fa76a44002a1ca04302b1
BLAKE2b-256 6d37bff4c79bfbe7c1f2ff5987213497ea79a6cecabdacff5e6bb26023fc6dda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2648960e7f9d89ae549202c349fab0fee708bb0a69bc2d67a32d9453b825720f
MD5 76d49be3030438d905c71797b420d56c
BLAKE2b-256 f4573408abd089371c078a6b5d0369412a34fd8846afe1f302b42bc5c66d8d66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.2.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9fa027aefc6f21eb1d53a94a24c1b1ffda61f1234985113fc6011d25691485d0
MD5 653d8a385b9cb84a66d77996201da421
BLAKE2b-256 50fe1df0197eb80e26829ce9c584e81236d06934155c548cdbff2d99c181b9ca

See more details on using hashes here.

Provenance

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