Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustify QED #416

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1762846
start implementation of aem1
tgiani Oct 16, 2024
61220f8
complete aem1.py
tgiani Oct 21, 2024
a40908b
unit tests
tgiani Oct 21, 2024
f0edfae
add struct for charge combinations
tgiani Oct 21, 2024
a8d72c0
some work on gamma_ns_qed
tgiani Oct 23, 2024
e8a3a8b
start as1aem1.rs
tgiani Oct 23, 2024
136dbe8
gamma_qph as1aem1
tgiani Oct 23, 2024
ce11227
some work on as1aem1
tgiani Oct 25, 2024
659fe31
addingv recursive harmonics to cache
tgiani Oct 25, 2024
4007f0d
S1p2 and G3p2. Check that this is correct
tgiani Oct 25, 2024
7c160f1
gamma_nsp
tgiani Oct 25, 2024
37a65e8
rewrite ChargeCombination struct
tgiani Nov 11, 2024
fc5de81
missing entries in as1aem1
tgiani Nov 11, 2024
2a911b1
adding tests
tgiani Nov 11, 2024
bad124a
some work on spacelike.rs and recasting from list to vec
tgiani Nov 20, 2024
d50e9c7
valence qed
tgiani Nov 20, 2024
b0f6722
some unit tests
tgiani Nov 20, 2024
e4c621b
use Vec<> only when dimension is not known, else use normal list
tgiani Nov 20, 2024
81ece22
fix notation row/columns
tgiani Nov 20, 2024
0def938
add unravel functions for qed case. To be checked
tgiani Nov 20, 2024
9b58455
modifying rust_quad_ker_qcd, PyQuadKerQCDT and QuadQCDargs to include…
tgiani Nov 21, 2024
588496a
add qed valence option in rust_quad_ker_qcd
tgiani Nov 21, 2024
3452243
remove useless flag is_qed
tgiani Nov 21, 2024
9335b97
extend QuadQCDargs to include arguments for c_quad_ker_qed
tgiani Nov 21, 2024
3390aca
setting up input vectors for cb_quad_ker_qed
tgiani Nov 28, 2024
6a3af19
cb_quad_ker_qed
tgiani Dec 3, 2024
f0a727d
fix modes for singlet QED and use == in if statements
tgiani Dec 9, 2024
398c89a
small fix
tgiani Dec 9, 2024
ea44cee
cargo fmt
tgiani Dec 9, 2024
5721326
forgot pre-commit
tgiani Dec 9, 2024
83af836
updating patch file
tgiani Dec 11, 2024
1af5cbf
Update crates/ekore/src/constants.rs
tgiani Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
# Run the formatter.
- id: ruff-format
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: "master"
hooks:
- id: docformatter
additional_dependencies: [tomli]
Expand Down
140 changes: 131 additions & 9 deletions crates/eko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct RawCmplx {
}

