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.2-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.2-cp313-cp313-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

pyghl-0.3.2-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.2-cp312-cp312-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pyghl-0.3.2-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.2-cp311-cp311-macosx_14_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pyghl-0.3.2-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.2-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.2-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyghl-0.3.2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fa386bb31685230a5a8adae75e88d26ee1f973239b737531761dd1cc486fd8e5
MD5 dc6f2558483897cfe34feab373b483f7
BLAKE2b-256 d903402ee586abdc3df1f7fcf5301493ab298ee90a23591e0e31eb7e8f69b8bd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5ba2bf4730810aef30ef9239e34e123d02bd4e59d6e901c258d8863a0b00ecb7
MD5 f98561c72677d662f91923ad9318c7ac
BLAKE2b-256 70ae8cfa3e39aa57e8a6c0c354dca6fcfe1e6e1c22e1cefc79f8c5f13aff6420

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2f17e80a6737b1c4e684088c3828df3bfae2e000837b3654aec90c5d44e394e7
MD5 14dfdb4fa2089656f114ad03a6ba6fca
BLAKE2b-256 204f9f6de228fc1562dfab7ff0b865666402329bec5004b3053173fc57efe6e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bf4e5d63e42e974f3e7ddce4c80d3e400e5aa51ac86e22ec90e6cc4f1a500544
MD5 5167cb31db7151dff7a2ab671a441f4a
BLAKE2b-256 84e96814184d82fb1be3bd01bbf9aa1889e701a52493422e7fd23c452d1a5c94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fba7fe93c2ee7c45c96254b7e39b033dedfa939f183d38050646dca256193540
MD5 c73a2ba3b379f92a5d71b5ba8879d220
BLAKE2b-256 8440b93ef2689906d8f8db86f2279fa73c4a922e29dfe4d409584be759646938

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 daf37a0a5d5f502577fea8270574a22e2d6baa73a384b88b5f1eb688cba0cc2e
MD5 5c0b849e5eaa3577134c94d1820b8188
BLAKE2b-256 43820fd6a38402e5274236b0880e5db11555d7ad277915fc878df1316f5f192c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a16f3e460e1cc6349993505d39f743d72c3fc7c50df937d4bc8d110c72e50d8
MD5 e26e5c465f4266972b768eab9b0a37bc
BLAKE2b-256 967281c2baa539edfdea8900087d14f1085ec4bfee45ecf7dd285fc93a57dc22

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyghl-0.3.2-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b98502c37f4d49df1425c79f4f289341bc1912cc179dd20c600cc388599ed6cf
MD5 ba9dc5ef61b39ae9bba7e92532651fa1
BLAKE2b-256 75fce3a39f724dff5db14710bd136d4a00770e2fa14b21216fcf7eb8f87ca6f6

See more details on using hashes here.

Provenance

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