Skip to content

Commit

Permalink
add new function for warmstart
Browse files Browse the repository at this point in the history
  • Loading branch information
nychiang committed Jun 3, 2024
1 parent f338053 commit 49094a9
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/Interface/hiopInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,38 @@ class hiopInterfaceBase
{
return true;
}


/**
* This method is used to provide an user all the hiop iterate
* procedure. @see solution_callback() for an explanation of the parameters.
*
* @param[in] x array of (local) entries of the primal variables (managed by Umpire, see note below)
* @param[in] z_L array of (local) entries of the dual variables for lower bounds (managed by Umpire, see note below)
* @param[in] z_U array of (local) entries of the dual variables for upper bounds (managed by Umpire, see note below)
* @param[in] yc array of (local) entries of the dual variables for equality constraints (managed by Umpire, see note below)
* @param[in] yd array of (local) entries of the dual variables for inequality constraints (managed by Umpire, see note below)
* @param[in] s array of the slacks added to transfer inequalities to equalities (managed by Umpire, see note below)
* @param[in] v_L array of (local) entries of the dual variables for constraint lower bounds (managed by Umpire, see note below)
* @param[in] v_U array of (local) entries of the dual variables for constraint upper bounds (managed by Umpire, see note below)
*
* @note HiOp's option `callback_mem_space` can be used to change the memory location of array parameters managaged by Umpire.
* More specifically, when `callback_mem_space` is set to `host` (and `mem_space` is `device`), HiOp transfers the
* arrays from device to host first, and then passes/returns pointers on host for the arrays managed by Umpire. These pointers
* can be then used in host memory space (without the need to rely on or use Umpire).
*
*/
virtual bool ws_iterate_callback(const double* x,
const double* z_L,
const double* z_U,
const double* yc,
const double* yd,
const double* s,
const double* v_L,
const double* v_U)
{
return true;
}

/**
* A wildcard function used to change the primal variables.
*
Expand Down
69 changes: 68 additions & 1 deletion src/Optimization/hiopNlpFormulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ bool hiopNlpFormulation::user_callback_iterate(int iter,
hiopVectorPar x_host(n_vars_, vec_distrib_, comm_);
x.copy_to_vectorpar(x_host);

hiopVectorPar s_host(n_vars_, vec_distrib_, comm_);
hiopVectorPar s_host(n_cons_ineq_, vec_distrib_, comm_);
s.copy_to_vectorpar(s_host);

hiopVectorPar zl_host(n_vars_, vec_distrib_, comm_);
Expand Down Expand Up @@ -1271,6 +1271,73 @@ bool hiopNlpFormulation::user_callback_iterate(int iter,
return bret;
}

bool hiopNlpFormulation::user_callback_ws_iterate(hiopVector& x,
hiopVector& z_L,
hiopVector& z_U,
hiopVector& y_c,
hiopVector& y_d,
hiopVector& s,
hiopVector& v_L,
hiopVector& v_U)
{
assert(x.get_size()==n_vars_);
assert(y_c.get_size() == n_cons_eq_);
assert(y_d.get_size() == n_cons_ineq_);

bool bret{false};

if(options->GetString("callback_mem_space")=="host" && options->GetString("mem_space")=="device") {

#if !defined(HIOP_USE_MPI)
int* vec_distrib_ = nullptr;
MPI_Comm comm_ = MPI_COMM_SELF;
#endif
hiopVectorPar x_host(n_vars_, vec_distrib_, comm_);
x.copy_to_vectorpar(x_host);

hiopVectorPar zl_host(n_vars_, vec_distrib_, comm_);
z_L.copy_to_vectorpar(zl_host);

hiopVectorPar zu_host(n_vars_, vec_distrib_, comm_);
z_U.copy_to_vectorpar(zu_host);

hiopVectorPar yc_host(n_cons_eq_, vec_distrib_, comm_);
y_c.copy_to_vectorpar(yc_host);

hiopVectorPar yd_host(n_cons_ineq_, vec_distrib_, comm_);
y_d.copy_to_vectorpar(yd_host);

hiopVectorPar s_host(n_cons_ineq_, vec_distrib_, comm_);
s.copy_to_vectorpar(s_host);

hiopVectorPar vl_host(n_cons_ineq_, vec_distrib_, comm_);
v_L.copy_to_vectorpar(zl_host);

hiopVectorPar vu_host(n_cons_ineq_, vec_distrib_, comm_);
v_U.copy_to_vectorpar(zu_host);

bret = interface_base.ws_iterate_callback(x_host.local_data_const(),
zl_host.local_data_const(),
zu_host.local_data_const(),
yc_host.local_data_const(),
yd_host.local_data_const(),
s_host.local_data_const(),
vl_host.local_data_const(),
vu_host.local_data_const());
} else {
bret = interface_base.ws_iterate_callback(x.local_data_const(),
z_L.local_data_const(),
z_U.local_data_const(),
y_c.local_data_const(),
y_d.local_data_const(),
s.local_data_const(),
v_L.local_data_const(),
v_U.local_data_const());
}
return bret;
}


bool hiopNlpFormulation::user_force_update(int iter,
double& obj_value,
hiopVector& x,
Expand Down
10 changes: 10 additions & 0 deletions src/Optimization/hiopNlpFormulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ class hiopNlpFormulation
double alpha_pr,
int ls_trials);

virtual
bool user_callback_ws_iterate(hiopVector& x,
hiopVector& z_L,
hiopVector& z_U,
hiopVector& y_c,
hiopVector& y_d,
hiopVector& s,
hiopVector& v_L,
hiopVector& v_U);

virtual
bool user_force_update(int iter,
double& obj_value,
Expand Down

0 comments on commit 49094a9

Please sign in to comment.