/// Map tensors to c-ordered list
/// (res is a vector with dim order_qcd filled with DIMxDIM matrices)
fn unravel<const DIM: usize>(res: Vec<[[Complex<f64>; DIM]; DIM]>, order_qcd: usize) -> RawCmplx {
let mut target = RawCmplx {
re: Vec::<f64>::new(),
Expand All @@ -30,14 +31,61 @@ fn unravel<const DIM: usize>(res: Vec<[[Complex<f64>; DIM]; DIM]>, order_qcd: us
target
}

/// Map tensors to c-ordered list in the QED singlet and valence case
/// (res is a matrix with dim order_qcd x order_qed filled with DIMxDIM matrices)
fn unravel_qed<const DIM: usize>(
res: Vec<Vec<[[Complex<f64>; DIM]; DIM]>>,
order_qcd: usize,
order_qed: usize,
) -> RawCmplx {
let mut target = RawCmplx {
re: Vec::<f64>::new(),
im: Vec::<f64>::new(),
};
for obj_ in res.iter().take(order_qcd) {
for obj in obj_.iter().take(order_qed) {
for col in obj.iter().take(DIM) {
for el in col.iter().take(DIM) {
target.re.push(el.re);
target.im.push(el.im);
}
}
}
}
target
}

/// Map tensors to c-ordered list in the QED non-singlet case
/// (res is a matrix with dim order_qcd x order_qed filled with complex numbers)
fn unravel_qed_ns(res: Vec<Vec<Complex<f64>>>, order_qcd: usize, order_qed: usize) -> RawCmplx {
let mut target = RawCmplx {
re: Vec::<f64>::new(),
im: Vec::<f64>::new(),
};
for col in res.iter().take(order_qcd) {
for el in col.iter().take(order_qed) {
target.re.push(el.re);
target.im.push(el.im);
}
}
target
}

/// QCD intergration kernel inside quad.
///
/// # Safety
/// This is the connection from Python, so we don't know what is on the other side.
#[no_mangle]
pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
let args = *(rargs as *mut QuadQCDargs);
let is_singlet = (100 == args.mode0) || (21 == args.mode0) || (90 == args.mode0);

let is_singlet = (100 == args.mode0)
|| (21 == args.mode0)
|| (90 == args.mode0)
|| (22 == args.mode0)
|| (101 == args.mode0);

let is_qed_valence = (10200 == args.mode0) || (10204 == args.mode0);
// prepare Mellin stuff
let path = mellin::TalbotPath::new(u, args.logx, is_singlet);
let jac = path.jac() * path.prefactor();
Expand Down Expand Up @@ -70,14 +118,41 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
);
}
} else if is_singlet {
let gamma_singlet_qcd = match args.is_polarized {
true => ekore::anomalous_dimensions::polarized::spacelike::gamma_singlet_qcd,
false => ekore::anomalous_dimensions::unpolarized::spacelike::gamma_singlet_qcd,
};
raw = unravel(
gamma_singlet_qcd(args.order_qcd, &mut c, args.nf),
args.order_qcd,
);
if args.order_qed > 0 {
let gamma_singlet_qed =
ekore::anomalous_dimensions::unpolarized::spacelike::gamma_singlet_qed;
raw = unravel_qed(
gamma_singlet_qed(args.order_qcd, args.order_qed, &mut c, args.nf),
args.order_qcd,
args.order_qed,
);
} else {
let gamma_singlet_qcd = match args.is_polarized {
true => ekore::anomalous_dimensions::polarized::spacelike::gamma_singlet_qcd,
false => ekore::anomalous_dimensions::unpolarized::spacelike::gamma_singlet_qcd,
};
raw = unravel(
gamma_singlet_qcd(args.order_qcd, &mut c, args.nf),
args.order_qcd,
);
}
} else if args.order_qed > 0 {
if is_qed_valence {
let gamma_valence_qed =
ekore::anomalous_dimensions::unpolarized::spacelike::gamma_valence_qed;
raw = unravel_qed(
gamma_valence_qed(args.order_qcd, args.order_qed, &mut c, args.nf),
args.order_qcd,
args.order_qed,
);
} else {
let gamma_ns_qed = ekore::anomalous_dimensions::unpolarized::spacelike::gamma_ns_qed;
raw = unravel_qed_ns(
gamma_ns_qed(args.order_qcd, args.order_qed, args.mode0, &mut c, args.nf),
args.order_qcd,
args.order_qed,
);
}
} else {
// we can not do 1D
let gamma_ns_qcd = match args.is_polarized {
Expand All @@ -100,6 +175,7 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
jac.re,
jac.im,
args.order_qcd,
args.order_qed,
is_singlet,
args.mode0,
args.mode1,
Expand All @@ -118,6 +194,15 @@ pub unsafe extern "C" fn rust_quad_ker_qcd(u: f64, rargs: *mut c_void) -> f64 {
args.sv_mode_num,
args.is_threshold,
args.Lsv,
// additional QED params
args.as_list,
args.as_list_len,
args.mu2_from,
args.mu2_to,
args.a_half,
args.a_half_x,
args.a_half_y,
args.alphaem_running,
)
}

Expand All @@ -130,6 +215,7 @@ type PyQuadKerQCDT = unsafe extern "C" fn(
f64,
f64,
usize,
usize,
bool,
u16,
u16,
Expand All @@ -148,6 +234,14 @@ type PyQuadKerQCDT = unsafe extern "C" fn(
u8,
bool,
f64,
*const f64,
u8,
f64,
f64,
*const f64,
u8,
u8,
bool,
) -> f64;

/// Additional integration parameters
Expand All @@ -156,6 +250,7 @@ type PyQuadKerQCDT = unsafe extern "C" fn(
#[derive(Clone, Copy)]
pub struct QuadQCDargs {
pub order_qcd: usize,
pub order_qed: usize,
pub mode0: u16,
pub mode1: u16,
pub is_polarized: bool,
Expand All @@ -177,6 +272,15 @@ pub struct QuadQCDargs {
pub is_threshold: bool,
pub is_ome: bool,
pub Lsv: f64,
// additional param required for QED
pub as_list: *const f64,
pub as_list_len: u8,
pub mu2_from: f64,
pub mu2_to: f64,
pub a_half: *const f64,
pub a_half_x: u8,
pub a_half_y: u8,
pub alphaem_running: bool,
}

/// Empty placeholder function for python callback.
Expand All @@ -191,6 +295,7 @@ pub unsafe extern "C" fn my_py(
_re_jac: f64,
_im_jac: f64,
_order_qcd: usize,
_order_qed: usize,
_is_singlet: bool,
_mode0: u16,
_mode1: u16,
Expand All @@ -209,6 +314,14 @@ pub unsafe extern "C" fn my_py(
_sv_mode_num: u8,
_is_threshold: bool,
_lsv: f64,
_as_list: *const f64,
_as_list_len: u8,
_mu2_from: f64,
_mu2_to: f64,
_a_half: *const f64,
_a_half_x: u8,
_a_half_y: u8,
_alphaem_running: bool,
) -> f64 {
0.
}
Expand All @@ -224,6 +337,7 @@ pub unsafe extern "C" fn my_py(
pub unsafe extern "C" fn empty_qcd_args() -> QuadQCDargs {
QuadQCDargs {
order_qcd: 0,
order_qed: 0,
mode0: 0,
mode1: 0,
is_polarized: false,
Expand All @@ -245,5 +359,13 @@ pub unsafe extern "C" fn empty_qcd_args() -> QuadQCDargs {
is_threshold: false,
is_ome: false,
Lsv: 0.,
as_list: [].as_ptr(),
as_list_len: 0,
mu2_from: 0.,
mu2_to: 0.,
a_half: [].as_ptr(),
a_half_x: 0,
a_half_y: 0,
alphaem_running: false,
}
}
Loading
Loading