Skip to content

Commit

Permalink
Merge branch 'master' into manipulate-operators
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Aug 8, 2024
2 parents 08c55d3 + b8761a5 commit d4d7efb
Show file tree
Hide file tree
Showing 54 changed files with 654 additions and 329 deletions.
11 changes: 9 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.17.0
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/pydocstyle
Expand All @@ -43,6 +43,13 @@ repos:
args: ["--add-ignore=D107,D105"]
additional_dependencies:
- toml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML]
pass_filenames: false
args: ["--ignore-missing-imports", "src/"]
- repo: local
hooks:
- id: fmt
Expand All @@ -53,6 +60,6 @@ repos:
files: ^crates/.*\.rs$
args: []
- repo: https://github.com/pre-commit/pre-commit
rev: v3.7.1
rev: v3.8.0
hooks:
- id: validate_manifest
65 changes: 65 additions & 0 deletions crates/doc-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
// activate KaTeX
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});

// Allow abbreviations
let abbrevs = {
"EKO": "Evolution Kernel Operator",
"PDF": "Parton Distribution Function(s)",
"FF": "Fragmentation Function(s)",
"FNS": "Flavor Number Scheme",
"FFNS": "Fixed Flavor Number Scheme",
"VFNS": "Variable Flavor Number Scheme",
"LO": "Leading Order",
"NLO": "Next-to-Leading Order",
"NNLO": "Next-to-Next-to-Leading Order",
"N3LO": "Next-to-Next-to-Next-to-Leading Order",
"LL": "Leading Log",
"NLL": "Next-to-Leading Log",
"NNLL": "Next-to-Next-to-Leading Log",
"DGLAP": "Dokshitzer-Gribov-Lipatov-Altarelli-Parisi",
"PID": "(Monte Carlo) parton identifier",
"OME": "Operator Matrix Element",
"RGE": "Renormalization Group Equation",
"MHOU": "Missing Higher Order Uncertainties",
"QCD": "Quantum Chromodynamics",
"QED": "Quantum Electrodynamics",
"DIS": "Deep Inelastic Scattering",
"BFKL": "Balitsky-Fadin-Kuraev-Lipatov",
"FHMRUVV": "Falcioni, Herzog, Moch, Ruijl, Ueda, Vermaseren and Vogt",
"API": "Application Program Interface",
};
// parse abbreviations
let parsedAbbrevs = {};
for (el in abbrevs) {
parsedAbbrevs["|" + el + "|"] = "<abbr title='"+abbrevs[el]+"' >"+el+"</abbr>";
}
// do the actual replace
function replaceAbbrev(el) {
let txt = el.textContent;
for (k in parsedAbbrevs)
txt = txt.replace(k, parsedAbbrevs[k]);
el.innerHTML = txt;
}
// search texts
let longs = document.getElementsByClassName("docblock");
for (let el of longs) replaceAbbrev(el);
let shorts = document.getElementsByClassName("docblock-short");
for (let el of shorts) replaceAbbrev(el);
});
</script>
2 changes: 1 addition & 1 deletion crates/eko/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "katex-header.html"]
rustdoc-args = ["--html-in-header", "doc-header.html"]

[lib]
name = "ekors"
Expand Down
1 change: 1 addition & 0 deletions crates/eko/doc-header.html
1 change: 0 additions & 1 deletion crates/eko/katex-header.html

This file was deleted.

