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

Introduce inconsistent fit closure test data #2180

Merged
merged 20 commits into from
Feb 14, 2025

Conversation

comane
Copy link
Member

@comane comane commented Oct 17, 2024

Reimplements #1682

This pull request introduces a new class, InconsistentCommonData, to handle inconsistencies within closure tests and includes several related changes across multiple files. The most important changes include the addition of the new class, updates to the configuration parsing, and new filtering methods for handling inconsistent closure data.

New Class and Methods:

Configuration Updates:

Filtering Methods:

Testing:

  • validphys2/src/validphys/tests/test_inconsistent_ct.py: Added unit tests for InconsistentCommonData class methods, including tests for the getter and setter of systematic_errors, select_systype_table_indices, rescale_systematics, process_commondata, and export_uncertainties.

Benchmarking of Code

  • Test against old code to see whether we reproduce it, eg the same Ratio bias variance results.

Test 0.0

Test that an inconsistent ct fit (using the inconsistent closure test filter) with lambda = 1.0 gives the same results as a consistent closure test:

https://vp.nnpdf.science/VIdN_z0ETx6Ph0szzKLY0g==

Multiclosure Test

DIS multiclosure test with maximal lambda inconsistency parameter (lambda=0)

https://vp.nnpdf.science/idXftjIBTp6r2ufbFIhMaA==

Also note that for a single fit with the same L1 data

This is the type of agreement found between old and new branch for a DIS only inconsistent closure test with lambda = 0
https://vp.nnpdf.science/sH-C_csbTGCPCdEGFXj_1w==

Example of inconsistent closure test runcard:

inconsistent_data_settings:

  treatment_names: [MULT]
  names_uncertainties: [CORR, SPECIAL]

  inconsistent_datasets:
    - HERA_NC_318GEV_EM-SIGMARED
    - HERA_NC_251GEV_EP-SIGMARED
    - HERA_NC_300GEV_EP-SIGMARED
    - HERA_NC_318GEV_EP-SIGMARED

  sys_rescaling_factor: 0.0


closuretest:
  errorsize: 1.0
  fakedata: true
  inconsistent_fakedata: true
  fakenoise: true
  fakepdf: 210223-mw-000_fakepdf
  filterseed: 1
  printpdf4gen: false
  rancutmethod: 0
  rancutprob: 1.0
  rancuttrnval: false

datacuts:
  q2min: 3.49
  t0pdfset: 210223-mw-000_fakepdf
  use_cuts: internal
  w2min: 12.5

dataset_inputs:
- dataset: NMCPD_dw_ite
  frac: 0.75
- dataset: SLACP_dwsh
  frac: 0.75
- dataset: SLACD_dw_ite
  frac: 0.75
- dataset: BCDMSP_dwsh
  frac: 0.75
- dataset: BCDMSD_dw_ite
  frac: 0.75
- dataset: CHORUSNUPb_dw_ite
  frac: 0.75
- dataset: CHORUSNBPb_dw_ite
  frac: 0.75
- cfac:
  - MAS
  dataset: NTVNUDMNFe_dw_ite
  frac: 0.75
- dataset: HERACOMBNCEM
  frac: 0.75
- dataset: HERACOMBNCEP575
  frac: 0.75
- dataset: HERACOMBNCEP820
  frac: 0.75
- dataset: HERACOMBNCEP920
  frac: 0.75
- dataset: HERACOMBCCEP
  frac: 0.75
- dataset: HERACOMB_SIGMARED_C
  frac: 0.75

debug: false

description: DIS only data. Some datasets (see partition) are left out of the fit.
  Partition is chosen as in NNPDF40_hyperopt. An inconsistency of type 2 is introduced
  for some of the in-sample datasets, namely all of the HERA NC ones.

