Automatic differentiation for high-energy physics correction factor calculations.
Project description
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
CorrectionWithGradient
object from acorrectionlib.schemav2.Correction
- there is no point 2: you can use
CorrectionWithGradient.evaluate
as a normal JAX-friendly, auto-differentiable function
Example
import jax
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 jax.numpy.isclose(value, 9.0)
assert jax.numpy.isclose(grad, 6.0)
# jax.jit works too
value, grad = jax.jit(jax.value_and_grad(c.evaluate))(3.0)
assert jax.numpy.isclose(value, 9.0)
assert jax.numpy.isclose(grad, 6.0)
Supported types of corrections
Currently the following corrections from correctionlib.schemav2
are supported:
Formula
Binning
with uniform and non-uniform bin edges, simple scalar bin values, andflow="clamp"
- scalar constants
License
correctionlib-gradients
is distributed under the terms of the BSD 3-Clause license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for correctionlib_gradients-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56390ccb9e52956f10d1348576e3831ab6ac870a41023e531f80e2c059c9fd9 |
|
MD5 | fdfdfb9f37468d0c5cb54b302016a070 |
|
BLAKE2b-256 | 94b50ac38d32024b6be01584051c654a711d4d4d464896c6a96c5ed66c4b19a3 |
Close
Hashes for correctionlib_gradients-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ab0f61384d4c7f45cddcb354eaffc85644cbf2c06d604da48b9021b81b8ef2 |
|
MD5 | f2d4bbc7392dfb3b5687d870e12923b0 |
|
BLAKE2b-256 | b0b231c77721f2730c6295e33ea6614488c62a45456ada87f8aab874a5201320 |