NNPDF / nnpdf

An open-source machine learning framework for global analyses of parton distributions.
https://docs.nnpdf.science/
GNU General Public License v3.0
28 stars 6 forks source link

Avoid using resources at the module level #1761

Closed scarlehoff closed 1 year ago

scarlehoff commented 1 year ago

https://github.com/NNPDF/nnpdf/blob/7eb0c4eb67604a7d0b80f9a8ac075aab994904cc/validphys2/src/validphys/tests/photon/test_compute.py#L17

and here

https://github.com/NNPDF/nnpdf/blob/7eb0c4eb67604a7d0b80f9a8ac075aab994904cc/validphys2/src/validphys/tests/photon/test_structurefunctions.py#L10

For a quick fix it would be enough changing the FIATLUX_RUNCARD dictionary to something like

def generate_fiatlux_runcard():
    return {
        "luxset": PDFset(PDF),
        # check if "LUXqed17_plus_PDF4LHC15_nnlo_100" is installed
        "additional_errors": FallbackLoader().check_pdf("LUXqed17_plus_PDF4LHC15_nnlo_100"),
        "luxseed": 123456789,
        "eps_base": 1e-2,  # using low precision to speed up tests
    }

That way the resources won't be downloaded upon import but only if they are actually needed (i.e., when people run a test in which this will be used)

And similarly, the theory id can be put as an integer value in conftest.py and then called with API.theoryid(theoryid=THEORY_QED) every time it is needed.

niclaurenti commented 1 year ago

You mean that I should use a function also for generating the theoryID? Something like

def generate_theory():
    retrun API.theoryid(theoryid=THEORY_QED)
scarlehoff commented 1 year ago

tbh for the theory I would call directly API.theoryid(theoryid=THEORY_QED) inside the test functions.