2 changes: 1 addition & 1 deletion crates/ekore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "katex-header.html"]
rustdoc-args = ["--html-in-header", "doc-header.html"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions crates/ekore/doc-header.html
1 change: 0 additions & 1 deletion crates/ekore/katex-header.html

This file was deleted.

19 changes: 0 additions & 19 deletions crates/katex-header.html

This file was deleted.

20 changes: 20 additions & 0 deletions crates/parse-abbrev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Parse abbreviations from sphinx to Rust."""

import pathlib
import re

SRC = (
pathlib.Path(__file__).parents[1]
/ "doc"
/ "source"
/ "shared"
/ "abbreviations.rst"
)

cnt = SRC.read_text("utf-8")
for el in cnt.split(".."):
test = re.match(r"\s*(.+)\s+replace::\n\s+:abbr:`(.+?)\((.+)\)`", el.strip())
if test is None:
continue
# Print to terminal - the user can dump to the relevant file
print(f'"{test[2].strip()}": "{test[3].strip()}",')
9 changes: 7 additions & 2 deletions src/eko/couplings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"""

import logging
from typing import Iterable, List
from typing import Dict, Iterable, List, Tuple

import numba as nb
import numpy as np
import numpy.typing as npt
import scipy

from . import constants, matchings
Expand Down Expand Up @@ -383,6 +384,10 @@ def couplings_expanded_fixed_alphaem(order, couplings_ref, nf, scale_from, scale
return np.array([res_as, aem])


_CouplingsCacheKey = Tuple[float, float, int, float, float]
"""Cache key containing (a0, a1, nf, scale_from, scale_to)."""


class Couplings:
r"""Compute the strong and electromagnetic coupling constants :math:`a_s, a_{em}`.
Expand Down Expand Up @@ -480,7 +485,7 @@ def assert_positive(name, var):
self.decoupled_running,
)
# cache
self.cache = {}
self.cache: Dict[_CouplingsCacheKey, npt.NDArray] = {}

@property
def mu2_ref(self):
Expand Down
30 changes: 21 additions & 9 deletions src/eko/evolution_operator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import time
from multiprocessing import Pool
from typing import Dict, Tuple

import numba as nb
import numpy as np
Expand All @@ -20,6 +21,8 @@
from .. import basis_rotation as br
from .. import interpolation, mellin
from .. import scale_variations as sv
from ..io.types import EvolutionMethod, OperatorLabel
from ..kernels import ev_method
from ..kernels import non_singlet as ns
from ..kernels import non_singlet_qed as qed_ns
from ..kernels import singlet as s
Expand Down Expand Up @@ -600,7 +603,11 @@ def quad_ker_qed(
return ker


class Operator(sv.ModeMixin):
OpMembers = Dict[OperatorLabel, OpMember]
"""Map of all operators."""


class Operator(sv.ScaleVariationModeMixin):
"""Internal representation of a single EKO.
The actual matrices are computed upon calling :meth:`compute`.
Expand All @@ -625,8 +632,8 @@ class Operator(sv.ModeMixin):

log_label = "Evolution"
# complete list of possible evolution operators labels
full_labels = br.full_labels
full_labels_qed = br.full_unified_labels
full_labels: Tuple[OperatorLabel, ...] = br.full_labels
full_labels_qed: Tuple[OperatorLabel, ...] = br.full_unified_labels

def __init__(
self, config, managers, segment: Segment, mellin_cut=5e-2, is_threshold=False
Expand All @@ -639,9 +646,9 @@ def __init__(
# TODO make 'cut' external parameter?
self._mellin_cut = mellin_cut
self.is_threshold = is_threshold
self.op_members = {}
self.op_members: OpMembers = {}
self.order = tuple(config["order"])
self.alphaem_running = self.managers["couplings"].alphaem_running
self.alphaem_running = self.managers.couplings.alphaem_running
if self.log_label == "Evolution":
self.a = self.compute_a()
self.as_list, self.a_half_list = self.compute_aem_list()
Expand All @@ -663,7 +670,7 @@ def xif2(self):
@property
def int_disp(self):
"""Return the interpolation dispatcher."""
return self.managers["interpol_dispatcher"]
return self.managers.interpolator

@property
def grid_size(self):
Expand All @@ -686,7 +693,7 @@ def mu2(self):

def compute_a(self):
"""Return the computed values for :math:`a_s` and :math:`a_{em}`."""
coupling = self.managers["couplings"]
coupling = self.managers.couplings
a0 = coupling.a(
self.mu2[0],
nf_to=self.nf,
Expand Down Expand Up @@ -722,7 +729,7 @@ def compute_aem_list(self):
as_list = np.array([self.a_s[0], self.a_s[1]])
a_half = np.zeros((ev_op_iterations, 2))
else:
couplings = self.managers["couplings"]
couplings = self.managers.couplings
mu2_steps = np.geomspace(self.q2_from, self.q2_to, 1 + ev_op_iterations)
mu2_l = mu2_steps[0]
as_list = np.array(
Expand Down Expand Up @@ -780,6 +787,11 @@ def labels(self):
labels.extend(br.singlet_unified_labels)
return labels

@property
def ev_method(self):
"""Return the evolution method."""
return ev_method(EvolutionMethod(self.config["method"]))

def quad_ker(self, label, logx, areas):
"""Return partially initialized integrand function.
Expand All @@ -803,7 +815,7 @@ def quad_ker(self, label, logx, areas):
order=self.order,
mode0=label[0],
mode1=label[1],
method=self.config["method"],
method=self.ev_method,
is_log=self.int_disp.log,
logx=logx,
areas=areas,
Expand Down
26 changes: 13 additions & 13 deletions src/eko/evolution_operator/__init__.py.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/eko/evolution_operator/__init__.py b/src/eko/evolution_operator/__init__.py
index 1c759c5c..5eb394d0 100644
index fe07ade9..0f58c9e5 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.
@@ -3,16 +3,16 @@ r"""Contains the central operator classes.
See :doc:`Operator overview </code/Operators>`.
"""

Expand All @@ -11,6 +11,7 @@ index 1c759c5c..5eb394d0 100644
import os
import time
from multiprocessing import Pool
from typing import Dict, Tuple

+import ekors
import numba as nb
Expand All @@ -20,7 +21,7 @@ index 1c759c5c..5eb394d0 100644

import ekore.anomalous_dimensions.polarized.space_like as ad_ps
import ekore.anomalous_dimensions.unpolarized.space_like as ad_us
@@ -27,92 +27,10 @@ from ..kernels import singlet_qed as qed_s
@@ -30,92 +30,10 @@ from ..kernels import singlet_qed as qed_s
from ..kernels import valence_qed as qed_v
from ..matchings import Segment, lepton_number
from ..member import OpMember
Expand Down Expand Up @@ -114,7 +115,7 @@ index 1c759c5c..5eb394d0 100644
spec = [
("is_singlet", nb.boolean),
("is_QEDsinglet", nb.boolean),
@@ -184,422 +102,6 @@ class QuadKerBase:
@@ -187,421 +105,6 @@ class QuadKerBase:
return self.path.prefactor * pj * self.path.jac


Expand Down Expand Up @@ -533,13 +534,12 @@ index 1c759c5c..5eb394d0 100644
- )
- return ker
-
-
class Operator(sv.ModeMixin):
"""Internal representation of a single EKO.

@@ -780,50 +282,6 @@ class Operator(sv.ModeMixin):
labels.extend(br.singlet_unified_labels)
return labels
OpMembers = Dict[OperatorLabel, OpMember]
"""Map of all operators."""
@@ -792,50 +295,6 @@ class Operator(sv.ScaleVariationModeMixin):
"""Return the evolution method."""
return ev_method(EvolutionMethod(self.config["method"]))

- def quad_ker(self, label, logx, areas):
- """Return partially initialized integrand function.
Expand All @@ -564,7 +564,7 @@ index 1c759c5c..5eb394d0 100644
- order=self.order,
- mode0=label[0],
- mode1=label[1],
- method=self.config["method"],
- method=self.ev_method,
- is_log=self.int_disp.log,
- logx=logx,
- areas=areas,
Expand All @@ -588,7 +588,7 @@ index 1c759c5c..5eb394d0 100644
def initialize_op_members(self):
"""Init all operators with the identity or zeros."""
eye = OpMember(
@@ -846,10 +304,7 @@ class Operator(sv.ModeMixin):
@@ -858,10 +317,7 @@ class Operator(sv.ScaleVariationModeMixin):
else:
self.op_members[n] = zero.copy()

Expand All @@ -600,7 +600,7 @@ index 1c759c5c..5eb394d0 100644
"""Run the integration for each grid point.

Parameters
@@ -864,18 +319,56 @@ class Operator(sv.ModeMixin):
@@ -876,18 +332,56 @@ class Operator(sv.ScaleVariationModeMixin):
"""
column = []
k, logx = log_grid
Expand Down
Loading

0 comments on commit d4d7efb

Please sign in to comment.