Skip to content

Commit

Permalink
edit makers to use new default backend syntax in my pyhf fork
Browse files Browse the repository at this point in the history
  • Loading branch information
phinate committed Nov 30, 2020
1 parent 196ccf9 commit 68a7e32
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 58 deletions.
Binary file added docs/assets/2_model_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/makers.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ <h2 id="statistical-models">statistical models<a class="anchor-link" href="#stat


<div class="output_markdown rendered_html output_subarea ">
<h4 id="hepdata_like_from_hists" class="doc_header"><code>hepdata_like_from_hists</code><a href="https://github.com/gradhep/neos/neos/makers.py#L266" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>hepdata_like_from_hists</code>(<strong><code>histogram_maker</code></strong>)</p>
<h4 id="hepdata_like_from_hists" class="doc_header"><code>hepdata_like_from_hists</code><a href="https://github.com/gradhep/neos/neos/makers.py#L265" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>hepdata_like_from_hists</code>(<strong><code>histogram_maker</code></strong>)</p>
</blockquote>
<p>Returns a function that constructs a typical 'hepdata-like' statistical
model with signal, background, and background uncertainty yields when
Expand Down Expand Up @@ -358,7 +358,7 @@ <h3 id="Usage:">Usage:<a class="anchor-link" href="#Usage:"> </a></h3>


<div class="output_markdown rendered_html output_subarea ">
<h4 id="histosys_model_from_hists" class="doc_header"><code>histosys_model_from_hists</code><a href="https://github.com/gradhep/neos/neos/makers.py#L292" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>histosys_model_from_hists</code>(<strong><code>histogram_maker</code></strong>)</p>
<h4 id="histosys_model_from_hists" class="doc_header"><code>histosys_model_from_hists</code><a href="https://github.com/gradhep/neos/neos/makers.py#L291" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>histosys_model_from_hists</code>(<strong><code>histogram_maker</code></strong>)</p>
</blockquote>
<p>Returns a function that constructs a HEP statistical model using a
'histosys' uncertainty for the background (nominal background, up and down
Expand Down
30 changes: 2 additions & 28 deletions nbs/02_makers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,12 @@
"outputs": [],
"source": [
"#export\n",
"import sys\n",
"from unittest.mock import patch\n",
"\n",
"import pyhf\n",
"\n",
"jax_backend = pyhf.tensor.jax_backend(precision=\"64b\")\n",
"pyhf.set_backend(jax_backend)\n",
"pyhf.set_backend(jax_backend, default=True)\n",
"\n",
"from neos.models import hepdata_like"
]
Expand Down Expand Up @@ -526,32 +525,7 @@
" background-only parameters for use in downstream inference.\n",
" \"\"\"\n",
"\n",
" # bunch of patches to make sure we use jax in pyhf\n",
" @patch(\"pyhf.default_backend\", new=jax_backend)\n",
" @patch.object(\n",
" sys.modules[\"pyhf.interpolators.code0\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.interpolators.code1\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.interpolators.code2\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.interpolators.code4\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.interpolators.code4p\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.modifiers.shapefactor\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.modifiers.shapesys\"], \"default_backend\", new=jax_backend\n",
" )\n",
" @patch.object(\n",
" sys.modules[\"pyhf.modifiers.staterror\"], \"default_backend\", new=jax_backend\n",
" )\n",
"\n",
" def from_spec(yields):\n",
"\n",
" s, b, bup, bdown = yields\n",
Expand Down
30 changes: 2 additions & 28 deletions neos/makers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,12 @@ def hist_maker(hm_params):


# Cell
import sys
from unittest.mock import patch

import pyhf

jax_backend = pyhf.tensor.jax_backend(precision="64b")
pyhf.set_backend(jax_backend)
pyhf.set_backend(jax_backend, default=True)

from .models import hepdata_like

Expand Down Expand Up @@ -304,32 +303,7 @@ def histosys_model_from_hists(histogram_maker):
background-only parameters for use in downstream inference.
"""

# bunch of patches to make sure we use jax in pyhf
@patch("pyhf.default_backend", new=jax_backend)
@patch.object(
sys.modules["pyhf.interpolators.code0"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.interpolators.code1"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.interpolators.code2"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.interpolators.code4"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.interpolators.code4p"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.modifiers.shapefactor"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.modifiers.shapesys"], "default_backend", new=jax_backend
)
@patch.object(
sys.modules["pyhf.modifiers.staterror"], "default_backend", new=jax_backend
)

def from_spec(yields):

s, b, bup, bdown = yields
Expand Down

0 comments on commit 68a7e32

Please sign in to comment.