fitting:
  savepseudodata: true
  basis:
  - fl: sng
    largex:
    - 1.498
    - 3.138
    smallx:
    - 1.121
    - 1.154
    trainable: false
  - fl: g
    largex:
    - 3.266
    - 6.214
    smallx:
    - 0.9224
    - 1.149
    trainable: false
  - fl: v
    largex:
    - 1.6
    - 3.588
    smallx:
    - 0.5279
    - 0.8017
    trainable: false
  - fl: v3
    largex:
    - 1.761
    - 3.427
    smallx:
    - 0.2011
    - 0.4374
    trainable: false
  - fl: v8
    largex:
    - 1.589
    - 3.378
    smallx:
    - 0.5775
    - 0.8357
    trainable: false
  - fl: t3
    largex:
    - 1.763
    - 3.397
    smallx:
    - -0.484
    - 1.0
    trainable: false
  - fl: t8
    largex:
    - 1.572
    - 3.496
    smallx:
    - 0.6714
    - 0.9197
    trainable: false
  - fl: t15
    largex:
    - 1.503
    - 3.636
    smallx:
    - 1.073
    - 1.164
    trainable: false
  fitbasis: EVOL

genrep: true

integrability:
  integdatasets:
  - dataset: INTEGXT8
    maxlambda: 1e2
  - dataset: INTEGXT3
    maxlambda: 1e2

maxcores: 4
mcseed: 75955222
nnseed: 2080989803

parameters:
  activation_per_layer:
  - tanh
  - tanh
  - linear
  dropout: 0.0
  epochs: 17000
  initializer: glorot_normal
  integrability:
    initial: 10
    multiplier: null
  layer_type: dense
  nodes_per_layer:
  - 25
  - 20
  - 8
  optimizer:
    clipnorm: 6.073e-06
    learning_rate: 0.002621
    optimizer_name: Nadam
  positivity:
    initial: 184.8
    multiplier: null
  stopping_patience: 0.1
  threshold_chi2: 3.5
positivity:
  posdatasets:
  - dataset: POSF2U
    maxlambda: 1e6
  - dataset: POSF2DW
    maxlambda: 1e6
  - dataset: POSF2S
    maxlambda: 1e6
  - dataset: POSFLL
    maxlambda: 1e6
  - dataset: POSDYU
    maxlambda: 1e10
  - dataset: POSDYD
    maxlambda: 1e10
  - dataset: POSDYS
    maxlambda: 1e10
  - dataset: POSF2C
    maxlambda: 1e6
  - dataset: POSXUQ
    maxlambda: 1e6
  - dataset: POSXUB
    maxlambda: 1e6
  - dataset: POSXDQ
    maxlambda: 1e6
  - dataset: POSXDB
    maxlambda: 1e6
  - dataset: POSXSQ
    maxlambda: 1e6
  - dataset: POSXSB
    maxlambda: 1e6
  - dataset: POSXGL
    maxlambda: 1e6

save: weights.h5

theory:
  theoryid: 200
trvlseed: 376191634

@comane comane force-pushed the introduce_inconsistent_fit_data branch 3 times, most recently from 36371a3 to 809dd6d Compare October 20, 2024 12:01
@scarlehoff
Copy link
Member

This is the type of agreement found between old and new branch for a DIS only inconsistent closure test with lambda = 0
https://vp.nnpdf.science/sH-C_csbTGCPCdEGFXj_1w==

I also used parallel_models: true for the new fit. Is this compatible with the type of agreement that is found between standard runned fits and parallel_models run fits? (@scarlehoff)

I would need to see chi2 / distances / etc. By running in parallel the seeding might happen differently at some stage but the initialization (if everything goes well) should be equivalent.

By eye they look too different to me, but if all metrics are very close it could well be a random fluctuation.

@RoyStegeman
Copy link
Member

Looking at the plots I share @scarlehoff's impression, but indeed a full compare report including chi2s and distances would be needed to say it more conclusively.

From Stefano's comments during the PC I have the impression that the paper is about to be finished, so I think this PR deserves some priority. It would be very good to have this merged before the paper is on arxiv, because otherwise I'm afraid it may never happen.

@comane
Copy link
Member Author

comane commented Feb 13, 2025

@scarlehoff , @RoyStegeman , and @giovannidecrescenzo

I have tested this module by running a multiclosure test for the DIS bulk inconsistency scenario with an inconsistency parameter lambda = 0.
The results (see report below) seem to be in good agreement with what we find with the other branch and also have in the paper draft.

