Skip to content

Commit 972edc4

Browse files
authored
Merge pull request #385 from NNPDF/ome_rust
Rustify ome.u.s.{as1, as2}
2 parents d8963ef + 8896dea commit 972edc4

File tree

26 files changed

+1488
-236
lines changed

26 files changed

+1488
-236
lines changed

crates/dekoder/src/eko.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl EKO {
9292
pub fn write(&self, dst: PathBuf) -> Result<()> {
9393
self.assert_working_dir()?;
9494
// create writer
95-
let dst_file = File::create(&dst)?;
95+
let dst_file = File::create(dst)?;
9696
let dst_file = BufWriter::with_capacity(TAR_WRITER_CAPACITY, dst_file);
9797
let mut ar = tar::Builder::new(dst_file);
9898
// do it!
@@ -101,7 +101,7 @@ impl EKO {
101101

102102
/// Extract tar file from `src` to `dst`.
103103
pub fn extract(src: PathBuf, dst: PathBuf) -> Result<Self> {
104-
let mut ar = tar::Archive::new(File::open(&src)?);
104+
let mut ar = tar::Archive::new(File::open(src)?);
105105
ar.unpack(&dst)?;
106106
Self::load_opened(dst)
107107
}

crates/eko/src/lib.rs

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
//! Interface to the eko Python package.
22
33
use ekore::harmonics::cache::Cache;
4+
use num::Complex;
45
use std::ffi::c_void;
56

67
pub mod bib;
78
pub mod mellin;
89

10+
/// Wrapper to pass arguments back to Python
11+
struct RawCmplx {
12+
re: Vec<f64>,
13+
im: Vec<f64>,
14+
}
15+
16+
/// Map tensors to c-ordered list
17+
fn unravel<const DIM: usize>(res: Vec<[[Complex<f64>; DIM]; DIM]>, order_qcd: usize) -> RawCmplx {
18+
let mut target = RawCmplx {
19+
re: Vec::<f64>::new(),
20+
im: Vec::<f64>::new(),
21+
};
22+
for obj in res.iter().take(order_qcd) {
23+
for col in obj.iter().take(DIM) {
24+
for el in col.iter().take(DIM) {
25+
target.re.push(el.re);
26+
target.im.push(el.im);
27+
}
28+
}
29+
}
30+
target
31+
}
32+
933
/// QCD intergration kernel inside quad.
1034
///
1135
/// # Safety
@@ -14,44 +38,66 @@ pub mod mellin;
1438
pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
1539
let args = *(rargs as *mut QuadQCDargs);
1640
let is_singlet = (100 == args.mode0) || (21 == args.mode0) || (90 == args.mode0);
17-
// prepare gamma
41+
// prepare Mellin stuff
1842
let path = mellin::TalbotPath::new(u, args.logx, is_singlet);
1943
let jac = path.jac() * path.prefactor();
2044
let mut c = Cache::new(path.n());
21-
let mut re = Vec::<f64>::new();
22-
let mut im = Vec::<f64>::new();
23-
if is_singlet {
24-
let res = ekore::anomalous_dimensions::unpolarized::spacelike::gamma_singlet_qcd(
45+
let mut raw = RawCmplx {
46+
re: Vec::<f64>::new(),
47+
im: Vec::<f64>::new(),
48+
};
49+
50+
if args.is_ome {
51+
if is_singlet {
52+
raw = unravel(
53+
ekore::operator_matrix_elements::unpolarized::spacelike::A_singlet(
54+
args.order_qcd,
55+
&mut c,
56+
args.nf,
57+
args.L,
58+
),
59+
args.order_qcd,
60+
);
61+
} else {
62+
raw = unravel(
63+
ekore::operator_matrix_elements::unpolarized::spacelike::A_non_singlet(
64+
args.order_qcd,
65+
&mut c,
66+
args.nf,
67+
args.L,
68+
),
69+
args.order_qcd,
70+
);
71+
}
72+
} else if is_singlet {
73+
raw = unravel(
74+
ekore::anomalous_dimensions::unpolarized::spacelike::gamma_singlet_qcd(
75+
args.order_qcd,
76+
&mut c,
77+
args.nf,
78+
),
2579
args.order_qcd,
26-
&mut c,
27-
args.nf,
2880
);
29-
for gamma_s in res.iter().take(args.order_qcd) {
30-
for col in gamma_s.iter().take(2) {
31-
for el in col.iter().take(2) {
32-
re.push(el.re);
33-
im.push(el.im);
34-
}
35-
}
36-
}
3781
} else {
82+
// we can not do 1D
3883
let res = ekore::anomalous_dimensions::unpolarized::spacelike::gamma_ns_qcd(
3984
args.order_qcd,
4085
args.mode0,
4186
&mut c,
4287
args.nf,
4388
);
4489
for el in res.iter().take(args.order_qcd) {
45-
re.push(el.re);
46-
im.push(el.im);
90+
raw.re.push(el.re);
91+
raw.im.push(el.im);
4792
}
4893
}
94+
4995
// pass on
5096
(args.py)(
51-
re.as_ptr(),
52-
im.as_ptr(),
53-
c.n.re,
54-
c.n.im,
97+
raw.re.as_ptr(),
98+
raw.im.as_ptr(),
99+
c.n().re,
100+
c.n().im,
55101
jac.re,
56102
jac.im,
57103
args.order_qcd,
@@ -72,6 +118,7 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
72118
args.ev_op_max_order_qcd,
73119
args.sv_mode_num,
74120
args.is_threshold,
121+
args.Lsv,
75122
)
76123
}
77124

@@ -101,6 +148,7 @@ type PyQuadKerQCDT = unsafe extern "C" fn(
101148
u8,
102149
u8,
103150
bool,
151+
f64,
104152
) -> f64;
105153

106154
/// Additional integration parameters
@@ -128,6 +176,8 @@ pub struct QuadQCDargs {
128176
pub ev_op_max_order_qcd: u8,
129177
pub sv_mode_num: u8,
130178
pub is_threshold: bool,
179+
pub is_ome: bool,
180+
pub Lsv: f64,
131181
}
132182

133183
/// Empty placeholder function for python callback.
@@ -159,14 +209,15 @@ pub unsafe extern "C" fn my_py(
159209
_ev_op_max_order_qcd: u8,
160210
_sv_mode_num: u8,
161211
_is_threshold: bool,
212+
_lsv: f64,
162213
) -> f64 {
163214
0.
164215
}
165216

166217
/// Return empty additional arguments.
167218
///
168219
/// This is required to make the arguments part of the API, otherwise it won't be added to the compiled
169-
/// package (since it does not appear in the signature of `quad_ker_qcd`).
220+
/// package (since it does not appear in the signature of `rust_quad_ker_qcd`).
170221
///
171222
/// # Safety
172223
/// This is the connection from and back to Python, so we don't know what is on the other side.
@@ -193,5 +244,7 @@ pub unsafe extern "C" fn empty_qcd_args() -> QuadQCDargs {
193244
ev_op_max_order_qcd: 0,
194245
sv_mode_num: 0,
195246
is_threshold: false,
247+
is_ome: false,
248+
Lsv: 0.,
196249
}
197250
}

crates/ekore/refs.bib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,16 @@ @article{Buza1996wv
9494
pages = "301--320",
9595
year = "1998"
9696
}
97+
@article{Bierenbaum2009zt,
98+
author = "Bierenbaum, Isabella and Blumlein, Johannes and Klein, Sebastian",
99+
title = "{The Gluonic Operator Matrix Elements at O(alpha(s)**2) for DIS Heavy Flavor Production}",
100+
eprint = "0901.0669",
101+
archivePrefix = "arXiv",
102+
primaryClass = "hep-ph",
103+
reportNumber = "DESY-08-187, SFB-CPP-08-107, IFIC-08-68",
104+
doi = "10.1016/j.physletb.2009.01.057",
105+
journal = "Phys. Lett. B",
106+
volume = "672",
107+
pages = "401--406",
108+
year = "2009"
109+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
//! The anomalous dimensions for DGLAP evolution.
1+
//! The anomalous dimensions for |DGLAP| evolution.
22
33
pub mod unpolarized;
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! LO QCD
1+
//! |LO| |QCD|.
22
33
use num::complex::Complex;
44

@@ -9,7 +9,7 @@ use crate::harmonics::cache::{Cache, K};
99
///
1010
/// Implements Eq. (3.4) of [\[Moch:2004pa\]][crate::bib::Moch2004pa].
1111
pub fn gamma_ns(c: &mut Cache, _nf: u8) -> Complex<f64> {
12-
let N = c.n;
12+
let N = c.n();
1313
let S1 = c.get(K::S1);
1414
let gamma = -(3.0 - 4.0 * S1 + 2.0 / N / (N + 1.0));
1515
CF * gamma
@@ -19,7 +19,7 @@ pub fn gamma_ns(c: &mut Cache, _nf: u8) -> Complex<f64> {
1919
///
2020
/// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw).
2121
pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex<f64> {
22-
let N = c.n;
22+
let N = c.n();
2323
let gamma = -(N.powu(2) + N + 2.0) / (N * (N + 1.0) * (N + 2.0));
2424
2.0 * TR * 2.0 * (nf as f64) * gamma
2525
}
@@ -28,7 +28,7 @@ pub fn gamma_qg(c: &mut Cache, nf: u8) -> Complex<f64> {
2828
///
2929
/// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw).
3030
pub fn gamma_gq(c: &mut Cache, _nf: u8) -> Complex<f64> {
31-
let N = c.n;
31+
let N = c.n();
3232
let gamma = -(N.powu(2) + N + 2.0) / (N * (N + 1.0) * (N - 1.0));
3333
2.0 * CF * gamma
3434
}
@@ -37,7 +37,7 @@ pub fn gamma_gq(c: &mut Cache, _nf: u8) -> Complex<f64> {
3737
///
3838
/// Implements Eq. (3.5) of [\[Vogt:2004mw\]](crate::bib::Vogt2004mw).
3939
pub fn gamma_gg(c: &mut Cache, nf: u8) -> Complex<f64> {
40-
let N = c.n;
40+
let N = c.n();
4141
let S1 = c.get(K::S1);
4242
let gamma = S1 - 1.0 / N / (N - 1.0) - 1.0 / (N + 1.0) / (N + 2.0);
4343
CA * (4.0 * gamma - 11.0 / 3.0) + 4.0 / 3.0 * TR * (nf as f64)
@@ -54,63 +54,64 @@ pub fn gamma_singlet(c: &mut Cache, nf: u8) -> [[Complex<f64>; 2]; 2] {
5454

5555
#[cfg(test)]
5656
mod tests {
57-
use crate::cmplx;
58-
use crate::{anomalous_dimensions::unpolarized::spacelike::as1::*, harmonics::cache::Cache};
59-
use float_cmp::assert_approx_eq;
57+
use super::*;
58+
use crate::harmonics::cache::Cache;
59+
use crate::{assert_approx_eq_cmplx, cmplx};
6060
use num::complex::Complex;
61+
use num::Zero;
6162
const NF: u8 = 5;
6263

6364
#[test]
6465
fn number_conservation() {
65-
const N: Complex<f64> = cmplx![1., 0.];
66+
const N: Complex<f64> = cmplx!(1., 0.);
6667
let mut c = Cache::new(N);
6768
let me = gamma_ns(&mut c, NF);
68-
assert_approx_eq!(f64, me.re, 0., epsilon = 1e-12);
69-
assert_approx_eq!(f64, me.im, 0., epsilon = 1e-12);
69+
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
7070
}
7171

7272
#[test]
7373
fn quark_momentum_conservation() {
74-
const N: Complex<f64> = cmplx![2., 0.];
74+
const N: Complex<f64> = cmplx!(2., 0.);
7575
let mut c = Cache::new(N);
7676
let me = gamma_ns(&mut c, NF) + gamma_gq(&mut c, NF);
77-
assert_approx_eq!(f64, me.re, 0., epsilon = 1e-12);
78-
assert_approx_eq!(f64, me.im, 0., epsilon = 1e-12);
77+
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
7978
}
8079

8180
#[test]
8281
fn gluon_momentum_conservation() {
83-
const N: Complex<f64> = cmplx![2., 0.];
82+
const N: Complex<f64> = cmplx!(2., 0.);
8483
let mut c = Cache::new(N);
8584
let me = gamma_qg(&mut c, NF) + gamma_gg(&mut c, NF);
86-
assert_approx_eq!(f64, me.re, 0., epsilon = 1e-12);
87-
assert_approx_eq!(f64, me.im, 0., epsilon = 1e-12);
85+
assert_approx_eq_cmplx!(f64, me, Complex::zero(), epsilon = 1e-12);
8886
}
8987

9088
#[test]
9189
fn gamma_qg_() {
92-
const N: Complex<f64> = cmplx![1., 0.];
90+
const N: Complex<f64> = cmplx!(1., 0.);
9391
let mut c = Cache::new(N);
9492
let me = gamma_qg(&mut c, NF);
95-
assert_approx_eq!(f64, me.re, -20. / 3.0, ulps = 32);
96-
assert_approx_eq!(f64, me.im, 0., epsilon = 1e-12);
93+
assert_approx_eq_cmplx!(f64, me, cmplx!(-20. / 3., 0.), ulps = 32, epsilon = 1e-12);
9794
}
9895

9996
#[test]
10097
fn gamma_gq_() {
101-
const N: Complex<f64> = cmplx![0., 1.];
98+
const N: Complex<f64> = cmplx!(0., 1.);
10299
let mut c = Cache::new(N);
103100
let me = gamma_gq(&mut c, NF);
104-
assert_approx_eq!(f64, me.re, 4. / 3.0, ulps = 32);
105-
assert_approx_eq!(f64, me.im, -4. / 3.0, ulps = 32);
101+
assert_approx_eq_cmplx!(f64, me, cmplx!(4. / 3.0, -4. / 3.0), ulps = 32);
106102
}
107103

108104
#[test]
109105
fn gamma_gg_() {
110-
const N: Complex<f64> = cmplx![0., 1.];
106+
const N: Complex<f64> = cmplx!(0., 1.);
111107
let mut c = Cache::new(N);
112108
let me = gamma_gg(&mut c, NF);
113-
assert_approx_eq!(f64, me.re, 5.195725159621, ulps = 32, epsilon = 1e-11);
114-
assert_approx_eq!(f64, me.im, 10.52008856962, ulps = 32, epsilon = 1e-11);
109+
assert_approx_eq_cmplx!(
110+
f64,
111+
me,
112+
cmplx!(5.195725159621, 10.52008856962),
113+
ulps = 32,
114+
epsilon = 1e-11
115+
);
115116
}
116117
}

0 commit comments

Comments
 (0)