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

Making n3fit use python pseudodata #1268

Merged
merged 5 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 7 additions & 4 deletions n3fit/src/n3fit/scripts/n3fit_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
actions_ = []
)

N3FIT_PROVIDERS = ["n3fit.performfit",
"validphys.results",
"validphys.n3fit_data",
"n3fit.n3fit_checks_provider"
N3FIT_PROVIDERS = [
"n3fit.performfit",
"n3fit.n3fit_checks_provider",
"validphys.results",
"validphys.n3fit_data",
"validphys.pseudodata",
"validphys.commondata",
]

log = logging.getLogger(__name__)
Expand Down
109 changes: 79 additions & 30 deletions n3fit/src/n3fit/tests/regressions/quickcard_1.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,97 @@
{
"preprocessing": "",
"preprocessing": [
{
"fl": "sng",
"smallx": 1.1519856452941895,
"largex": 2.635816812515259,
"trainable": true
},
{
"fl": "g",
"smallx": 1.1843736171722412,
"largex": 1.5618072748184204,
"trainable": true
},
{
"fl": "v",
"smallx": 0.5399999022483826,
"largex": 2.0055015087127686,
"trainable": true
},
{
"fl": "v3",
"smallx": 0.3049614429473877,
"largex": 2.6231420040130615,
"trainable": true
},
{
"fl": "v8",
"smallx": 0.5784729719161987,
"largex": 2.1212551593780518,
"trainable": true
},
{
"fl": "t3",
"smallx": 1.3452119827270508,
"largex": 1.7576805353164673,
"trainable": true
},
{
"fl": "t8",
"smallx": 1.0689963102340698,
"largex": 1.9449496269226074,
"trainable": true
},
{
"fl": "cp",
"smallx": 0.741088330745697,
"largex": 3.4628548622131348,
"trainable": true
}
],
"stop_epoch": 1000,
"best_epoch": 1000,
"erf_tr": 33.213114420572914,
"erf_vl": 28.218009317727912,
"chi2": 21.431137768190297,
"erf_tr": 35.36870388454861,
"erf_vl": 29.485028718647204,
"chi2": 21.601274632695894,
"pos_state": "POS_VETO",
"arc_lengths": [
1.1068653239049326,
1.4953119558272292,
1.201799272013087,
1.4270234891345712,
1.1920037459864075
1.1068650193928187,
1.495362525909499,
1.2016360471427414,
1.417299567086602,
1.1920902042035828
],
"integrability": [
0.0026635357935483883,
0.0026635357935447246,
0.00014161983198945904,
5.059403657913208,
0.00397586848703213
0.002665607098606748,
0.002665607098605749,
0.00013836964808366936,
5.058645844459534,
0.0039739306957948806
],
"timing": {
"walltime": {
"Total": 14.067598581314087,
"Total": 41.31889986991882,
"start": 0.0,
"data_loaded": 0.3445882797241211,
"replica_set": 0.34477806091308594,
"replica_fitted": 14.066914319992065,
"replica_set_to_replica_fitted": 13.72213625907898
"data_loaded": 0.033830881118774414,
"replica_set": 0.03406381607055664,
"replica_fitted": 41.31194734573364,
"replica_set_to_replica_fitted": 41.277883529663086
},
"cputime": {
"Total": 15.760098933,
"Total": 41.987736192999996,
"start": 0.0,
"data_loaded": 1.3225217320000002,
"replica_set": 1.3239677300000001,
"replica_fitted": 15.759413147999998,
"replica_set_to_replica_fitted": 14.435445417999999
"data_loaded": 0.020405508000000516,
"replica_set": 0.020640056000000406,
"replica_fitted": 41.984591997,
"replica_set_to_replica_fitted": 41.963951941000005
}
},
"version": {
"keras": "2.4.0",
"tensorflow": "2.3.1, mkl=False",
"numpy": "1.18.5",
"nnpdf": "3.5.1439+g47c1a11a6-dev",
"validphys": "3.5.1439+g47c1a11a6-dev"
"keras": "2.3.0-tf",
"tensorflow": "2.2.0, mkl=False",
"numpy": "1.19.1",
"nnpdf": "4.0.1.316+gf0c7b34",
"validphys": "4.0.1.316+gf0c7b34"
}
}
}
111 changes: 80 additions & 31 deletions n3fit/src/n3fit/tests/regressions/quickcard_2.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,97 @@
{
"preprocessing": "",
"preprocessing": [
{
"fl": "sng",
"smallx": 1.102711796760559,
"largex": 2.700000047683716,
"trainable": true
},
{
"fl": "g",
"smallx": 0.9399998784065247,
"largex": 1.6224322319030762,
"trainable": true
},
{
"fl": "v",
"smallx": 0.7402178645133972,
"largex": 1.7066106796264648,
"trainable": true
},
{
"fl": "v3",
"smallx": 0.21739234030246735,
"largex": 1.3615831136703491,
"trainable": true
},
{
"fl": "v8",
"smallx": 0.7599998712539673,
"largex": 2.411074161529541,
"trainable": true
},
{
"fl": "t3",
"smallx": 1.4385331869125366,
"largex": 2.29486083984375,
"trainable": true
},
{
"fl": "t8",
"smallx": 1.0592598915100098,
"largex": 1.7743843793869019,
"trainable": true
},
{
"fl": "cp",
"smallx": 0.22786737978458405,
"largex": 2.78507661819458,
"trainable": true
}
],
"stop_epoch": 1000,
"best_epoch": 998,
"erf_tr": 2.606570236771195,
"erf_vl": 3.0318090969458558,
"chi2": 1.5918478894589552,
"best_epoch": 999,
"erf_tr": 2.491444057888455,
"erf_vl": 2.8942466391656634,
"chi2": 1.6324648501268073,
"pos_state": "POS_PASS",
"arc_lengths": [
1.931689594079703,
1.697054671644156,
1.1340829034892161,
32.891455584502694,
1.1119670640240853
1.9364193786789174,
1.5682913617806982,
1.1399297208463033,
31.118964175987294,
1.1057977439528737
],
"integrability": [
0.02683432819322168,
0.026834328193217516,
0.0004258475692022756,
20.328540325164795,
0.028318760450927627
0.02547394391149188,
0.025473943911492936,
0.00041527650682848805,
19.97365140914917,
0.02800018619745881
],
"timing": {
"walltime": {
"Total": 16.93633460998535,
"Total": 43.86756992340088,
"start": 0.0,
"data_loaded": 0.34407711029052734,
"replica_set": 0.3442709445953369,
"replica_fitted": 16.935593366622925,
"replica_set_to_replica_fitted": 16.591322422027588
"data_loaded": 0.03478097915649414,
"replica_set": 0.035103559494018555,
"replica_fitted": 43.86035966873169,
"replica_set_to_replica_fitted": 43.82525610923767
},
"cputime": {
"Total": 18.655240567,
"Total": 44.583864212,
"start": 0.0,
"data_loaded": 1.317259243,
"replica_set": 1.3187306250000002,
"replica_fitted": 18.65449747,
"replica_set_to_replica_fitted": 17.335766845000002
"data_loaded": 0.01997594100000022,
"replica_set": 0.020298879999999464,
"replica_fitted": 44.580285373,
"replica_set_to_replica_fitted": 44.559986493000004
}
},
"version": {
"keras": "2.4.0",
"tensorflow": "2.3.1, mkl=False",
"numpy": "1.18.5",
"nnpdf": "3.5.1439+g47c1a11a6-dev",
"validphys": "3.5.1439+g47c1a11a6-dev"
"keras": "2.3.0-tf",
"tensorflow": "2.2.0, mkl=False",
"numpy": "1.19.1",
"nnpdf": "4.0.1.316+gf0c7b34-dev",
"validphys": "4.0.1.316+gf0c7b34-dev"
}
}
}
4 changes: 2 additions & 2 deletions validphys2/src/validphys/n3fit_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def generate_data_replica(data, replica_mcseed):

