From 6ca6c8bd966453c17e1b08fab6237a0807161adf Mon Sep 17 00:00:00 2001 From: giacomomagni Date: Tue, 22 Oct 2024 12:10:04 +0200 Subject: [PATCH 1/5] fix tutorial --- doc/source/overview/tutorials/pdf.ipynb | 70 ++++++++++--------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/doc/source/overview/tutorials/pdf.ipynb b/doc/source/overview/tutorials/pdf.ipynb index bfc6ad3ad..38ddcd63d 100644 --- a/doc/source/overview/tutorials/pdf.ipynb +++ b/doc/source/overview/tutorials/pdf.ipynb @@ -74,7 +74,7 @@ "from ekobox.apply import apply_pdf\n", "\n", "with eko.EKO.read(\"./myeko.tar\") as evolution_operator:\n", - " evolved_pdfs = apply_pdf(evolution_operator, pdf)" + " evolved_pdfs, _integration_errors = apply_pdf(evolution_operator, pdf)" ] }, { @@ -82,7 +82,9 @@ "id": "0c2e752c-4a7c-4e2a-bd97-94f54907184a", "metadata": {}, "source": [ - "The returned object `evolved_pdfs` is a dictionary which maps the requested final scales onto further dictionaries:" + "The function returns two dictionaries, one filled with PDF values for each final scale (`evolved_pdfs`), \n", + "and the other containing the integration errors (`_integration_errors`). \n", + "Both of them have the same structure, for example, let's inspect `evolved_pdfs` :" ] }, { @@ -111,8 +113,8 @@ "id": "0ddf91bb-bc2c-4833-b624-32c5ac2d717a", "metadata": {}, "source": [ - "Each final scale contains a dictionary with a key `pdfs`, where all PDF values are hold, and a key `errors` , where the integration errors are hold.\n", - "Finally, inside each of those there is a mapping of Monte Carlo particle identifiers onto a the PDF value at the requested interpolation points.\n", + "Each final scale contains a dictionary, where all PDF values are hold.\n", + "Those are mapped with the Monte Carlo particle identifiers onto a the PDF value at the requested interpolation points.\n", "\n", "E.g. to access the gluon PDF at $Q^2 = 10000\\,\\text{GeV}^2$ you can run:" ] @@ -136,7 +138,7 @@ } ], "source": [ - "evolved_pdfs[(10000.0, 5)][\"pdfs\"][21]" + "evolved_pdfs[(10000.0, 5)][21]" ] }, { @@ -222,13 +224,6 @@ "id": "8c18c327", "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Overwriting old PDF installation\n" - ] - }, { "name": "stdout", "output_type": "stream", @@ -263,7 +258,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "LHAPDF 6.4.0 loading /home/felix/local/share/LHAPDF/Evolved_PDF/Evolved_PDF_0000.dat\n", + "LHAPDF 6.5.0 loading /Users/giacomomagni/.conda/envs/eko_dev/share/LHAPDF/Evolved_PDF/Evolved_PDF_0000.dat\n", "Evolved_PDF PDF set, member #0, version 1\n" ] } @@ -339,7 +334,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "LHAPDF 6.4.0 loading /home/felix/local/share/LHAPDF/CT14llo/CT14llo_0000.dat\n", + "LHAPDF 6.5.0 loading /Users/giacomomagni/.conda/envs/eko_dev/share/LHAPDF/CT14llo/CT14llo_0000.dat\n", "CT14llo PDF set, member #0, version 1; LHAPDF ID = 13205\n" ] } @@ -384,17 +379,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 22, "id": "05b81dca", "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Overwriting old PDF installation\n" - ] - }, { "name": "stdout", "output_type": "stream", @@ -424,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 23, "id": "2b02aab1", "metadata": {}, "outputs": [ @@ -432,34 +420,34 @@ "name": "stdout", "output_type": "stream", "text": [ - "LHAPDF 6.4.0 loading /home/felix/local/share/LHAPDF/my_ct14llo/my_ct14llo_0000.dat\n", - "my_ct14llo PDF set, member #0, version 1\n", + "LHAPDF 6.5.0 loading /Users/giacomomagni/.conda/envs/eko_dev/share/LHAPDF/my_ct14llo/my_ct14llo_0000.dat\n", " x Q2 ct14llo my_ct14llo relative_diff\n", - "0 0.000010 25.000000 7.635785e+01 7.630719e+01 0.000663\n", - "1 0.000173 25.000000 3.194273e+01 3.192239e+01 0.000637\n", - "2 0.003000 25.000000 1.081843e+01 1.081160e+01 0.000632\n", + "0 0.000010 25.000000 7.635785e+01 7.630727e+01 0.000662\n", + "1 0.000173 25.000000 3.194273e+01 3.192242e+01 0.000636\n", + "2 0.003000 25.000000 1.081843e+01 1.081161e+01 0.000631\n", "3 0.051962 25.000000 1.958956e+00 1.958820e+00 0.000069\n", - "4 0.900000 25.000000 1.922415e-05 1.955440e-05 -0.017179\n", - "5 0.000010 111.803399 1.333957e+02 1.333028e+02 0.000697\n", - "6 0.000173 111.803399 4.777286e+01 4.773855e+01 0.000718\n", + "4 0.900000 25.000000 1.922415e-05 1.955338e-05 -0.017126\n", + "5 0.000010 111.803399 1.333957e+02 1.333029e+02 0.000696\n", + "6 0.000173 111.803399 4.777286e+01 4.773856e+01 0.000718\n", "7 0.003000 111.803399 1.341028e+01 1.340044e+01 0.000734\n", "8 0.051962 111.803399 1.978216e+00 1.978292e+00 -0.000038\n", - "9 0.900000 111.803399 6.644805e-06 6.756354e-06 -0.016787\n", - "10 0.000010 500.000000 1.967032e+02 1.965517e+02 0.000770\n", - "11 0.000173 500.000000 6.291393e+01 6.286327e+01 0.000805\n", + "9 0.900000 111.803399 6.644805e-06 6.754169e-06 -0.016459\n", + "10 0.000010 500.000000 1.967032e+02 1.965518e+02 0.000770\n", + "11 0.000173 500.000000 6.291393e+01 6.286326e+01 0.000805\n", "12 0.003000 500.000000 1.542347e+01 1.541073e+01 0.000826\n", "13 0.051962 500.000000 1.947465e+00 1.947532e+00 -0.000034\n", - "14 0.900000 500.000000 2.929060e-06 2.979511e-06 -0.017224\n", - "15 0.000010 2236.067977 2.633266e+02 2.631189e+02 0.000789\n", + "14 0.900000 500.000000 2.929060e-06 2.977019e-06 -0.016373\n", + "15 0.000010 2236.067977 2.633266e+02 2.631190e+02 0.000789\n", "16 0.000173 2236.067977 7.708540e+01 7.702204e+01 0.000822\n", "17 0.003000 2236.067977 1.700410e+01 1.699004e+01 0.000827\n", "18 0.051962 2236.067977 1.893923e+00 1.894094e+00 -0.000090\n", - "19 0.900000 2236.067977 1.544450e-06 1.572860e-06 -0.018395\n", - "20 0.000010 10000.000000 3.314097e+02 3.311450e+02 0.000799\n", - "21 0.000173 10000.000000 9.023010e+01 9.015576e+01 0.000824\n", - "22 0.003000 10000.000000 1.825934e+01 1.824477e+01 0.000798\n", + "19 0.900000 2236.067977 1.544450e-06 1.570506e-06 -0.016870\n", + "20 0.000010 10000.000000 3.314097e+02 3.311451e+02 0.000799\n", + "21 0.000173 10000.000000 9.023010e+01 9.015575e+01 0.000824\n", + "22 0.003000 10000.000000 1.825934e+01 1.824476e+01 0.000798\n", "23 0.051962 10000.000000 1.830992e+00 1.831291e+00 -0.000163\n", - "24 0.900000 10000.000000 9.288458e-07 9.463689e-07 -0.018866\n" + "24 0.900000 10000.000000 9.288458e-07 9.442889e-07 -0.016626\n", + "my_ct14llo PDF set, member #0, version 1\n" ] } ], From af7b39d4f0eba8fd9a0b98cb6ac28e3fa1cd9d06 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 15 Oct 2024 14:42:57 +0300 Subject: [PATCH 2/5] Rework ekobox.apply --- src/ekobox/apply.py | 61 ++++++++++----------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/src/ekobox/apply.py b/src/ekobox/apply.py index 09dad2d0f..e7932f54b 100644 --- a/src/ekobox/apply.py +++ b/src/ekobox/apply.py @@ -60,50 +60,6 @@ def apply_pdf( rotate_to_evolution_basis : if True rotate to evoluton basis - Returns - ------- - pdfs : - PDFs for the computed evolution points - errors : - Integration errors for PDFs for the computed evolution points - """ - # prepare post-process - qed = eko.theory_card.order[1] > 0 - flavor_rotation = None - labels = br.flavor_basis_pids - if rotate_to_evolution_basis: - if not qed: - flavor_rotation = br.rotate_flavor_to_evolution - labels = br.evol_basis_pids - else: - flavor_rotation = br.rotate_flavor_to_unified_evolution - labels = br.unified_evol_basis_pids - return apply_pdf_flavor(eko, lhapdf_like, labels, targetgrid, flavor_rotation) - - -def apply_pdf_flavor( - eko: EKO, - lhapdf_like, - flavor_labels: Sequence[int], - targetgrid: npt.ArrayLike = None, - flavor_rotation: npt.ArrayLike = None, -) -> tuple[LabeledPdfResult, LabeledErrorResult]: - """Apply all available operators to the input PDF. - - Parameters - ---------- - eko : - eko output object containing all informations - lhapdf_like : Any - object that provides an `xfxQ2` callable (as `lhapdf `_ - and :class:`ekomark.toyLH.toyPDF` do) (and thus is in flavor basis) - flavor_labels : - flavor names - targetgrid : - if given, interpolates to the targetgrid (instead of xgrid) - flavor_rotation : - if give, rotate in flavor space - Returns ------- pdfs : @@ -121,10 +77,19 @@ def apply_pdf_flavor( ) # apply grids, grid_errors = apply_grids(eko, input_pdfs[None, :]) - new_grids = rotate_result(eko, grids, flavor_labels, targetgrid, flavor_rotation) - new_errors = rotate_result( - eko, grid_errors, flavor_labels, targetgrid, flavor_rotation - ) + # post-process + qed = eko.theory_card.order[1] > 0 + flavor_rotation = None + labels = br.flavor_basis_pids + if rotate_to_evolution_basis: + if not qed: + flavor_rotation = br.rotate_flavor_to_evolution + labels = br.evol_basis_pids + else: + flavor_rotation = br.rotate_flavor_to_unified_evolution + labels = br.unified_evol_basis_pids + new_grids = rotate_result(eko, grids, labels, targetgrid, flavor_rotation) + new_errors = rotate_result(eko, grid_errors, labels, targetgrid, flavor_rotation) # unwrap the replica axis again pdfs: LabeledPdfResult = {} errors: LabeledErrorResult = {} From 12a8f49fbb55cb31f504ef1c72c0e7c321338340 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 15 Oct 2024 15:14:26 +0300 Subject: [PATCH 3/5] Fix evol_pdf From ee5e16f48ed89518264a36e8fd02cc655bac6787 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 15 Oct 2024 16:06:55 +0300 Subject: [PATCH 4/5] Adjust apply for ekomark --- src/ekobox/apply.py | 61 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/src/ekobox/apply.py b/src/ekobox/apply.py index e7932f54b..09dad2d0f 100644 --- a/src/ekobox/apply.py +++ b/src/ekobox/apply.py @@ -67,17 +67,7 @@ def apply_pdf( errors : Integration errors for PDFs for the computed evolution points """ - # create pdfs - input_pdfs = np.zeros((len(br.flavor_basis_pids), len(eko.xgrid))) - for j, pid in enumerate(br.flavor_basis_pids): - if not lhapdf_like.hasFlavor(pid): - continue - input_pdfs[j] = np.array( - [lhapdf_like.xfxQ2(pid, x, eko.mu20) / x for x in eko.xgrid.raw] - ) - # apply - grids, grid_errors = apply_grids(eko, input_pdfs[None, :]) - # post-process + # prepare post-process qed = eko.theory_card.order[1] > 0 flavor_rotation = None labels = br.flavor_basis_pids @@ -88,8 +78,53 @@ def apply_pdf( else: flavor_rotation = br.rotate_flavor_to_unified_evolution labels = br.unified_evol_basis_pids - new_grids = rotate_result(eko, grids, labels, targetgrid, flavor_rotation) - new_errors = rotate_result(eko, grid_errors, labels, targetgrid, flavor_rotation) + return apply_pdf_flavor(eko, lhapdf_like, labels, targetgrid, flavor_rotation) + + +def apply_pdf_flavor( + eko: EKO, + lhapdf_like, + flavor_labels: Sequence[int], + targetgrid: npt.ArrayLike = None, + flavor_rotation: npt.ArrayLike = None, +) -> tuple[LabeledPdfResult, LabeledErrorResult]: + """Apply all available operators to the input PDF. + + Parameters + ---------- + eko : + eko output object containing all informations + lhapdf_like : Any + object that provides an `xfxQ2` callable (as `lhapdf `_ + and :class:`ekomark.toyLH.toyPDF` do) (and thus is in flavor basis) + flavor_labels : + flavor names + targetgrid : + if given, interpolates to the targetgrid (instead of xgrid) + flavor_rotation : + if give, rotate in flavor space + + Returns + ------- + pdfs : + PDFs for the computed evolution points + errors : + Integration errors for PDFs for the computed evolution points + """ + # create pdfs + input_pdfs = np.zeros((len(br.flavor_basis_pids), len(eko.xgrid))) + for j, pid in enumerate(br.flavor_basis_pids): + if not lhapdf_like.hasFlavor(pid): + continue + input_pdfs[j] = np.array( + [lhapdf_like.xfxQ2(pid, x, eko.mu20) / x for x in eko.xgrid.raw] + ) + # apply + grids, grid_errors = apply_grids(eko, input_pdfs[None, :]) + new_grids = rotate_result(eko, grids, flavor_labels, targetgrid, flavor_rotation) + new_errors = rotate_result( + eko, grid_errors, flavor_labels, targetgrid, flavor_rotation + ) # unwrap the replica axis again pdfs: LabeledPdfResult = {} errors: LabeledErrorResult = {} From 0850e67ec0fe5509f2a42cf63a813bf984f5cd31 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Wed, 16 Oct 2024 10:09:57 +0300 Subject: [PATCH 5/5] Fix inv matching benchmark