Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mex interface - add checks and DAE SQP example #456

Merged
merged 58 commits into from Sep 10, 2019

Conversation

@FreyJo
Copy link
Member

commented Aug 27, 2019

This PR builds on top of #452
I extended the MEX integrator to have all the DAE capabilities from the core.
There were some setters/getters to add and bugs to fix.

Modified the sim_inverted_pendulum to use the new external function generation code.
Made an equivalent Matlab example to illustrate how to simulate DAEs from Matlab.

@codecov

This comment has been minimized.

Copy link

commented Aug 27, 2019

Codecov Report

Merging #456 into master will increase coverage by 0.07%.
The diff coverage is 31.25%.

@@            Coverage Diff             @@
##           master     #456      +/-   ##
==========================================
+ Coverage   69.46%   69.53%   +0.07%     
==========================================
  Files          45       45              
  Lines       10628    10643      +15     
==========================================
+ Hits         7383     7401      +18     
+ Misses       3245     3242       -3
@codecov

This comment has been minimized.

Copy link

commented Aug 27, 2019

Codecov Report

Merging #456 into master will decrease coverage by 0.79%.
The diff coverage is 42.1%.

@@            Coverage Diff            @@
##           master     #456     +/-   ##
=========================================
- Coverage   69.56%   68.76%   -0.8%     
=========================================
  Files          45       45             
  Lines       10639    11068    +429     
=========================================
+ Hits         7401     7611    +210     
- Misses       3238     3457    +219

@FreyJo FreyJo requested a review from giaf Aug 27, 2019

@giaf

This comment has been minimized.

Copy link
Collaborator

commented Aug 28, 2019

I would look at this after the previous PR has been merged, otherwise there are too many changes and it's difficult to get to which PR they belong

{
mem->set_sim_guess[ii] = false;
}

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

Always remember to align after you allocate an array of bool (like here, so I only want to warn). It is actually a bit tricky, because sizeof(bool) may be 1, 2 or 4 bytes depending on the compiler (even if just 1 bit is enough to hold the 0-1 information). In case of 1 or 2 bytes size, if alignment doesn't happen after, it will screw up what is coming after and give rise to nasty bugs on certain architectures/compilers. So this may be a reason to prefer int which I didn't consider before.

FreyJo added 2 commits Sep 10, 2019
rename folders examples/matlab_mex -> examples/acados_matlab_octave, …
…interfaces/matlab_mex -> interfaces/acados_matlab_octave
{
config->sim_solver->memory_set(config->sim_solver, work->sim_in->dims, mem->sim_solver,
"guesses_blasfeo", mem->sim_guess);
mem->set_sim_guess[0] = false;

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

maybe add a comment to point out that this means the guess is only used the first time

@@ -142,10 +142,45 @@ void ocp_nlp_dynamics_disc_dims_set(void *config_, void *dims_, const char *dim,
}
else
{
assert(0 == 1); // dimension type not available in module
printf("\ndimension type not available in module\n");

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

a bit more specific: something like ("dimension type %s not available in module ocp_nlp_dynamics_disc", field)

{
if ( *value > 0)
{
printf("\nerror: discrete dynamics with nz>0\n");

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

more specific here too

}
else
{
printf("\ndimension type not available in module\n");

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

more specific here too

@@ -1718,6 +1719,11 @@ void ocp_nlp_sqp_get(void *config_, void *mem_, const char *field, void *return_
int *value = return_value_;
*value = mem->stat_n;
}
else if (!strcmp("mem_nlp", field))

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

nlp_mem instead? (as the structure member name)

@@ -1290,6 +1294,9 @@ void *sim_gnsf_memory_assign(void *config, void *dims_, void *opts_, void *raw_m
int nK2 = num_stages * nxz2;
int nZ1 = num_stages * nz1;

// initial align
align_char_to(8, &c_ptr);

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

did you add the 8 bytes to the corresponding calculate_size? (it doesn't look like from the github changes)

@@ -548,6 +558,9 @@ static void *sim_irk_workspace_cast(void *config_, void *dims_, void *opts_, voi

char *c_ptr = (char *) raw_memory;

// initial align
align_char_to(8, &c_ptr);

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

same here, did you add the 8 bytes to the calculate_size ?

@@ -362,6 +362,9 @@ void *sim_lifted_irk_memory_assign(void *config, void *dims_, void *opts_, void

int num_steps = opts->num_steps;

// initial align
align_char_to(8, &c_ptr);

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

same here, did you add the 8 bytes to the calculate size?

fprintf('\nstatus = %d, sqp_iter = %d, time_ext = %f [ms], time_int = %f [ms] (time_lin = %f [ms], time_qp_sol = %f [ms]), Pel = %f\n', status, sqp_iter, time_ext*1e3, time_tot*1e3, time_lin*1e3, time_qp_sol*1e3, electrical_power);

if 0
stat = ocp.get('stat');

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

for another PR, this stuff could go into a ocp.print('stat')

obj.opts_struct.qp_solver = 'partial_condensing_hpipm';
obj.opts_struct.qp_solver_iter_max = 50;
obj.opts_struct.qp_solver_cond_N = 5; % for partial condensing_hpipm

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

this is unsafe, and will seg fault or the like if N<5

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

if nothing is set, the C code will choose as default value N, i.e. no partial condensing

/* dims */
int nx, nu;
int nz = 0;
int ny = 0, ny_e = 0;

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

split in two lines?

ocp_nlp_cost_model_set(config, dims, in, ii, "W", W);
}
}
// TODO: else complain?

This comment has been minimized.

Copy link
@giaf

giaf Sep 10, 2019

Collaborator

yep complain (I guess in another PR)

This comment has been minimized.

Copy link
@FreyJo

FreyJo Sep 10, 2019

Author Member

done in this one, for W, W_e.

@giaf giaf merged commit 8ba9822 into master Sep 10, 2019

2 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@FreyJo FreyJo deleted the mex_interface branch Sep 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.