correctionlib-gradients
A JAX-friendly, auto-differentiable, Python-only implementation of correctionlib correction evaluations.
Table of Contents
Installation
pip install correctionlib-gradients
Usage
- construct a
CorrectionWithGradientobject from acorrectionlib.schemav2.Correction - there is no point 2: you can use
CorrectionWithGradient.evaluateas a normal JAX-friendly, auto-differentiable function
Example
import jax
import jax.numpy as jnp
from correctionlib import schemav2
from correctionlib_gradients import CorrectionWithGradient
# given a correctionlib schema:
formula_schema = schemav2.Correction(
name="x squared",
version=2,
inputs=[schemav2.Variable(name="x", type="real")],
output=schemav2.Variable(name="a scale", type="real"),
data=schemav2.Formula(
nodetype="formula",
expression="x * x",
parser="TFormula",
variables=["x"],
),
)
# construct a CorrectionWithGradient
c = CorrectionWithGradient(formula_schema)
# use c.evaluate as a JAX-friendly, auto-differentiable function
value, grad = jax.value_and_grad(c.evaluate)(3.0)
assert jnp.isclose(value, 9.0)
assert jnp.isclose(grad, 6.0)
# for Formula corrections, jax.jit and jax.vmap work too
xs = jnp.array([3.0, 4.0])
values, grads = jax.vmap(jax.jit(jax.value_and_grad(c.evaluate)))(xs)
assert jnp.allclose(values, jnp.array([9.0, 16.0]))
assert jnp.allclose(grads, jnp.array([6.0, 8.0]))
Supported types of corrections
Currently the following corrections from correctionlib.schemav2 are supported:
Formula, including parametrical formulasBinningwith uniform or non-uniform bin edges andflow="clamp"; bin contents can be either:- all scalar values
- all
FormulaorFormulaRef
- scalar constants
Known limitations
Only the evaluation of Formula corrections is fully JAX traceable.
For other corrections, e.g. Binning, gradients can be computed (jax.grad works) but as JAX cannot
trace the computation utilities such as jax.jit and jax.vmap will not work.
np.vectorize can be used as an alternative to jax.vmap in these cases.
License
correctionlib-gradients is distributed under the terms of the BSD 3-Clause license.
Metadata
Release files for correctionlib-gradients 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| correctionlib_gradients-0.2.2.tar.gz | 14.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| correctionlib_gradients-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / correctionlib_gradients-0.2.2.tar.gz
| Download URL | correctionlib_gradients-0.2.2.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa994ee9706cacde516bafbdd2b6c09364611ee05d4912e4298bec5227d4b261
|
|
BLAKE2b-256 checksum How to use checksums |
42478ebd2dcfb33ab4207a1414d00768dac42716d32377f07aa560ad448783c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.25.1
|
Release files / correctionlib_gradients-0.2.2-py3-none-any.whl
| Download URL | correctionlib_gradients-0.2.2-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0adbf6a9744a4f9e4437a6226f312007004fa33a6576447d2ae7e16153b93add
|
|
BLAKE2b-256 checksum How to use checksums |
160b7d479fcfa893b6eff24044df689f5391a962a9edb9d02d10a7085f930d30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.25.1
|
Security for correctionlib-gradients 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.