Skip to content

Commit d3e36d2

Browse files
committed
time sclaing parameter added to the config xml
1 parent 8769e21 commit d3e36d2

6 files changed

Lines changed: 40 additions & 9 deletions

File tree

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ There are three types of input files that must be provided:
157157
- **cuqdyn config xml:**
158158
This file contains the configuration of the cuqdyn solver used in the cuqdyn-c library.
159159

160-
- The tolerances block defines the rtol and atol used by the cvodes library.
161-
- The ode model is defined inside the ode_expr block.
162-
- y0 is the initial conditions of the ODE (If no present, the first row of the data matrix will be used) (Optional).
163-
- The states_transformer block defines the transformations applied to the different states in case of the observed data
164-
being a combination of the different states.
160+
- **tolerances:** rtol and atol used by the cvodes library.
161+
- **ode_expr:** ODE model expression or identifier.
162+
- **time_scaling:** Scaling factor for time. Using negative powers of 10 helps cvodes speed.
163+
- **y0:** Initial conditions of the ODE.
164+
- **states_transformer:** Transformations expressions or identidier applied to the different states in case of the
165+
observed data being a combination of the different states.
165166

166-
There is an option to accelerate the process of evaluating the ODE by defining it and the states transformer inside the
167-
mevalexpr module. We will talk about this later.
167+
There is an option to accelerate the process of evaluating the ODE by defining it and the states transformer inside the mevalexpr module. We will talk about this later.
168168

169169
```xml
170170
<?xml version="1.0" encoding="UTF-8" ?>
@@ -191,7 +191,8 @@ There are three types of input files that must be provided:
191191
p1 * y11 * y7 - p24 * p22 * y14
192192
p28 + p27 * y7 - p29 * y15
193193
</ode_expr>
194-
<y0> <!-- Optional -->
194+
<time_scaling>0.001</time_scaling> <!-- Optional (Defaults to 1.0) -->
195+
<y0> <!-- Optional (Defaults to the first row of the data file) -->
195196
0.200000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000316, 0.002296, 0.004783, 0.000003, 0.002507, 0.003436, 0.000003, 0.060000, 0.000079, 0.000003
196197
</y0>
197198
<states_transformer count="6"> <!-- Optional -->
@@ -208,7 +209,7 @@ There are three types of input files that must be provided:
208209
- **Data file:**
209210
The data file containing a mtrix of observed data and the initial value
210211
needed to solve the ODE. The data file should be a txt file written with the following format:
211-
212+
212213
```
213214
# The first row is gonna be used as the initial condition if y0 is not present in the config file
214215
31 3 # Matrix dimensions so the parsing is easier

example-files/nfkb_cuqdyn_config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ode_expr y_count="15" p_count="29">
99
nfkb
1010
</ode_expr>
11+
<time_scaling>0.001</time_scaling>
1112
<y0>
1213
0.200000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000316, 0.002296, 0.004783, 0.000003, 0.002507, 0.003436, 0.000003, 0.060000, 0.000079, 0.000003
1314
</y0>

modules/cuqdyn-c/include/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef struct
3232
{
3333
Tolerances tolerances;
3434
OdeExpr ode_expr;
35+
double time_scaling;
3536
Y0 y0;
3637
StatesTransformer states_transformer;
3738
} CuqdynConf;

modules/cuqdyn-c/src/cuqdyn.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
7474
exit(1);
7575
}
7676

77+
for (int i = 0; i < NV_LENGTH_S(times); ++i)
78+
{
79+
NV_Ith_S(times, i) = NV_Ith_S(times, i) * config->time_scaling;
80+
}
81+
7782
const sunrealtype t0 = NV_Ith_S(times, 0);
7883
N_Vector initial_condition = NULL;
7984

@@ -87,6 +92,8 @@ CuqdynResult *cuqdyn_algo(const char *data_file, const char *sacess_conf_file, c
8792
memcpy(NV_DATA_S(initial_condition), config->y0.array, config->y0.len * sizeof(sunrealtype));
8893
}
8994

95+
// Note: observed_data is a transposed matrix so the rows of the transposed
96+
// matrix are the columns of the original matrix
9097
const long n = SM_ROWS_D(observed_data);
9198
const long m = SM_COLUMNS_D(observed_data);
9299

