Skip to main content

sciforge_hub/engine/experience/
experiment.rs

1//! Experiment data model.
2//!
3//! [`DomainType`] enumerates every supported scientific discipline;
4//! [`Experiment`] pairs a domain with a function name and a list of
5//! [`ParameterValue`]s.
6
7/// Supported scientific domains.
8#[derive(Debug, Clone)]
9pub enum DomainType {
10    Maths,
11    Physics,
12    Chemistry,
13    Biology,
14    Astronomy,
15    Geology,
16    Meteorology,
17    Astrochemistry,
18    Geophysics,
19    Astrophysics,
20    Biochemistry,
21    Biophysics,
22    Geochemistry,
23    Astrobiology,
24    AtmosphericChemistry,
25    AtmosphericPhysics,
26    PlanetaryGeology,
27    Biomathematics,
28    MathematicalPhysics,
29}
30
31/// Typed parameter value passed to a computation.
32#[derive(Debug, Clone)]
33pub enum ParameterValue {
34    Scalar(f64),
35    Integer(i64),
36    Vector(Vec<f64>),
37    Matrix(Vec<Vec<f64>>),
38    Boolean(bool),
39    Text(String),
40    Complex(f64, f64),
41    ComplexVector(Vec<(f64, f64)>),
42    Polynomial(Vec<f64>),
43    IntVector(Vec<usize>),
44    IntMatrix(Vec<Vec<usize>>),
45    EdgeList(Vec<(usize, usize, f64)>),
46    Sparse {
47        rows: usize,
48        cols: usize,
49        row_ptr: Vec<usize>,
50        col_idx: Vec<usize>,
51        values: Vec<f64>,
52    },
53    Tensor {
54        data: Vec<f64>,
55        shape: Vec<usize>,
56    },
57}
58
59/// A computation request targeting a domain function with parameters.
60#[derive(Debug, Clone)]
61pub struct Experiment {
62    /// Scientific domain.
63    pub domain: DomainType,
64    /// Function to invoke.
65    pub function_name: String,
66    /// Named parameters.
67    pub parameters: Vec<(String, ParameterValue)>,
68}
69
70impl Experiment {
71    /// Creates an experiment with no parameters.
72    pub fn new(domain: DomainType, function_name: &str) -> Self {
73        Self {
74            domain,
75            function_name: function_name.to_string(),
76            parameters: Vec::new(),
77        }
78    }
79
80    /// Appends a named parameter.
81    pub fn param(mut self, name: &str, value: ParameterValue) -> Self {
82        self.parameters.push((name.to_string(), value));
83        self
84    }
85}