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 utils;
25pub mod uv;
26pub use gammaloop_tracing_filter::LogMessage;
27use integrands::*;
28use model::Model;
29use momentum::signature::ExternalSignature;
30use std::sync::atomic::AtomicBool;
31use symbolica::state::HasStateMap;
32use symbolica::state::StateMap;
33use utils::F;
34use utils::FloatLike;
35
36pub static INTERRUPTED: AtomicBool = AtomicBool::new(false);
37pub static ITERATION_ABORT_REQUESTED: AtomicBool = AtomicBool::new(false);
38
39pub const GAMMALOOP_NAMESPACE: &str = "GL";
40pub const MAX_CORES: usize = 1000;
41
42pub trait GammaLoopContext: HasStateMap + HasModel {}
43
44pub trait HasModel {
45    /// Returns the physics model associated with this computation context.
46    fn get_model(&self) -> &Model;
47}
48
49impl HasModel for Model {
50    fn get_model(&self) -> &Model {
51        self
52    }
53}
54
55impl HasModel for GammaLoopContextContainer<'_> {
56    fn get_model(&self) -> &Model {
57        self.model
58    }
59}
60
61#[derive(Clone, Copy)]
62pub struct GammaLoopContextContainer<'a> {
63    /// Symbolica state map used to resolve symbols during GammaLoop computations.
64    pub state_map: &'a StateMap,
65    /// Physics model that supplies particles, parameters, and interactions.
66    pub model: &'a Model,
67}
68
69impl<'a> HasStateMap for GammaLoopContextContainer<'a> {
70    fn get_state_map(&self) -> &StateMap {
71        self.state_map
72    }
73}
74
75impl<'a> GammaLoopContext for GammaLoopContextContainer<'a> {}
76
77#[cfg(not(feature = "higher_loops"))]
78pub const MAX_LOOP: usize = 3;
79#[cfg(feature = "higher_loops")]
80pub const MAX_LOOP: usize = 6;
81
82pub fn set_interrupt_handler() {
83    INTERRUPTED.store(false, std::sync::atomic::Ordering::Relaxed);
84    ITERATION_ABORT_REQUESTED.store(false, std::sync::atomic::Ordering::Relaxed);
85    let _ = ctrlc::set_handler(|| {
86        INTERRUPTED.store(true, std::sync::atomic::Ordering::Relaxed);
87    });
88}
89
90#[inline]
91pub fn request_interrupt() {
92    INTERRUPTED.store(true, std::sync::atomic::Ordering::Relaxed);
93}
94
95#[inline]
96pub fn request_iteration_abort() {
97    ITERATION_ABORT_REQUESTED.store(true, std::sync::atomic::Ordering::Relaxed);
98}
99
100#[inline]
101pub fn is_interrupt_requested() -> bool {
102    INTERRUPTED.load(std::sync::atomic::Ordering::Relaxed)
103}
104
105#[inline]
106pub(crate) fn is_interrupted() -> bool {
107    is_interrupt_requested()
108}
109
110#[inline]
111pub(crate) fn is_iteration_abort_requested() -> bool {
112    ITERATION_ABORT_REQUESTED.load(std::sync::atomic::Ordering::Relaxed)
113}
114
115#[inline]
116pub(crate) fn set_interrupted(flag: bool) {
117    INTERRUPTED.store(flag, std::sync::atomic::Ordering::Relaxed);
118}
119
120#[inline]
121pub fn clear_interrupt_request() {
122    set_interrupted(false);
123}
124
125#[inline]
126pub(crate) fn clear_iteration_abort_request() {
127    ITERATION_ABORT_REQUESTED.store(false, std::sync::atomic::Ordering::Relaxed);
128}
129
130#[derive(Clone, Copy, Debug)]
131pub enum DependentMomentaConstructor<'a> {
132    Amplitude(&'a ExternalSignature),
133    //CrossSection {
134    //    external_connections: &'a [ExternalConnection],
135    //}, // 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), ...
136    CrossSection,
137}