Because of this I think that this branch is ready to be merged

https://vp.nnpdf.science/idXftjIBTp6r2ufbFIhMaA==

Copy link
Member

@scarlehoff scarlehoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I've left a few comments, mostly related to reducing the reach of the changes inside validphys (I think the more funcionality is shared the better it will be for future maintainability).

Other than that it looks good I think.

inconsistent_data_settings,
):
"""
Same as _filter_closure_data, but for inconsistent closure tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add when / what makes the difference with respect to _filter_closure_data.

I think that, since this an internal function (where all the funcionality is) and not an action, it would be greatly benefitial to have the functionality inside _filter_closure_data with a switch (it is probably enough to check whether inconsistent_data_settings is None.

Something like adding:

if inconsistent_data_settings is not None:
       # Modify the closure data adding inconsistencies.
       closure_data = [
             InconsistentCommonData(
                 setname=cd.setname,
                 ndata=cd.ndata,
                 commondataproc=cd.commondataproc,
                 nkin=cd.nkin,
                 nsys=cd.nsys,
                 commondata_table=cd.commondata_table,
                 systype_table=cd.systype_table,
             )
             for cd in closure_data
         ]

directly to _filter_closure_data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't completely agree on this. the function is internal and used as an explicit node by the config module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the one used as a node is filter_inconsistent_closure_data_by_experiment, I mean _filter_closure_data and _filter_inconsistent_closure_data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry meant that one.
What I mean is that I don't understand why you want
filter_inconsistent_closure_data_by_experiment
to be calling the same internal function as
filter_closure_data_by_experiment

they are two separate things and this only adds one extra function (_filter_inconsistent_closure_data )
to filters.
The advantage, in my opinion, is that _filter_closure_data does not become to large as a function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if anything changes in how _filter_closure_data behaves now you have to change two functions instead of one.
Or worse, someone down the line will change something in _filter_closure_data and will forget that the inconsistent one has to be changed in the same way and both functions will drift away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to say I agree with this. _filtere_inconsistent_closure_data is an extension of _filter_closure_data that still seems to make use of all of the original functionality so making it two separate functions is not ideal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think there are at least two ways of doing this
I can either leave two separate nodes filter_inconsistent_closure_data_by_experiment and filter_closure_data_by_experiment and let the explicit node deal with them, or reduce even those.

I am actually favourable to having the two separate nodes and a rule in config that depends on whether inconsistent_fakedata has been set True.
This would avoid running inconsistent closure tests in the case in which one has forgotten inconsistent_data_settings in the runcard.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had quick comment: as of now we are disregarding the option to generate lvl1 data "inconsistently" in the sense that we do not have anymore the option to vary the generation of lvl 1 data, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is what you refer here what we used to call type 2 inconsistency?

If so, we never used this and it is not in the paper.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly, just to be sure

@comane comane force-pushed the introduce_inconsistent_fit_data branch from 809dd6d to 2072d85 Compare February 13, 2025 12:33
Copy link
Member

@RoyStegeman RoyStegeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I don't have much to add to JCM's comments.

Please add documentation

inconsistent_data_settings,
):
"""
Same as _filter_closure_data, but for inconsistent closure tests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to say I agree with this. _filtere_inconsistent_closure_data is an extension of _filter_closure_data that still seems to make use of all of the original functionality so making it two separate functions is not ideal.

@comane
Copy link
Member Author

comane commented Feb 14, 2025

@scarlehoff, @RoyStegeman If you are happy with the current state of this PR, I would suggest merging it.

Copy link
Member

@scarlehoff scarlehoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It might be nice to refer to the paper once it is out in the docstr for context.

Just a last nitpic, did you use pre-commit? I think isort would've picked up some of the issues (you can just touch the files, then git add them and do precommit, otherwise just run isort on all of them -also the test-).

@comane
Copy link
Member Author

comane commented Feb 14, 2025

Thanks for all the comments, they should all have been addressed

@comane comane merged commit 9e82a95 into master Feb 14, 2025
9 checks passed
@comane comane deleted the introduce_inconsistent_fit_data branch February 14, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants