-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathconftest.py
More file actions
277 lines (206 loc) · 8.28 KB
/
conftest.py
File metadata and controls
277 lines (206 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
"""
conftest.py
Pytest fixtures.
"""
import contextlib
import pathlib
import sys
from hypothesis import settings
import pytest
# Adding this here to change the time of deadline from default (200ms) to 1500ms
settings.register_profile("extratime", deadline=1500)
settings.load_profile("extratime")
try:
import lhapdf
lhapdf.setVerbosity(0)
except ModuleNotFoundError:
pass
# Fortunately py.test works much like reportengine and providers are
# connected by argument names.
@pytest.fixture
def tmp(tmpdir):
"""A tempdir that is manipulated like pathlib Paths"""
return pathlib.Path(tmpdir)
# Here define the default config items like the PDF, theory and experiment specs
SINGLE_DATASET = {'dataset': 'HERA_NC_318GEV_EP-SIGMARED'}
SINGLE_DATAPOINT = {'dataset': 'ATLAS_Z0_13TEV_TOT', 'cfac': ['NRM']}
SINGLE_CATEGORICAL = {'dataset': 'ATLAS_WPWM_13TEV_TOT', 'cfac': ['NRM']}
DATA = [
SINGLE_DATASET,
{'dataset': 'ATLAS_TTBAR_7TEV_TOT_X-SEC', 'variant': 'legacy_theory'},
{'dataset': 'CMS_Z0J_8TEV_PT-Y', 'cfac': ['NRM'], 'variant': 'sys_10'},
# Explicitly put a CMS dataset between the two ATLAS
SINGLE_DATAPOINT,
]
SINGLE_EXP = [{'experiment': 'pseudo experiment', 'datasets': DATA[0:3]}]
WEIGHTED_DATA = [
{'dataset': 'NMC_NC_NOTFIXED_P_EM-SIGMARED', 'variant': 'legacy'},
{'dataset': 'NMC_NC_NOTFIXED_P_EM-SIGMARED', 'variant': 'legacy', 'weight': 100},
]
DATA_THCOVMAT = [
{'dataset': 'NMC_NC_NOTFIXED_P_EM-SIGMARED', 'variant': 'legacy'},
{'dataset': 'CHORUS_CC_NOTFIXED_PB_NU-SIGMARED', 'variant': 'legacy_dw'},
{'dataset': 'CMS_Z0J_8TEV_PT-Y', 'cfac': ['NRM'], 'variant': 'sys_10'},
{'dataset': 'ATLAS_WJ_8TEV_WP-PT'},
{'dataset': 'LHCB_Z0_8TEV_MUON_Y', 'cfac': ['NRM']},
]
POSITIVITIES = ["NNPDF_POS_2P24GEV_DYU", "NNPDF_POS_2P24GEV_F2S"]
PDF = "NNPDF40_nnlo_as_01180"
HESSIAN_PDF = "NNPDF40_nnlo_as_01180_hessian"
THEORYID = 40_000_000
THEORY_QED = 40_000_100
FIT_3REPLICAS = "FIT_3REPLICAS_250616"
FIT_3REPLICAS_DIAG = "FIT_3REPLICAS_251114"
FIT_3REPLICAS_DCUTS = "FIT_3REPLICAS_250616_diffcuts"
FIT = "NNPDF40_nnlo_like_CI_testing_250616"
FIT_ITERATED = "NNPDF40_nnlo_like_CI_testing_250616_iterated"
PSEUDODATA_FIT = "pseudodata_test_fit_n3fit_250616"
PSEUDODATA_FIT_DIAG = "pseudodata_test_fit_n3fit_251104"
# These fits contain _only_ data
MULTICLOSURE_FITS = ["250618-test-multiclosure-001", "250618-test-multiclosure-002"]
base_config = dict(
pdf=PDF, use_cuts='nocuts', use_t0_sampling=False, dataset_inputs=DATA, theoryid=THEORYID, Q=10
)
@pytest.fixture(scope='module')
def data_config():
return base_config
@pytest.fixture(scope='module')
def thcovmat_config(data_config):
"""Same as data_config but with additional info for the thcovmat production."""
new_config = dict(data_config)
new_config["use_cuts"] = "internal"
new_config.update(theoryid=THEORYID)
new_config.update(dataset_inputs=DATA_THCOVMAT)
return new_config
@pytest.fixture(scope='module')
def data_internal_cuts_config(data_config):
config_dict = dict(data_config)
config_dict.update(use_cuts='internal')
return config_dict
@pytest.fixture(scope='module')
def data_internal_cuts_closure_config(data_internal_cuts_config):
# Filterseed is not added so that it is changed by the tests
config = dict(data_internal_cuts_config)
config["fakepdf"] = PDF
return config
@pytest.fixture(scope='module')
def data_fromfit_cuts_config(data_internal_cuts_config):
config = dict(data_internal_cuts_config)
config.update(use_cuts="fromfit")
return config
@pytest.fixture(scope='module')
def single_data_internal_cuts_config(data_internal_cuts_config):
"""Like data_internal_cuts_config but for a single dataset"""
config_dict = dict(data_internal_cuts_config)
config_dict.pop("dataset_inputs")
config_dict.update(dataset_input=DATA[0])
return config_dict
@pytest.fixture(scope='module')
def single_data_categorical_internal_cuts_config(data_internal_cuts_config):
"""Test dataset with categorical plotting variables"""
return {**data_internal_cuts_config, 'dataset_input': SINGLE_CATEGORICAL, 'theoryid': THEORYID}
@pytest.fixture(scope='module')
def single_data_single_point_internal_cuts_config(single_data_internal_cuts_config):
config_dict = dict(single_data_internal_cuts_config)
config_dict.update(dataset_input=SINGLE_DATAPOINT)
return config_dict
@pytest.fixture(scope='module')
def data_witht0_config():
config_dict = dict(**base_config, use_t0=True, t0pdfset=PDF)
return config_dict
@pytest.fixture(scope='module')
def data_witht0_internal_cuts_config(data_witht0_config):
config_dict = dict(data_witht0_config)
config_dict.update(use_cuts='internal')
return config_dict
@pytest.fixture(scope='module')
def data_singleexp_witht0_config(data_witht0_config):
config_dict = dict(data_witht0_config)
config_dict.pop("dataset_inputs")
config_dict.update({'experiments': SINGLE_EXP})
config_dict.update(use_cuts='internal')
return config_dict
@pytest.fixture(scope='module')
def weighted_data_witht0_config(data_witht0_config):
config_dict = dict(data_witht0_config)
config_dict.update({'dataset_inputs': WEIGHTED_DATA})
return config_dict
@pytest.fixture(scope='module')
def weighted_data_witht0_internal_cuts_config(data_witht0_internal_cuts_config):
config_dict = dict(data_witht0_internal_cuts_config)
config_dict.update({'dataset_inputs': WEIGHTED_DATA})
return config_dict
@pytest.fixture(scope='module')
def fromfit_closure_config():
"""A configuration useful for closure test where everything is
read from the fit"""
config = {
"dataset_inputs": {"from_": "fit"},
"datacuts": {"from_": "fit"},
"use_cuts": "fromfit",
"fakepdf": {"from_": "closuretest"},
"theory": {"from_": "fit"},
"theoryid": {"from_": "theory"},
"pdf": {"from_": "fit"},
"closuretest": {"from_": "fit"},
"filterseed": {"from_": "closuretest"},
"use_fitcommondata": True,
"use_t0": True,
"t0pdfset": {"from_": "datacuts"},
}
return config
def pytest_runtest_setup(item):
ALL = {"darwin", "linux"}
supported_platforms = ALL.intersection(mark.name for mark in item.iter_markers())
plat = sys.platform
if supported_platforms and plat not in supported_platforms:
pytest.skip(f"cannot run on platform {plat}")
def pytest_configure(config):
config.addinivalue_line("markers", "linux: mark test to run only on linux")
@pytest.fixture(scope='module')
def flavour_basis_initial_scale_config():
"""Set the basis to ``flavour`` and fix ``Q`` to be 1.651, which is
about the initial scale at the point of creating this fixture.
In practice these values don't matter, but we will fix them here for the
sake of having stable tests.
"""
return {"basis": "flavour", "Q": 1.651}
@pytest.fixture(scope='module')
def mc_pdf_config(flavour_basis_initial_scale_config):
"""``flavour_basis_initial_scale_config`` with pdf set to be
a MC pdf
"""
return {"pdf": PDF, **flavour_basis_initial_scale_config}
@pytest.fixture(scope='module')
def hessian_pdf_config(flavour_basis_initial_scale_config):
"""``flavour_basis_initial_scale_config`` with pdf set to be
a hessian pdf
"""
return {"pdf": HESSIAN_PDF, **flavour_basis_initial_scale_config}
@pytest.fixture(scope='module')
def hessian_data_config(data_config):
"""Same as data config but with hessian PDF"""
new_config = dict(data_config)
new_config["pdf"] = HESSIAN_PDF
return new_config
@pytest.fixture(scope='module')
def hessian_data_internal_cuts_config(data_internal_cuts_config):
"""Same as data config but with hessian PDF"""
new_config = dict(data_internal_cuts_config)
new_config["pdf"] = HESSIAN_PDF
return new_config
@pytest.fixture(scope='module')
def hessian_single_data_internal_cuts_config(single_data_internal_cuts_config):
"""Same as single data config but with hessian PDF"""
new_config = dict(single_data_internal_cuts_config)
new_config["pdf"] = HESSIAN_PDF
return new_config
@contextlib.contextmanager
def temp_lhapdf_path(folder):
"""Modify the data path for LHAPDF sets"""
oldpaths = lhapdf.paths()
lhapdf.setPaths([str(folder)])
try:
yield
finally:
lhapdf.setPaths(oldpaths)