Skip to content

Commit 00476e2

Browse files
committed
Now logging after calls to CheckConvergence
1 parent 64f1a96 commit 00476e2

File tree

14 files changed

+172
-117
lines changed

14 files changed

+172
-117
lines changed

check/TestPdlp.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ TEST_CASE("pdlp-restart-add-row", "[pdlp]") {
333333
}
334334

335335
TEST_CASE("hi-pdlp", "[pdlp]") {
336-
std::string model = "afiro"; //"adlittle";//"afiro";//
336+
std::string model = "afiro"; //"adlittle";//"afiro";//
337337
std::string model_file =
338338
std::string(HIGHS_DIR) + "/check/instances/" + model + ".mps";
339339
Highs h;
@@ -342,17 +342,15 @@ TEST_CASE("hi-pdlp", "[pdlp]") {
342342
h.setOptionValue("solver", kHiPdlpString);
343343
h.setOptionValue("kkt_tolerance", kkt_tolerance);
344344

345-
HighsInt pdlp_features_off =
346-
// kPdlpScalingOff +
347-
kPdlpRestartOff +
348-
kPdlpAdaptiveStepSizeOff;
345+
HighsInt pdlp_features_off =
346+
// kPdlpScalingOff +
347+
kPdlpRestartOff + kPdlpAdaptiveStepSizeOff;
349348
h.setOptionValue("pdlp_features_off", pdlp_features_off);
350349

351-
HighsInt pdlp_scaling = //0;
352-
kPdlpScalingRuiz
353-
//+ kPdlpScalingL2
354-
+ kPdlpScalingPC
355-
;
350+
HighsInt pdlp_scaling = // 0;
351+
kPdlpScalingRuiz
352+
//+ kPdlpScalingL2
353+
+ kPdlpScalingPC;
356354
h.setOptionValue("pdlp_scaling_mode", pdlp_scaling);
357355
h.setOptionValue("pdlp_step_size_strategy", 0);
358356
h.setOptionValue("pdlp_restart_strategy", 2);

highs/pdlp/CupdlpWrapper.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,8 @@ HighsStatus solveLpCupdlp(const HighsOptions& options, HighsTimer& timer,
207207

208208
// Print final solution using debugPdlpFinalSolutionLog
209209
debugPdlpFinalSolutionLog(w->debug_pdlp_log_file_,
210-
highs_solution.col_value.data(),
211-
lp.num_col_,
212-
highs_solution.row_dual.data(),
213-
lp.num_row_);
210+
highs_solution.col_value.data(), lp.num_col_,
211+
highs_solution.row_dual.data(), lp.num_row_);
214212
fclose(w->debug_pdlp_log_file_);
215213
model_status = HighsModelStatus::kUnknown;
216214
highs_solution.value_valid = value_valid;

highs/pdlp/HiPdlpWrapper.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
*/
1212
#include "pdlp/HiPdlpWrapper.h"
1313

14+
#include "pdlp/cupdlp/cupdlp_utils.h"
1415
#include "pdlp/hipdlp/logger.hpp"
1516
#include "pdlp/hipdlp/pdhg.hpp"
1617
#include "pdlp/hipdlp/restart.hpp"
17-
#include "pdlp/cupdlp/cupdlp_utils.h"
1818

1919
HighsStatus solveLpHiPdlp(HighsLpSolverObject& solver_object) {
2020
return solveLpHiPdlp(solver_object.options_, solver_object.timer_,
@@ -68,7 +68,9 @@ HighsStatus solveLpHiPdlp(const HighsOptions& options, HighsTimer& timer,
6868
}
6969

7070
// print col_value and row_dual
71-
debugPdlpFinalSolutionLog(pdlp.debug_pdlp_log_file_, pdlp_solution.col_value.data(), lp.num_col_, pdlp_solution.row_dual.data(), lp.num_row_);
71+
debugPdlpFinalSolutionLog(pdlp.debug_pdlp_log_file_,
72+
pdlp_solution.col_value.data(), lp.num_col_,
73+
pdlp_solution.row_dual.data(), lp.num_row_);
7274
pdlp.solveReturn();
7375
// --- Print Summary ---
7476
pdlp.logSummary();
@@ -118,15 +120,15 @@ HighsStatus solveLpHiPdlp(const HighsOptions& options, HighsTimer& timer,
118120
}
119121
assert(termination_status == TerminationStatus::OPTIMAL ||
120122
termination_status == TerminationStatus::TIMEOUT);
121-
//highs_solution.col_value = x;
122-
//highs_solution.col_value.resize(lp.num_col_);
123-
//highs_solution.row_dual = y;
124-
//lp.a_matrix_.product(highs_solution.row_value, highs_solution.col_value);
125-
//lp.a_matrix_.productTranspose(highs_solution.col_dual,
126-
// highs_solution.row_dual);
127-
//for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++)
128-
// highs_solution.col_dual[iCol] =
129-
// lp.col_cost_[iCol] - highs_solution.col_dual[iCol];
123+
// highs_solution.col_value = x;
124+
// highs_solution.col_value.resize(lp.num_col_);
125+
// highs_solution.row_dual = y;
126+
// lp.a_matrix_.product(highs_solution.row_value, highs_solution.col_value);
127+
// lp.a_matrix_.productTranspose(highs_solution.col_dual,
128+
// highs_solution.row_dual);
129+
// for (HighsInt iCol = 0; iCol < lp.num_col_; iCol++)
130+
// highs_solution.col_dual[iCol] =
131+
// lp.col_cost_[iCol] - highs_solution.col_dual[iCol];
130132
highs_solution.value_valid = true;
131133
highs_solution.dual_valid = true;
132134
return HighsStatus::kOk;

highs/pdlp/cupdlp/cupdlp_solver.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ void PDHG_Print_Iter(CUPDLPwork *pdhg) {
847847
const double gap_log_value = resobj->dRelObjGap;
848848
const double primal_feas_log_value = resobj->dPrimalFeas / (1.0 + scaling->dNormRhs);
849849
const double dual_feas_log_value = resobj->dDualFeas / (1.0 + scaling->dNormCost);
850+
850851
cupdlp_printf("%9d %+15.8e %+15.8e %+8.2e %10.2e %8.2e %7s [L]\n",
851852
timers->nIter, resobj->dPrimalObj, resobj->dDualObj,
852853
// resobj->dDualityGap, resobj->dPrimalFeas, resobj->dDualFeas,
@@ -863,7 +864,6 @@ void PDHG_Print_Iter_Average(CUPDLPwork *pdhg) {
863864
cupdlp_snprintf(timeString, 8, "%6.2fs", timers->dSolvingTime);
864865
else
865866
cupdlp_snprintf(timeString, 8, "%6ds", (cupdlp_int)timers->dSolvingTime);
866-
867867
CUPDLPscaling *scaling = pdhg->scaling;
868868
const double gap_log_value = resobj->dRelObjGapAverage;
869869
const double primal_feas_log_value = resobj->dPrimalFeasAverage / (1.0 + scaling->dNormRhs);
@@ -966,6 +966,22 @@ cupdlp_retcode PDHG_Solve(const cupdlp_int* has_variables, CUPDLPwork *pdhg) {
966966
iter_log_since_header++;
967967
}
968968

969+
debugPdlpFeasOptLog(pdhg->debug_pdlp_log_file_,
970+
pdhg->timers->nIter,
971+
pdhg->resobj->dPrimalObj,
972+
pdhg->resobj->dDualObj,
973+
pdhg->resobj->dRelObjGap,
974+
pdhg->resobj->dPrimalFeas / (1.0 + pdhg->scaling->dNormRhs),
975+
pdhg->resobj->dDualFeas / (1.0 + pdhg->scaling->dNormCost), "[L]");
976+
debugPdlpFeasOptLog(pdhg->debug_pdlp_log_file_,
977+
pdhg->timers->nIter,
978+
pdhg->resobj->dPrimalObjAverage,
979+
pdhg->resobj->dDualObjAverage,
980+
pdhg->resobj->dRelObjGapAverage,
981+
pdhg->resobj->dPrimalFeasAverage / (1.0 + pdhg->scaling->dNormRhs),
982+
pdhg->resobj->dDualFeasAverage / (1.0 + pdhg->scaling->dNormCost), "[A]");
983+
debugPdlpIterHeaderLog(pdhg->debug_pdlp_log_file_);
984+
969985
// Termination check printing is only done when printing is full
970986
int termination_print = bool_print && full_print;
971987
if (PDHG_Check_Termination(pdhg, termination_print)) {

highs/pdlp/cupdlp/cupdlp_step.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void PDHG_primalGradientStep(CUPDLPwork *work, CUPDLPvec *xUpdate,
1919
CUPDLPproblem *problem = work->problem;
2020

2121
// print norm of A'y
22-
double aty_norm = 0.0;
23-
cupdlp_twoNorm(work, problem->nCols, ATy->data, &aty_norm);
24-
work->debug_pdlp_data_.aty_norm = aty_norm;
22+
double debug_pdlp_data_aty_norm = 0.0;
23+
cupdlp_twoNorm(work, problem->nCols, ATy->data, &debug_pdlp_data_aty_norm);
24+
work->debug_pdlp_data_.aty_norm = debug_pdlp_data_aty_norm;
2525

2626
#if !defined(CUPDLP_CPU) && USE_KERNELS
2727
cupdlp_pgrad_cuda(xUpdate->data, x->data, problem->cost,
@@ -197,10 +197,10 @@ void PDHG_Update_Iterate_Constant_Step_Size(CUPDLPwork *pdhg) {
197197

198198
Ax(pdhg, ax, x);
199199
//pint norm of Ax
200-
double ax_norm = 0.0;
200+
double debug_pdlp_data_ax_norm = 0.0;
201201
cupdlp_twoNorm(pdhg, problem->nRows, ax->data,
202-
&ax_norm);
203-
pdhg->debug_pdlp_data_.ax_norm = ax_norm;
202+
&debug_pdlp_data_ax_norm);
203+
pdhg->debug_pdlp_data_.ax_norm = debug_pdlp_data_ax_norm;
204204
ATy(pdhg, aty, y);
205205

206206
// x^{k+1} = proj_{X}(x^k - dPrimalStep * (c - A'y^k))
@@ -410,9 +410,16 @@ void PDHG_Compute_Average_Iterate(CUPDLPwork *work) {
410410
Ax(work, iterates->axAverage, iterates->xAverage);
411411
ATy(work, iterates->atyAverage, iterates->yAverage);
412412

413-
cupdlp_float ax_norm = 0.0;
414-
cupdlp_twoNormSquared(work, lp->nCols, iterates->axAverage->data, &ax_norm);
415-
work->debug_pdlp_data_.ax_norm = ax_norm;
413+
cupdlp_float debug_pdlp_data_ax_average_norm = 0.0;
414+
cupdlp_twoNormSquared(work, lp->nCols, iterates->axAverage->data, &debug_pdlp_data_ax_average_norm);
415+
work->debug_pdlp_data_.ax_average_norm = debug_pdlp_data_ax_average_norm;
416+
417+
/*
418+
// Uncomment this once Yanyu is computing aty_average_norm
419+
cupdlp_float debug_pdlp_data_aty_average_norm = 0.0;
420+
cupdlp_twoNormSquared(work, lp->nCols, iterates->atyAverage->data, &debug_pdlp_data_aty_average_norm);
421+
work->debug_pdlp_data_.aty_average_norm = debug_pdlp_data_aty_average_norm;
422+
*/
416423
}
417424

418425
void PDHG_Update_Average(CUPDLPwork *work) {

highs/pdlp/cupdlp/cupdlp_utils.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,19 @@ void debugPdlpIterLog(FILE* file, const int iter_num, const struct DebugPdlpData
18031803
beta);
18041804
}
18051805

1806-
void debugPdlpFeasOptLog(FILE* file) {
1806+
void debugPdlpFeasOptLog(FILE* file,
1807+
const int iter_num,
1808+
const double primal_obj, const double dual_obj,
1809+
const double gap, const double primal_feas, const double dual_feas,
1810+
const char* type) {
1811+
fprintf(file,
1812+
"%6d Feasibility-optimality %s\n"
1813+
" primal_obj = %11.4g\n"
1814+
" dual_obj = %11.4g\n"
1815+
" gap = %11.4g\n"
1816+
" primal_feas = %11.4g\n"
1817+
" dual_feas = %11.4g\n",
1818+
iter_num, type, primal_obj, dual_obj, gap, primal_feas, dual_feas);
18071819
}
18081820

18091821
void debugPdlpRestartLog(FILE* file, const int iter_num, const double current_score, const double average_score) {

highs/pdlp/cupdlp/cupdlp_utils.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ void writeSol(const char *fout, cupdlp_int nCols, cupdlp_int nRows,
196196
void debugPdlpIterHeaderLog(FILE* file);
197197
void debugPdlpDataInitialise(struct DebugPdlpData* debug_pdlp);
198198
void debugPdlpIterLog(FILE* file, const int iter_num, const struct DebugPdlpData* debug_pdlp, const double beta);
199-
void debugPdlpFeasOptLog(FILE* file);
199+
void debugPdlpFeasOptLog(FILE* file,
200+
const int iter_num,
201+
const double primal_obj, const double dual_obj,
202+
const double gap, const double primal_feas, const double dual_feas,
203+
const char* type);
200204
void debugPdlpRestartLog(FILE* file, const int iter_num, const double current_score, const double average_score);
201205
void debugPdlpRestarScoretLog(FILE* file, const double weight_squared, const double primal_feas, const double dual_feas, const double obj_gap);
202206
void debugPdlpFinalSolutionLog(FILE* file, const double* x, int nCols, const double* y, int nRows);

highs/pdlp/hipdlp/logger.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void Logger::print_header() {
6363
info("------------------------------------------------------------");
6464
}
6565

66-
6766
void Logger::print_params(const PrimalDualParams& params) {
6867
info("\nSolver Parameters:");
6968
std::stringstream ss;

0 commit comments

Comments
 (0)