Skip to main content

gammalooprs/
lib.rs

1#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
2// #![deny(clippy::all)]
3// #![warn(clippy::pedantic)]
4#![warn(clippy::all)]
5// #![warn(clippy::restriction)]
6// #![warn(clippy::nursery)]
7// #![warn(clippy::cargo)]
8// #![feature(min_specialization)]
9//
10
11pub mod cff;
12pub mod feyngen;
13pub mod graph;
14pub mod initialisation;
15pub mod integrands;
16pub mod integrate;
17pub mod model;
18pub mod momentum;
19pub mod numerator;
20pub mod observables;
21pub mod processes;
22pub mod settings;
23pub mod subtraction;
24pub mod tests;
25// pub mod tests_from_pytest;
26pub mod utils;
27pub mod uv;
28pub use gammaloop_tracing_filter::LogMessage;
29use integrands::*;
30use model::Model;
31use momentum::signature::ExternalSignature;
32use std::sync::atomic::AtomicBool;
33use symbolica::state::HasStateMap;
34use symbolica::state::StateMap;
35use utils::F;
36use utils::FloatLike;
37
38pub static INTERRUPTED: AtomicBool = AtomicBool::new(false);
39pub static ITERATION_ABORT_REQUESTED: AtomicBool = AtomicBool::new(false);
40
41pub const GAMMALOOP_NAMESPACE: &str = "GL";
42pub const MAX_CORES: usize = 1000;
43
44pub trait GammaLoopContext: HasStateMap + HasModel {}
45
46pub trait HasModel {
47    /// Returns the physics model associated with this computation context.
48    fn get_model(&self) -> &Model;
49}
50
51impl HasModel for Model {
52    fn get_model(&self) -> &Model {
53        self
54    }
55}
56
57impl HasModel for GammaLoopContextContainer<'_> {
58    fn get_model(&self) -> &Model {
59        self.model
60    }
61}
62
63#[derive(Clone, Copy)]
64pub struct GammaLoopContextContainer<'a> {
65    /// Symbolica state map used to resolve symbols during GammaLoop computations.
66    pub state_map: &'a StateMap,
67    /// Physics model that supplies particles, parameters, and interactions.
68    pub model: &'a Model,
69}
70
71impl<'a> HasStateMap for GammaLoopContextContainer<'a> {
72    fn get_state_map(&self) -> &StateMap {
73        self.state_map
74    }
75}
76
77impl<'a> GammaLoopContext for GammaLoopContextContainer<'a> {}
78
79#[cfg(not(feature = "higher_loops"))]
80pub const MAX_LOOP: usize = 3;
81#[cfg(feature = "higher_loops")]
82pub const MAX_LOOP: usize = 6;
83
84pub fn set_interrupt_handler() {
85    INTERRUPTED.store(false, std::sync::atomic::Ordering::Relaxed);
86    ITERATION_ABORT_REQUESTED.store(false, std::sync::atomic::Ordering::Relaxed);
87    let _ = ctrlc::set_handler(|| {
88        INTERRUPTED.store(true, std::sync::atomic::Ordering::Relaxed);
89    });
90}
91
92#[inline]
93pub fn request_interrupt() {
94    INTERRUPTED.store(true, std::sync::atomic::Ordering::Relaxed);
95}
96
97#[inline]
98pub fn request_iteration_abort() {
99    ITERATION_ABORT_REQUESTED.store(true, std::sync::atomic::Ordering::Relaxed);
100}
101
102#[inline]
103pub fn is_interrupt_requested() -> bool {
104    INTERRUPTED.load(std::sync::atomic::Ordering::Relaxed)
105}
106
107#[inline]
108pub(crate) fn is_interrupted() -> bool {
109    is_interrupt_requested()
110}
111
112#[inline]
113pub(crate) fn is_iteration_abort_requested() -> bool {
114    ITERATION_ABORT_REQUESTED.load(std::sync::atomic::Ordering::Relaxed)
115}
116
117#[inline]
118pub(crate) fn set_interrupted(flag: bool) {
119    INTERRUPTED.store(flag, std::sync::atomic::Ordering::Relaxed);
120}
121
122#[inline]
123pub fn clear_interrupt_request() {
124    set_interrupted(false);
125}
126
127#[inline]
128pub(crate) fn clear_iteration_abort_request() {
129    ITERATION_ABORT_REQUESTED.store(false, std::sync::atomic::Ordering::Relaxed);
130}
131
132#[derive(Clone, Copy, Debug)]
133pub enum DependentMomentaConstructor<'a> {
134    Amplitude(&'a ExternalSignature),
135    //CrossSection {
136    //    external_connections: &'a [ExternalConnection],
137    //}, // at the moment I assume the first n/2 externals are incoming and the second n/2 are outgoing, the mapping is (0, n/2), (1, n/2+1), (2, n/2+2), ...
138    CrossSection,
139}