From 359bb6e17e2b9ae67be156935261f2bd266f1342 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Fri, 19 Jul 2024 12:33:25 +0300 Subject: [PATCH 1/9] rust: Recover SV --- src/eko/evolution_operator/__init__.py.patch | 6 +++--- .../operator_matrix_element.py.patch | 5 ++--- src/eko/evolution_operator/quad_ker.py | 20 +++++++++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/eko/evolution_operator/__init__.py.patch b/src/eko/evolution_operator/__init__.py.patch index 169fa2eca..10f75df85 100644 --- a/src/eko/evolution_operator/__init__.py.patch +++ b/src/eko/evolution_operator/__init__.py.patch @@ -1,5 +1,5 @@ diff --git a/src/eko/evolution_operator/__init__.py b/src/eko/evolution_operator/__init__.py -index 1c759c5c..3cf678f2 100644 +index 1c759c5c..5ff2d867 100644 --- a/src/eko/evolution_operator/__init__.py +++ b/src/eko/evolution_operator/__init__.py @@ -3,15 +3,15 @@ r"""Contains the central operator classes. @@ -621,11 +621,11 @@ index 1c759c5c..3cf678f2 100644 + cfg.nf = self.nf + cfg.is_log = self.int_disp.log + cfg.logx = logx -+ cfg.L = np.log(self.xif2) ++ cfg.Lsv = np.log(self.xif2) + cfg.method_num = 1 + cfg.ev_op_iterations = self.config["ev_op_iterations"] + cfg.ev_op_max_order_qcd = self.config["ev_op_max_order"][0] -+ cfg.sv_mode_num = 1 ++ cfg.sv_mode_num = self.sv_mode + cfg.is_threshold = self.is_threshold + self.update_cfg(cfg) + diff --git a/src/eko/evolution_operator/operator_matrix_element.py.patch b/src/eko/evolution_operator/operator_matrix_element.py.patch index 2b8af09aa..d00feb1e4 100644 --- a/src/eko/evolution_operator/operator_matrix_element.py.patch +++ b/src/eko/evolution_operator/operator_matrix_element.py.patch @@ -1,5 +1,5 @@ diff --git a/src/eko/evolution_operator/operator_matrix_element.py b/src/eko/evolution_operator/operator_matrix_element.py -index 202fd18d..3e24870d 100644 +index 202fd18d..5f53858d 100644 --- a/src/eko/evolution_operator/operator_matrix_element.py +++ b/src/eko/evolution_operator/operator_matrix_element.py @@ -1,11 +1,13 @@ @@ -143,7 +143,7 @@ index 202fd18d..3e24870d 100644 class OperatorMatrixElement(Operator): r""" Internal representation of a single |OME|. -@@ -267,41 +168,14 @@ class OperatorMatrixElement(Operator): +@@ -267,41 +168,13 @@ class OperatorMatrixElement(Operator): ) return labels @@ -189,7 +189,6 @@ index 202fd18d..3e24870d 100644 + cfg.L = self.L + cfg.as1 = self.a_s + cfg.as0 = 0. -+ cfg.Lsv = np.log(self.xif2) @property def a_s(self): diff --git a/src/eko/evolution_operator/quad_ker.py b/src/eko/evolution_operator/quad_ker.py index 165192c77..c384eb1ed 100644 --- a/src/eko/evolution_operator/quad_ker.py +++ b/src/eko/evolution_operator/quad_ker.py @@ -88,15 +88,15 @@ def cb_quad_ker_qcd( areas_raw, areas_x, areas_y, - L, + _L, _method_num, as1, as0, ev_op_iterations, ev_op_max_order_qcd, - _sv_mode_num, + sv_mode, is_threshold, - _Lsv, + Lsv, ): """C Callback inside integration kernel.""" # recover complex variables @@ -107,7 +107,6 @@ def cb_quad_ker_qcd( pj = interpolation.evaluate_grid(n, is_log, logx, areas) # TODO recover parameters method = "iterate-exact" - sv_mode = sv.Modes.exponentiated order = (order_qcd, 0) ev_op_max_order = (ev_op_max_order_qcd, 0) if is_singlet: @@ -117,7 +116,7 @@ def cb_quad_ker_qcd( gamma_singlet = re_gamma_singlet + im_gamma_singlet * 1j if sv_mode == sv.Modes.exponentiated: gamma_singlet = sv.exponentiated.gamma_variation( - gamma_singlet, order, nf, L + gamma_singlet, order, nf, Lsv ) # construct eko ker = s.dispatcher( @@ -133,7 +132,7 @@ def cb_quad_ker_qcd( # scale var expanded is applied on the kernel if sv_mode == sv.Modes.expanded and not is_threshold: ker = np.ascontiguousarray( - sv.expanded.singlet_variation(gamma_singlet, as1, order, nf, L, dim=2) + sv.expanded.singlet_variation(gamma_singlet, as1, order, nf, Lsv, dim=2) ) @ np.ascontiguousarray(ker) ker = select_singlet_element(ker, mode0, mode1) else: @@ -142,7 +141,7 @@ def cb_quad_ker_qcd( im_gamma_ns = nb.carray(im_gamma_raw, order_qcd) gamma_ns = re_gamma_ns + im_gamma_ns * 1j if sv_mode == sv.Modes.exponentiated: - gamma_ns = sv.exponentiated.gamma_variation(gamma_ns, order, nf, L) + gamma_ns = sv.exponentiated.gamma_variation(gamma_ns, order, nf, Lsv) # construct eko ker = ns.dispatcher( order, @@ -154,7 +153,7 @@ def cb_quad_ker_qcd( ev_op_iterations, ) if sv_mode == sv.Modes.expanded and not is_threshold: - ker = sv.expanded.non_singlet_variation(gamma_ns, as1, order, nf, L) * ker + ker = sv.expanded.non_singlet_variation(gamma_ns, as1, order, nf, Lsv) * ker # recombine everything res = ker * pj * jac return np.real(res) @@ -241,7 +240,7 @@ def cb_quad_ker_ome( _as0, _ev_op_iterations, _ev_op_max_order_qcd, - _sv_mode_num, + sv_mode, _is_threshold, Lsv, ): @@ -253,7 +252,6 @@ def cb_quad_ker_ome( areas = nb.carray(areas_raw, (areas_x, areas_y)) pj = interpolation.evaluate_grid(n, is_log, logx, areas) # TODO recover parameters - sv_mode = sv.Modes.exponentiated order = (order_qcd, 0) if is_singlet: indices = {21: 0, 100: 1, 90: 2} @@ -273,7 +271,7 @@ def cb_quad_ker_ome( A = sv.exponentiated.gamma_variation(A, order, nf, Lsv) # TODO recover InversionMethod - backward_method = "" + backward_method = None # build the expansion in alpha_s depending on the strategy ker = build_ome(A, order, as1, backward_method) From ad063c5dbfc006adc7cb798c04299387287586ea Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Fri, 9 Aug 2024 15:28:50 +0300 Subject: [PATCH 2/9] rust: Fix ome patch --- src/eko/evolution_operator/operator_matrix_element.py.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eko/evolution_operator/operator_matrix_element.py.patch b/src/eko/evolution_operator/operator_matrix_element.py.patch index 22a8c3e6c..9b702557f 100644 --- a/src/eko/evolution_operator/operator_matrix_element.py.patch +++ b/src/eko/evolution_operator/operator_matrix_element.py.patch @@ -142,7 +142,7 @@ index 022f8073..017ec73d 100644 class OperatorMatrixElement(Operator): r""" Internal representation of a single |OME|. -@@ -291,41 +191,13 @@ class OperatorMatrixElement(Operator): +@@ -291,41 +191,14 @@ class OperatorMatrixElement(Operator): ) return labels From 25a3cdd38980848ee16779e81c2f8908ade2a9db Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Fri, 9 Aug 2024 15:40:04 +0300 Subject: [PATCH 3/9] rust: Pass ev/back method --- src/eko/evolution_operator/__init__.py.patch | 8 ++++---- .../operator_matrix_element.py.patch | 5 +++-- src/eko/evolution_operator/quad_ker.py | 12 ++++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/eko/evolution_operator/__init__.py.patch b/src/eko/evolution_operator/__init__.py.patch index 47c6f252e..0b4a996a3 100644 --- a/src/eko/evolution_operator/__init__.py.patch +++ b/src/eko/evolution_operator/__init__.py.patch @@ -1,5 +1,5 @@ diff --git a/src/eko/evolution_operator/__init__.py b/src/eko/evolution_operator/__init__.py -index fe07ade9..0f58c9e5 100644 +index fe07ade9..20c4539d 100644 --- a/src/eko/evolution_operator/__init__.py +++ b/src/eko/evolution_operator/__init__.py @@ -3,16 +3,16 @@ r"""Contains the central operator classes. @@ -588,7 +588,7 @@ index fe07ade9..0f58c9e5 100644 def initialize_op_members(self): """Init all operators with the identity or zeros.""" eye = OpMember( -@@ -858,10 +317,13 @@ class Operator(sv.ScaleVariationModeMixin): +@@ -858,10 +317,14 @@ class Operator(sv.ScaleVariationModeMixin): else: self.op_members[n] = zero.copy() @@ -601,12 +601,13 @@ index fe07ade9..0f58c9e5 100644 + cfg.as1 = self.as_list[1] + cfg.as0 = self.as_list[0] + cfg.py = ekors.ffi.cast("void *", cb_quad_ker_qcd.address) ++ cfg.method_num = self.ev_method + + def run_op_integration(self, log_grid): """Run the integration for each grid point. Parameters -@@ -876,18 +332,54 @@ class Operator(sv.ScaleVariationModeMixin): +@@ -876,18 +339,53 @@ class Operator(sv.ScaleVariationModeMixin): """ column = [] k, logx = log_grid @@ -622,7 +623,6 @@ index fe07ade9..0f58c9e5 100644 + cfg.is_log = self.int_disp.log + cfg.logx = logx + cfg.Lsv = np.log(self.xif2) -+ cfg.method_num = 1 + cfg.ev_op_iterations = self.config["ev_op_iterations"] + cfg.ev_op_max_order_qcd = self.config["ev_op_max_order"][0] + cfg.sv_mode_num = self.sv_mode diff --git a/src/eko/evolution_operator/operator_matrix_element.py.patch b/src/eko/evolution_operator/operator_matrix_element.py.patch index 9b702557f..643440ced 100644 --- a/src/eko/evolution_operator/operator_matrix_element.py.patch +++ b/src/eko/evolution_operator/operator_matrix_element.py.patch @@ -1,5 +1,5 @@ diff --git a/src/eko/evolution_operator/operator_matrix_element.py b/src/eko/evolution_operator/operator_matrix_element.py -index 022f8073..017ec73d 100644 +index 022f8073..f6b3235d 100644 --- a/src/eko/evolution_operator/operator_matrix_element.py +++ b/src/eko/evolution_operator/operator_matrix_element.py @@ -2,11 +2,12 @@ @@ -142,7 +142,7 @@ index 022f8073..017ec73d 100644 class OperatorMatrixElement(Operator): r""" Internal representation of a single |OME|. -@@ -291,41 +191,14 @@ class OperatorMatrixElement(Operator): +@@ -291,41 +191,15 @@ class OperatorMatrixElement(Operator): ) return labels @@ -189,6 +189,7 @@ index 022f8073..017ec73d 100644 + cfg.as1 = self.a_s + cfg.as0 = 0.0 + cfg.Lsv = np.log(self.xif2) ++ cfg.method_num = self.backward_method @property def a_s(self): diff --git a/src/eko/evolution_operator/quad_ker.py b/src/eko/evolution_operator/quad_ker.py index c384eb1ed..374f07c4c 100644 --- a/src/eko/evolution_operator/quad_ker.py +++ b/src/eko/evolution_operator/quad_ker.py @@ -89,7 +89,7 @@ def cb_quad_ker_qcd( areas_x, areas_y, _L, - _method_num, + method_num, as1, as0, ev_op_iterations, @@ -105,8 +105,7 @@ def cb_quad_ker_qcd( # combute basis functions areas = nb.carray(areas_raw, (areas_x, areas_y)) pj = interpolation.evaluate_grid(n, is_log, logx, areas) - # TODO recover parameters - method = "iterate-exact" + method = method_num order = (order_qcd, 0) ev_op_max_order = (ev_op_max_order_qcd, 0) if is_singlet: @@ -235,7 +234,7 @@ def cb_quad_ker_ome( areas_x, areas_y, L, - _method_num, + method_num, as1, _as0, _ev_op_iterations, @@ -251,7 +250,7 @@ def cb_quad_ker_ome( # compute basis functions areas = nb.carray(areas_raw, (areas_x, areas_y)) pj = interpolation.evaluate_grid(n, is_log, logx, areas) - # TODO recover parameters + backward_method = method_num order = (order_qcd, 0) if is_singlet: indices = {21: 0, 100: 1, 90: 2} @@ -270,9 +269,6 @@ def cb_quad_ker_ome( if sv_mode == sv.Modes.exponentiated: A = sv.exponentiated.gamma_variation(A, order, nf, Lsv) - # TODO recover InversionMethod - backward_method = None - # build the expansion in alpha_s depending on the strategy ker = build_ome(A, order, as1, backward_method) From 44afd2bf5ae7e15967444ef703d0e8b6629995d3 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Fri, 9 Aug 2024 15:57:05 +0300 Subject: [PATCH 4/9] rust: Avoid variable alias --- src/eko/evolution_operator/quad_ker.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/eko/evolution_operator/quad_ker.py b/src/eko/evolution_operator/quad_ker.py index 374f07c4c..032ed381a 100644 --- a/src/eko/evolution_operator/quad_ker.py +++ b/src/eko/evolution_operator/quad_ker.py @@ -89,7 +89,7 @@ def cb_quad_ker_qcd( areas_x, areas_y, _L, - method_num, + ev_method, as1, as0, ev_op_iterations, @@ -105,7 +105,6 @@ def cb_quad_ker_qcd( # combute basis functions areas = nb.carray(areas_raw, (areas_x, areas_y)) pj = interpolation.evaluate_grid(n, is_log, logx, areas) - method = method_num order = (order_qcd, 0) ev_op_max_order = (ev_op_max_order_qcd, 0) if is_singlet: @@ -120,7 +119,7 @@ def cb_quad_ker_qcd( # construct eko ker = s.dispatcher( order, - method, + ev_method, gamma_singlet, as1, as0, @@ -144,7 +143,7 @@ def cb_quad_ker_qcd( # construct eko ker = ns.dispatcher( order, - method, + ev_method, gamma_ns, as1, as0, @@ -234,7 +233,7 @@ def cb_quad_ker_ome( areas_x, areas_y, L, - method_num, + backward_method, as1, _as0, _ev_op_iterations, @@ -250,7 +249,6 @@ def cb_quad_ker_ome( # compute basis functions areas = nb.carray(areas_raw, (areas_x, areas_y)) pj = interpolation.evaluate_grid(n, is_log, logx, areas) - backward_method = method_num order = (order_qcd, 0) if is_singlet: indices = {21: 0, 100: 1, 90: 2} From 2ce11eb558811f1464f117491b17505ad624aab2 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Sep 2024 14:08:46 +0300 Subject: [PATCH 5/9] Add rusty LHA bot --- .github/workflows/lha_bot_rust.yml | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/lha_bot_rust.yml diff --git a/.github/workflows/lha_bot_rust.yml b/.github/workflows/lha_bot_rust.yml new file mode 100644 index 000000000..4155ae4d9 --- /dev/null +++ b/.github/workflows/lha_bot_rust.yml @@ -0,0 +1,46 @@ +# A single CI script with github workflow. +name: LHA Benchmarks (Rust) + +on: + push: + branches-ignore: + - "*" + tags: + pull_request: + types: + - closed + - ready_for_review + - review_requested + workflow_dispatch: + +jobs: + lhabench: + name: LHA paper Benchmarks + runs-on: ubuntu-latest + container: + image: ghcr.io/nnpdf/bench-evol:v2 + credentials: + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + with: + # tags needed for dynamic versioning + fetch-depth: 0 + - name: Install and configure Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: false + installer-parallel: true + - name: Install project + run: | + poetry install --no-interaction --with test -E mark -E box + - name: Install task runner + run: pip install poethepoet + - name: Run benchmark + run: | + ./rustify.sh + poe lha -m "nnlo and sv" + # TODO wait for polarized to reactivate + # poe lha -m "ffns_pol and sv" From 17d1bdce30e6ec4fe8dc7eae038dd94361171cde Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Sep 2024 14:15:00 +0300 Subject: [PATCH 6/9] Compile before LHA --- .github/workflows/lha_bot_rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lha_bot_rust.yml b/.github/workflows/lha_bot_rust.yml index 4155ae4d9..8a07ff047 100644 --- a/.github/workflows/lha_bot_rust.yml +++ b/.github/workflows/lha_bot_rust.yml @@ -41,6 +41,7 @@ jobs: - name: Run benchmark run: | ./rustify.sh + poe compile poe lha -m "nnlo and sv" # TODO wait for polarized to reactivate # poe lha -m "ffns_pol and sv" From 8b90da677f46a8bcd37edbe7d9b86cda9f4917da Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Sep 2024 14:18:51 +0300 Subject: [PATCH 7/9] Avoid container for rusty LHA --- .github/workflows/lha_bot_rust.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lha_bot_rust.yml b/.github/workflows/lha_bot_rust.yml index 8a07ff047..6bb1e063b 100644 --- a/.github/workflows/lha_bot_rust.yml +++ b/.github/workflows/lha_bot_rust.yml @@ -17,11 +17,11 @@ jobs: lhabench: name: LHA paper Benchmarks runs-on: ubuntu-latest - container: - image: ghcr.io/nnpdf/bench-evol:v2 - credentials: - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} + # container: + # image: ghcr.io/nnpdf/bench-evol:v2 + # credentials: + # username: ${{ github.repository_owner }} + # password: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 From f49f912a4bf473ae1726438a732b174e61574d7d Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Sep 2024 14:57:45 +0300 Subject: [PATCH 8/9] Install python in rusty LHA --- .github/workflows/lha_bot_rust.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lha_bot_rust.yml b/.github/workflows/lha_bot_rust.yml index 6bb1e063b..5de94c7e0 100644 --- a/.github/workflows/lha_bot_rust.yml +++ b/.github/workflows/lha_bot_rust.yml @@ -23,11 +23,21 @@ jobs: # username: ${{ github.repository_owner }} # password: ${{ secrets.GITHUB_TOKEN }} + strategy: + matrix: + python-version: ["3.12"] + fail-fast: false + steps: - uses: actions/checkout@v2 + # with: + # # tags needed for dynamic versioning + # fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} 🐍 + id: setup-python + uses: actions/setup-python@v5 with: - # tags needed for dynamic versioning - fetch-depth: 0 + python-version: ${{ matrix.python-version }} - name: Install and configure Poetry uses: snok/install-poetry@v1 with: From a124e22c9246dc196dab04c7dba4260aa05e2b03 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Sat, 21 Sep 2024 14:56:52 +0300 Subject: [PATCH 9/9] Fix ev_op/init patch --- src/eko/evolution_operator/__init__.py.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eko/evolution_operator/__init__.py.patch b/src/eko/evolution_operator/__init__.py.patch index bf6a0f803..a4951e687 100644 --- a/src/eko/evolution_operator/__init__.py.patch +++ b/src/eko/evolution_operator/__init__.py.patch @@ -605,7 +605,7 @@ index bd1b19d6..f543f7bc 100644 """Run the integration for each grid point. Parameters -@@ -875,18 +333,54 @@ class Operator(sv.ScaleVariationModeMixin): +@@ -875,18 +339,53 @@ class Operator(sv.ScaleVariationModeMixin): """ column = [] k, logx = log_grid