def fitting_data_dict(
data,
generate_data_replica,
make_replica,
tr_masks,
kfold_masks,
t0set=None,
Expand Down Expand Up @@ -258,7 +258,7 @@ def fitting_data_dict(
t0pdfset = t0set.load_t0()
spec_c.SetT0(t0pdfset)

expdata = generate_data_replica
expdata = make_replica

datasets = common_data_reader_experiment(spec_c, data)

Expand Down
4 changes: 2 additions & 2 deletions validphys2/src/validphys/pseudodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def read_fit_pseudodata(fitcontext, context_index):
return data_indices_list


def make_replica(dataset_inputs_loaded_cd_with_cuts, seed=None):
def make_replica(dataset_inputs_loaded_cd_with_cuts, replica_mcseed):
"""Function that takes in a list of :py:class:`validphys.coredata.CommonData`
objects and returns a pseudodata replica accounting for
possible correlations between systematic uncertainties.
Expand Down Expand Up @@ -153,7 +153,7 @@ def make_replica(dataset_inputs_loaded_cd_with_cuts, seed=None):
0.34843355, 0.34730928, 0.3090914 , 0.32825111, 0.3485292 ,
"""
# Seed the numpy RNG with the seed.
rng = np.random.default_rng(seed=seed)
rng = np.random.default_rng(seed=replica_mcseed)

# The inner while True loop is for ensuring a positive definite
# pseudodata replica
Expand Down
14 changes: 8 additions & 6 deletions validphys2/src/validphys/tests/test_pythonmakereplica.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from validphys.tests.test_covmats import CORR_DATA


SEED = 123456

SINGLE_SYS_DATASETS = [
{"dataset": "DYE886R"},
{"dataset": "D0ZRAP", "cfac": ["QCD"]},
Expand All @@ -42,7 +44,7 @@ def test_commondata_unchanged(data_config, dataset_inputs, use_cuts):
pre_mkrep_sys_tabs = [deepcopy(cd.systematics_table) for cd in ld_cds]
pre_mkrep_cd_tabs = [deepcopy(cd.commondata_table) for cd in ld_cds]

make_replica(ld_cds)
make_replica(ld_cds, SEED)

for post_mkrep_cd, pre_mkrep_cv in zip(ld_cds, pre_mkrep_cvs):
assert_series_equal(post_mkrep_cd.central_values, pre_mkrep_cv)
Expand All @@ -63,13 +65,12 @@ def test_pseudodata_seeding(data_config, dataset_inputs, use_cuts):
the random numbers are generated and used identically.

"""
seed = 123456
config = dict(data_config)
config["dataset_inputs"] = dataset_inputs
config["use_cuts"] = use_cuts
ld_cds = API.dataset_inputs_loaded_cd_with_cuts(**config)
rep_1 = make_replica(ld_cds, seed=seed)
rep_2 = make_replica(ld_cds, seed=seed)
config["replica_mcseed"] = SEED
rep_1 = API.make_replica(**config)
rep_2 = API.make_replica(**config)
np.testing.assert_allclose(rep_1, rep_2)


Expand All @@ -80,7 +81,8 @@ def test_pseudodata_has_correct_ndata(data_config, dataset_inputs, use_cuts):
config = dict(data_config)
config["dataset_inputs"] = dataset_inputs
config["use_cuts"] = use_cuts
config["replica_mcseed"] = SEED
ld_cds = API.dataset_inputs_loaded_cd_with_cuts(**config)
rep = make_replica(ld_cds)
rep = API.make_replica(**config)
ndata = np.sum([cd.ndata for cd in ld_cds])
assert len(rep) == ndata
2 changes: 1 addition & 1 deletion validphys2/src/validphys/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_mcreplica(data_config):
seed = 123456
# Use no cuts because if filter rules change in the
# future then this test will end up failing
rep = API.indexed_make_replica(**config, seed=seed)
rep = API.indexed_make_replica(**config, replica_mcseed=seed)
return rep


Expand Down