Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: diffable model! #1676

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pyhf/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ def __init__(self, pdfconfig, batch_size=None):
if not parset.pdf_type == 'normal':
continue

normal_constraint_data.append(thisauxdata)
normal_constraint_data.append(default_backend.astensor(thisauxdata))

# many constraints are defined on a unit gaussian
# but we reserved the possibility that a paramset
# can define non-standard uncertainties. This is used
# by the paramset associated to staterror modifiers.
# Such parsets define a 'sigmas' attribute
try:
normal_constraint_sigmas.append(parset.sigmas)
normal_constraint_sigmas.append(default_backend.astensor(parset.sigmas))
except AttributeError:
normal_constraint_sigmas.append([1.0] * len(thisauxdata))
normal_constraint_sigmas.append(
default_backend.astensor([1.0] * len(thisauxdata))
)

self._normal_data = None
self._sigmas = None
Expand Down
8 changes: 7 additions & 1 deletion src/pyhf/modifiers/histosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ def __init__(self, config):
self.required_parsets = {}

def collect(self, thismod, nom):
default_backend = pyhf.default_backend
lo_data = thismod['data']['lo_data'] if thismod else nom
hi_data = thismod['data']['hi_data'] if thismod else nom
maskval = bool(thismod)
mask = [maskval] * len(nom)
return {'lo_data': lo_data, 'hi_data': hi_data, 'mask': mask, 'nom_data': nom}
return {
'lo_data': default_backend.astensor(lo_data),
'hi_data': default_backend.astensor(hi_data),
'mask': default_backend.astensor(mask, dtype='bool'),
'nom_data': default_backend.astensor(nom),
}

def append(self, key, channel, sample, thismod, defined_samp):
self.builder_data.setdefault(key, {}).setdefault(sample, {}).setdefault(
Expand Down
14 changes: 11 additions & 3 deletions src/pyhf/modifiers/shapefactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,17 @@ def __init__(self, modifiers, pdfconfig, builder_data, batch_size=None):
for m in keys
]

global_concatenated_bin_indices = [
[[j for c in pdfconfig.channels for j in range(pdfconfig.channel_nbins[c])]]
]
global_concatenated_bin_indices = default_backend.astensor(
[
[
[
j
for c in pdfconfig.channels
for j in range(pdfconfig.channel_nbins[c])
]
]
]
)

self._access_field = default_backend.tile(
global_concatenated_bin_indices,
Expand Down
14 changes: 11 additions & 3 deletions src/pyhf/modifiers/shapesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ def __init__(self, modifiers, pdfconfig, builder_data, batch_size=None):
for m in keys
]
)
global_concatenated_bin_indices = [
[[j for c in pdfconfig.channels for j in range(pdfconfig.channel_nbins[c])]]
]
global_concatenated_bin_indices = default_backend.astensor(
[
[
[
j
for c in pdfconfig.channels
for j in range(pdfconfig.channel_nbins[c])
]
]
]
)

self._access_field = default_backend.tile(
global_concatenated_bin_indices,
Expand Down
14 changes: 11 additions & 3 deletions src/pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ def __init__(self, modifiers, pdfconfig, builder_data, batch_size=None):
for m in keys
]
)
global_concatenated_bin_indices = [
[[j for c in pdfconfig.channels for j in range(pdfconfig.channel_nbins[c])]]
]
global_concatenated_bin_indices = default_backend.astensor(
[
[
[
j
for c in pdfconfig.channels
for j in range(pdfconfig.channel_nbins[c])
]
]
]
)

self._access_field = default_backend.tile(
global_concatenated_bin_indices,
Expand Down