Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 93 additions & 19 deletions bench/plot.ipynb

Large diffs are not rendered by default.

109 changes: 75 additions & 34 deletions bench/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ def logsumexp(a, b):
r = np.empty_like(a)
for i in nb.prange(len(r)):
if a[i] > b[i]:
r[i] = a[i] + np.log(1 + np.exp(b[i] - a[i]))
c = a[i]
d = b[i]
else:
r[i] = b[i] + np.log(1 + np.exp(a[i] - b[i]))
c = b[i]
d = a[i]
r[i] = c + np.log1p(np.exp(d - c))
return r


Expand Down Expand Up @@ -210,39 +213,77 @@ def run():
assert_allclose(m.values[:-1], ARGS[:-1], atol=2 / n**0.5)


@pytest.mark.parametrize("n", N)
@pytest.mark.parametrize("BatchMode", [False, True])
@pytest.mark.parametrize("NumCPU", [0, nb.get_num_threads()])
@pytest.mark.parametrize("EvalBackend", ["legacy", "cpu"])
def test_RooFit(benchmark, n, BatchMode, NumCPU, EvalBackend):
try:
import ROOT as R

x = R.RooRealVar("x", "x", 0, 1)
z = R.RooRealVar("z", "z", 0.5, 0, 1)
mu = R.RooRealVar("mu", "mu", 0.5, 0, 1)
sigma = R.RooRealVar("sigma", "sigma", 0.1, 0, 10)
slope = R.RooRealVar("slope", "slope", 1.0, 0, 10)
pdf1 = R.RooGaussian("gauss", "gauss", x, mu, sigma)
pdf2 = R.RooExponential("expon", "expon", x, slope)
pdf = R.RooAddPdf("pdf", "pdf", [pdf1, pdf2], [z])
if R.__version__ >= "6.30":

@pytest.mark.parametrize("n", N)
@pytest.mark.parametrize("NumCPU", [0, nb.get_num_threads()])
@pytest.mark.parametrize(
"EvalBackend", ["legacy", "cpu", "codegen", "codegen_no_grad"]
)
def test_RooFit(benchmark, n, NumCPU, EvalBackend):
x = R.RooRealVar("x", "x", 0, 1)
z = R.RooRealVar("z", "z", 0.5, 0, 1)
mu = R.RooRealVar("mu", "mu", 0.5, 0, 1)
sigma = R.RooRealVar("sigma", "sigma", 0.1, 0, 10)
slope = R.RooRealVar("slope", "slope", 1.0, 0, 10)
pdf1 = R.RooGaussian("gauss", "gauss", x, mu, sigma)
pdf2 = R.RooExponential("expon", "expon", x, slope)
pdf = R.RooAddPdf("pdf", "pdf", [pdf1, pdf2], [z])

data = pdf.generate(x, n)

args = [R.RooFit.PrintLevel(-1), R.RooFit.EvalBackend(EvalBackend)]
if NumCPU:
args.append(R.RooFit.NumCPU(NumCPU))

def run():
mu.setVal(0.5)
sigma.setVal(0.1)
slope.setVal(1)
z.setVal(0.5)
pdf.fitTo(data, *args)

benchmark(run)
assert_allclose(z.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(mu.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(sigma.getVal(), 0.1, atol=5 / n**0.5)

data = pdf.generate(x, n)
else:

def run():
mu.setVal(0.5)
sigma.setVal(0.1)
slope.setVal(1)
z.setVal(0.5)
args = [
R.RooFit.PrintLevel(-1),
R.RooFit.BatchMode(BatchMode),
R.RooFit.EvalBackend(EvalBackend),
]
if NumCPU:
args.append(R.RooFit.NumCPU(NumCPU))
pdf.fitTo(data, *args)

benchmark(run)
assert_allclose(z.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(mu.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(sigma.getVal(), 0.1, atol=5 / n**0.5)
@pytest.mark.parametrize("n", N)
@pytest.mark.parametrize("NumCPU", [0, nb.get_num_threads()])
@pytest.mark.parametrize("BatchMode", [False, True])
def test_RooFit(benchmark, n, NumCPU, BatchMode):
x = R.RooRealVar("x", "x", 0, 1)
z = R.RooRealVar("z", "z", 0.5, 0, 1)
mu = R.RooRealVar("mu", "mu", 0.5, 0, 1)
sigma = R.RooRealVar("sigma", "sigma", 0.1, 0, 10)
slope = R.RooRealVar("slope", "slope", 1.0, 0, 10)
pdf1 = R.RooGaussian("gauss", "gauss", x, mu, sigma)
pdf2 = R.RooExponential("expon", "expon", x, slope)
pdf = R.RooAddPdf("pdf", "pdf", [pdf1, pdf2], [z])

data = pdf.generate(x, n)

args = [R.RooFit.PrintLevel(-1), R.RooFit.BatchMode(BatchMode)]
if NumCPU:
args.append(R.RooFit.NumCPU(NumCPU, 1))
args.append(R.RooFit.Parallelize(NumCPU))

def run():
mu.setVal(0.5)
sigma.setVal(0.1)
slope.setVal(1)
z.setVal(0.5)
pdf.fitTo(data, *args)

benchmark(run)
assert_allclose(z.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(mu.getVal(), 0.5, atol=5 / n**0.5)
assert_allclose(sigma.getVal(), 0.1, atol=5 / n**0.5)

except ModuleNotFoundError:
pass
2 changes: 1 addition & 1 deletion doc/_static/interactive_demo.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/automatic_differentiation.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/basic.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/binned_vs_unbinned.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/conditional_variable.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"id": "naked-recruitment",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/cost_function_benchmarks.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/cost_functions.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"id": "negative-concord",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/cython.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/error_bands.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"id": "frozen-raising",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/external_minimizer.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/generic_least_squares.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/gof.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/hesse_and_minos.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/interactive.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/memory_layout.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/numba.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/roofit.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/roofit/rf101_basics.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/roofit/rf109_chi2residpull.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/scipy_and_constraints.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"id": "ffdfe095",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/simultaneous_fits.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/template_fits.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/template_gof.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/template_model_mix.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cells": [
"cells": [
{
"attachments": {},
"cell_type": "markdown",
Expand Down