modules/cuqdyn-c/src/functions.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ extern void eval_f_exprs(sunrealtype t, sunrealtype *y, sunrealtype *ydot, sunre
1414

1515
int ode_model_fun(sunrealtype t, N_Vector y, N_Vector ydot, void *user_data)
1616
{
17+
CuqdynConf *conf = get_cuqdyn_conf(get_cuqdyn_context());
18+
1719
N_Vector params_vec = user_data;
1820
sunrealtype *params = NV_DATA_S(params_vec);
1921
sunrealtype *ydot_pointer = NV_DATA_S(ydot);
2022
sunrealtype *y_pointer = NV_DATA_S(y);
2123

24+
t /= conf->time_scaling;
25+
2226
#ifdef DEBUG
2327
fprintf(stdout, "[DEBUG] [ODE MODEL FUN] ");
2428
fprintf(stdout, "t: %f\n", t);

modules/mexpreval/src/context.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ pub struct StatesTransformerC {
3939
pub struct CuqdynConfigC {
4040
tolerances: TolerancesC,
4141
ode_expr: OdeExprC,
42+
time_scaling: f64,
4243
y0: Y0C,
4344
states_transformer: StatesTransformerC,
4445
}
4546

47+
fn default_time_scaling() -> f64 {
48+
1.0
49+
}
50+
4651
#[derive(Debug, Getters, Deserialize, Clone, PartialEq)]
4752
#[serde(rename = "cuqdyn-config")]
4853
pub struct CuqdynConfigRs {
@@ -52,6 +57,9 @@ pub struct CuqdynConfigRs {
5257
#[serde(rename = "ode_expr")]
5358
ode_expr: OdeExpr,
5459
#[get = "pub"]
60+
#[serde(rename = "time_scaling", default = "default_time_scaling")]
61+
time_scaling: f64,
62+
#[get = "pub"]
5563
#[serde(default)]
5664
y0: Option<F64Vec>,
5765
#[get = "pub"]
@@ -103,6 +111,7 @@ impl CuqdynConfigRs {
103111
p_count: 4,
104112
expr: StringVec(vec!["lotka-volterra".to_string()]),
105113
},
114+
time_scaling: 1.0,
106115
y0: None,
107116
states_transformer: None,
108117
}
@@ -122,6 +131,7 @@ impl CuqdynConfigRs {
122131
"-y2 * (p3 - p4 * y1)".to_string(),
123132
]),
124133
},
134+
time_scaling: 1.0,
125135
y0: None,
126136
states_transformer: None,
127137
}
@@ -138,6 +148,7 @@ impl CuqdynConfigRs {
138148
p_count: 5,
139149
expr: StringVec(vec!["alpha-pinene".to_string()]),
140150
},
151+
time_scaling: 1.0,
141152
y0: None,
142153
states_transformer: None,
143154
}
@@ -160,6 +171,7 @@ impl CuqdynConfigRs {
160171
"p4 * y3 - p5 * y5".to_string(),
161172
]),
162173
},
174+
time_scaling: 1.0,
163175
y0: None,
164176
states_transformer: None,
165177
}
@@ -176,6 +188,7 @@ impl CuqdynConfigRs {
176188
p_count: 2,
177189
expr: StringVec(vec!["p1 * y1 * (1 - y1 / p2)".to_string()]),
178190
},
191+
time_scaling: 1.0,
179192
y0: None,
180193
states_transformer: None,
181194
}
@@ -208,6 +221,7 @@ impl CuqdynConfigRs {
208221
"p28 + p27 * y7 - p29 * y15".to_string(),
209222
]),
210223
},
224+
time_scaling: 0.001,
211225
y0: Some(F64Vec(vec![0.200000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000316, 0.002296, 0.004783, 0.000003, 0.002507, 0.003436, 0.000003, 0.060000, 0.000079, 0.000003])),
212226
states_transformer: Some(StatesTransformer {count: 6, expr: StringVec(vec![
213227
"y7".to_string(),
@@ -234,6 +248,7 @@ impl CuqdynConfigRs {
234248
p_count: 29,
235249
expr: StringVec(vec!["nfkb".to_string()]),
236250
},
251+
time_scaling: 0.001,
237252
y0: Some(F64Vec(vec![
238253
0.200000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000316, 0.002296, 0.004783,
239254
0.000003, 0.002507, 0.003436, 0.000003, 0.060000, 0.000079, 0.000003,
@@ -395,6 +410,7 @@ impl From<CuqdynConfigRs> for CuqdynContext {
395410
let c_config = CuqdynConfigC {
396411
tolerances,
397412
ode_expr,
413+
time_scaling: value.time_scaling,
398414
y0,
399415
states_transformer: observables,
400416
};
@@ -485,6 +501,7 @@ mod tests {
485501
<ode_expr y_count="15" p_count="29">
486502
nfkb
487503
</ode_expr>
504+
<time_scaling>0.001</time_scaling>
488505
<y0>
489506
0.200000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000316, 0.002296, 0.004783, 0.000003, 0.002507, 0.003436, 0.000003, 0.060000, 0.000079, 0.000003
490507
</y0>

0 commit comments

Comments
 (0)