Skip to content

Commit 38f0061

Browse files
committed
transforming the states is working but not properly tested
1 parent 5b03bb2 commit 38f0061

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<xml>
2+
<run>
3+
<typebench>customized</typebench>
4+
<id>0</id>
5+
<log_scale>1</log_scale>
6+
<output>0</output>
7+
<verbose>1</verbose>
8+
<local_search>1</local_search>
9+
<stopping_criteria>
10+
<maxevaluation>3e3</maxevaluation>
11+
<maxtime>1e10</maxtime>
12+
<vtr>0</vtr>
13+
</stopping_criteria>
14+
</run>
15+
<method name="ScatterSearch">
16+
<user_options>
17+
<weight>default</weight>
18+
<tolc>default</tolc>
19+
<prob_bound>default</prob_bound>
20+
<nstuck_solution>default</nstuck_solution>
21+
</user_options>
22+
<global_options>
23+
<dim_ref>default</dim_ref>
24+
<ndiverse>default</ndiverse>
25+
<combination>default</combination>
26+
<n_stuck>default</n_stuck>
27+
</global_options>
28+
<local_options>
29+
<solver>nl2sol.dn2fb</solver>
30+
<tol>0</tol>
31+
<evalmax>9e3</evalmax>
32+
<iterprint>0</iterprint>
33+
<n1>1</n1>
34+
<n2>10</n2>
35+
<balance>0.25</balance>
36+
<bestx>default</bestx>
37+
</local_options>
38+
</method>
39+
<parallelization name="cooperative">
40+
<!-- saCeSS options -->
41+
<reception_threshold>1</reception_threshold>
42+
<evals_threshold>1</evals_threshold>
43+
<mult_num_sendSol>10</mult_num_sendSol>
44+
<minimum_num_sendSol>20</minimum_num_sendSol>
45+
<!-- CeSS option: migration time -->
46+
<migration_max_time>10</migration_max_time>
47+
</parallelization>
48+
49+
<problem>
50+
<dim> 29 </dim>
51+
<neq> 0 </neq>
52+
<ineq> 0 </ineq>
53+
<int_var> 0 </int_var>
54+
<bin_var> 0 </bin_var>
55+
<lb>
56+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58+
0, 0, 0, 0, 0, 0, 0, 0, 0
59+
</lb>
60+
<ub>
61+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
62+
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
63+
6, 6, 6, 6, 6, 6, 6, 6, 6
64+
</ub>
65+
<point>
66+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
67+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
68+
1, 1, 1, 1, 1, 1, 1, 1, 1
69+
</point>
70+
</problem>
71+
72+
</xml>

modules/cuqdyn-c/src/states_transformer.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Created by borja on 12/06/25.
33
//
44
#include <nvector/nvector_serial.h>
5+
#include <stdio.h>
56
#include <sunmatrix/sunmatrix_dense.h>
7+
#include <unistd.h>
68

79
#include "config.h"
810
#include "matlab.h"
@@ -20,26 +22,26 @@ SUNMatrix transform_states(SUNMatrix states)
2022

2123
const int rows = SM_ROWS_D(states);
2224
const int cols = SM_COLUMNS_D(states);
23-
25+
2426
SUNMatrix transformed_result = NewDenseMatrix(rows, conf->states_transformer.count + 1); // + 1 adds the time column
25-
27+
sunrealtype *output = malloc(conf->states_transformer.count * sizeof(sunrealtype));
28+
2629
for (int i = 0; i < rows; ++i)
2730
{
2831
N_Vector input = copy_matrix_row(states, i, 1, cols);
29-
sunrealtype *output = malloc(conf->states_transformer.count * sizeof(sunrealtype));
3032

3133
eval_states_transformer_expr(NV_DATA_S(input), output, get_cuqdyn_context());
3234

3335
SM_ELEMENT_D(transformed_result, i, 0) = SM_ELEMENT_D(states, i, 0);
3436
for (int j = 0; j < conf->states_transformer.count; ++j)
3537
{
36-
SM_ELEMENT_D(transformed_result, i, j + 1) = NV_Ith_S(input, j);
38+
SM_ELEMENT_D(transformed_result, i, j + 1) = output[j];
3739
}
3840

3941
N_VDestroy(input);
40-
free(output);
4142
}
4243

44+
free(output);
4345
SUNMatDestroy(states);
4446
return transformed_result;
4547
}

modules/mexpreval/src/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,14 @@ impl From<CuqdynConfigRs> for CuqdynContext {
372372
}
373373
};
374374

375-
let obs_exprs = if let Some(states_transformer) = value.states_transformer.as_ref() {
376-
states_transformer
375+
let (obs_exprs, obs_exprs_count) = if let Some(states_transformer) = value.states_transformer.as_ref() {
376+
(states_transformer
377377
.expr
378378
.iter()
379379
.map(|a| CString::new(a.as_bytes()).unwrap())
380-
.collect::<Vec<CString>>()
380+
.collect::<Vec<CString>>(), states_transformer.count)
381381
} else {
382-
vec![]
382+
(vec![], 0)
383383
};
384384

385385
let obs_exprs_c = obs_exprs
@@ -388,8 +388,8 @@ impl From<CuqdynConfigRs> for CuqdynContext {
388388
.collect::<Vec<*const c_char>>();
389389

390390
let observables = StatesTransformerC {
391-
count: obs_exprs.len() as i32,
392-
exprs: if obs_exprs.len() >= 1 { obs_exprs_c.as_ptr() } else { std::ptr::null() },
391+
count: obs_exprs_count,
392+
exprs: if obs_exprs_count >= 1 { obs_exprs_c.as_ptr() } else { std::ptr::null() },
393393
};
394394

395395
let c_config = CuqdynConfigC {

0 commit comments

Comments
 (0)