-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PyROOT binding registration (#224)
* Fix PyROOT binding registration * flake8 is falling behind other tools these days * no print
- Loading branch information
Showing
6 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ jobs: | |
- python-version: pypy-3.7 | ||
runs-on: ubuntu-latest | ||
|
||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
|
@@ -52,3 +51,33 @@ jobs: | |
|
||
- name: Test package | ||
run: python -m pytest -ra | ||
|
||
checkroot: | ||
name: Check ROOT bindings | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Set up Conda | ||
uses: conda-incubator/[email protected] | ||
with: | ||
python-version: 3.11 | ||
miniforge-variant: Mambaforge | ||
channels: conda-forge,defaults | ||
channel-priority: true | ||
|
||
- name: Install ROOT | ||
shell: bash -l {0} | ||
run: | | ||
mamba install root | ||
- name: Install package | ||
shell: bash -l {0} | ||
run: python -m pip install .[test] | ||
|
||
- name: Test package | ||
shell: bash -l {0} | ||
run: python -m pytest -ra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
import correctionlib | ||
import correctionlib.schemav2 as cs | ||
|
||
|
||
def test_pyroot_binding(): | ||
ROOT = pytest.importorskip("ROOT") | ||
correctionlib.register_pyroot_binding() | ||
assert ROOT.correction.CorrectionSet | ||
|
||
ptweight = cs.Correction( | ||
name="ptweight", | ||
version=1, | ||
inputs=[ | ||
cs.Variable(name="pt", type="real", description="Muon transverse momentum") | ||
], | ||
output=cs.Variable( | ||
name="weight", type="real", description="Multiplicative event weight" | ||
), | ||
data=cs.Binning( | ||
nodetype="binning", | ||
input="pt", | ||
edges=[10, 20, 30, 40, 50, 80, 120], | ||
content=[1.1, 1.08, 1.06, 1.04, 1.02, 1.0], | ||
flow="clamp", | ||
), | ||
) | ||
cset = cs.CorrectionSet(schema_version=2, corrections=[ptweight]) | ||
csetstr = cset.model_dump_json().replace('"', r"\"") | ||
|
||
ROOT.gInterpreter.Declare( | ||
f'auto cset = correction::CorrectionSet::from_string("{csetstr}");' # noqa: B907 | ||
) | ||
ROOT.gInterpreter.Declare('auto corr = cset->at("ptweight");') | ||
assert ROOT.corr.evaluate([1.2]) == 1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters