Skip to main content

Tools to work with pytrees.

Project description

PyPI PyPI - Python Version https://img.shields.io/conda/vn/conda-forge/pybaum.svg https://img.shields.io/conda/pn/conda-forge/pybaum.svg PyPI - License https://readthedocs.org/projects/pybaum/badge/?version=latest https://img.shields.io/github/workflow/status/OpenSourceEconomics/pybaum/main/main https://codecov.io/gh/OpenSourceEconomics/pybaum/branch/main/graph/badge.svg pre-commit.ci status https://img.shields.io/badge/code%20style-black-000000.svg

Installation

pybaum is available on PyPI and Anaconda.org. Install it with

$ pip install pybaum

# or

$ conda install -c conda-forge pybaum

About

pybaum provides tools to work with pytrees which is a concept borrowed from JAX.

What is a pytree?

In pybaum, we use the term pytree to refer to a tree-like structure built out of container-like Python objects. Classes are considered container-like if they are in the pytree registry, which by default includes lists, tuples, and dicts. That is:

  1. Any object whose type is not in the pytree container registry is considered a leaf pytree.

  2. Any object whose type is in the pytree container registry, and which contains pytrees, is considered a pytree.

For each entry in the pytree container registry, a container-like type is registered with a pair of functions that specify how to convert an instance of the container type to a (children, metadata) pair and how to convert such a pair back to an instance of the container type. Using these functions, pybaum can canonicalize any tree of registered container objects into tuples.

Example pytrees:

[1, "a", object()]  # 3 leaves

(1, (2, 3), ())  # 3 leaves

[1, {"k1": 2, "k2": (3, 4)}, 5]  # 5 leaves

pybaum can be extended to consider other container types as pytrees.

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

pybaum-0.1.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

pybaum-0.1.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pybaum-0.1.3.tar.gz.

File metadata

  • Download URL: pybaum-0.1.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pybaum-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5827d90d94ba6ea68b7920f13c8df26a101b9be943fadee77bb2cc2a5c28fda3
MD5 b6e71cda5f2c054dde7513b52401f1ce
BLAKE2b-256 ad8490f2e102776051e7904f2f67c976483d18d04e19659e1e39bcec87bd5a91

See more details on using hashes here.

File details

Details for the file pybaum-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pybaum-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pybaum-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a1d74200d0477c7da121af2f67a236d658ec62aaef5f5c35562ec959f52efa3d
MD5 65642d8e3418899cd2e7efb56e8147af
BLAKE2b-256 d320bcd8f317a17900e5daeb3f87a87327399c9bbe9dcd97f4025f4663c3bdf1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page