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

Bug in Optim pluggin with --with-debug #384

Closed
Jordan08 opened this issue Jun 4, 2019 · 12 comments
Closed

Bug in Optim pluggin with --with-debug #384

Jordan08 opened this issue Jun 4, 2019 · 12 comments

Comments

@Jordan08
Copy link
Member

Jordan08 commented Jun 4, 2019

  • A lot of warning appear when using Gaol (unused variable)
  • a bug appear line 91 of ibex_LSmear.cpp (out of index of a vector)
@bneveu
Copy link
Contributor

bneveu commented Jun 4, 2019

chez moi, je n'ai pas cette erreur en compilant ibex_LSmear.cpp en mode debug
il n'a que le warning de gaol

133/202] Compiling plugins/optim/src/bisector/ibex_LSmear.cpp
In file included from 3rd/include/gaol/gaol_common.h:37:0,
from 3rd/include/gaol/gaol:35,
from 3rd/include/gaol/gaol.h:33,
from src/arithmetic/ibex_Interval.h:25,
from ../src/arithmetic/ibex_IntervalVector.h:18,
from ../src/strategy/ibex_Cell.h:14,
from ../src/bisector/ibex_Bsc.h:14,
from ../src/bisector/ibex_SmearFunction.h:14,
from ../plugins/optim/src/bisector/ibex_LSmear.h:12,
from ../plugins/optim/src/bisector/ibex_LSmear.cpp:10:
3rd/include/gaol/gaol_port.h:148:21: warning: ‘gaol::NaN_val’ defined but not used [-Wunused-variable]
static uintdouble NaN_val = {{IFBIGENDIAN(0x7ff80000, 0x0)}};

@Jordan08
Copy link
Member Author

Jordan08 commented Jun 4, 2019

voici le warning qui apparait une centaine de fois:
../../OUT/include/ibex/3rd/gaol/gaol_port.h:148:21: warning: ‘gaol::NaN_val’ defined but not used [-Wunused-variable]
static uintdouble NaN_val = {{IFBIGENDIAN(0x7ff80000, 0x0)}};
^

  • et pour le bug, il apparait à l'exécution des utest:
    ./waf configure --prefix=../OUT --with-optim --lp-lib=soplex --with-debug
    ./waf install utest

from /home/jninin/Documents/WORK/DEV/IBEX/GIT3/ibex-lib: Error: 1 test failed

Test 'utest_optim_Optimizer' failed with return code -6
stderr:
utest_optim_Optimizer: ../../OUT/include/ibex/ibex_Vector.h:291: double& ibex::Vector::operator: Assertion `i>=0 && i<n' failed.
stdout:
..ESC[32m optimization successful!
ESC[0m
f* in [-20,-20]
(best bound)

x* = (3.1416 ; -10 ; -10)
(best feasible point)

relative precision on f*: 0ESC[32m [passed] ESC[0m
absolute precision on f*: 0ESC[32m [passed] ESC[0m
cpu time used: 0.0139601s
number of cells: 2

.ESC[31m no feasible point found (the problem may be infeasible)
ESC[0m
f* in [-0.0999999,1.00001e-10]
(best bound)

x* = --
(no feasible point found)

relative precision on f*: 1.00001e+09
absolute precision on f*: 0.100001ESC[32m [passed] ESC[0m
cpu time used: 6.00001e-06s
number of cells: 0

.

@gchabert
Copy link
Contributor

gchabert commented Jun 5, 2019

Il doit effectivement y avoir un bug dans LSmear.
Bertrand, c'est peut être un cas extrême auquel vous n'avez pas pensé: le test qui échoue consiste à résoudre:

x in [1,+oo]
minimiser x
sous la contrainte x>=0

Voici la trace :

#3  0x00007ffff7ab0142 in __GI___assert_fail (assertion=0x555555829028 "i>=0 && i<n", file=0x555555829008 "../src/arithmetic/ibex_Vector.h", line=291, 
    function=0x555555829a60 <ibex::Vector::operator[](int)::__PRETTY_FUNCTION__> "double& ibex::Vector::operator[](int)") at assert.c:101
#4  0x000055555559319e in ibex::Vector::operator[] (this=0x7fffffffd6e0, i=3) at ../src/arithmetic/ibex_Vector.h:291
#5  0x000055555564a9fc in ibex::LSmear::getdual (this=0x555555950c40, J=..., box=..., dual=...) at ../plugins/optim/src/bisector/ibex_LSmear.cpp:91
#6  0x000055555564accd in ibex::LSmear::var_to_bisect (this=0x555555950c40, J=..., box=...) at ../plugins/optim/src/bisector/ibex_LSmear.cpp:121
#7  0x00005555555b4816 in ibex::SmearFunction::choose_var (this=0x555555950c40, cell=...) at ../src/bisector/ibex_SmearFunction.cpp:82
#8  0x000055555559f33c in ibex::Bsc::bisect (this=0x555555950c40, cell=...) at ../src/bisector/ibex_Bsc.h:153
#9  0x000055555559db8c in ibex::Optimizer::optimize (this=0x7fffffffda60) at ../plugins/optim/src/strategy/ibex_Optimizer.cpp:404
#10 0x000055555559d165 in ibex::Optimizer::optimize (this=0x7fffffffda60, init_box=..., obj_init_bound=1e-10) at ../plugins/optim/src/strategy/ibex_Optimizer.cpp:268

Gilles

@bneveu
Copy link
Contributor

bneveu commented Jun 5, 2019 via email

@gchabert
Copy link
Contributor

gchabert commented Jun 5, 2019

ce probleme chez moi passe sans bug en mode debug (dans la branche que j'avais déposée)

Pardon, il faut prendre x in [-oo,+oo].
Le problème n'apparaît pas avec SmearSumRelative, je pense donc qu'il y a bien un petit bug avec LSmear.
Gilles

@bneveu
Copy link
Contributor

bneveu commented Jun 5, 2019 via email

@gchabert
Copy link
Contributor

gchabert commented Jun 5, 2019

Merci pour le patch, je l'ai appliqué mais il ne résout pas notre problème.
Cela dit, tu as raison, j'ai été trop vite car le système est résolu sans problème si on lance une optimisation classique. En fait, dans le test unitaire qui pose problème, l'erreur se produit car on utilise un loup initial.

Mais, bref, peu importe, pour éviter de te faire perdre encore du temps inutilement, j'ai créé le petit bout de code c++ qui, normalement, reproduit le problème:

	SystemFactory f;
	const ExprSymbol& x=ExprSymbol::new_();
	f.add_var(x);
	f.add_ctr(x>=0);
	f.add_goal(x);

	System sys(f);
	
	ExtendedSystem ext_sys(sys);

	IntervalVector box(2);
	box[0]=Interval::neg_reals();
	box[1]=Interval::zero();

	LSmear lsmear(ext_sys,0.1);
	lsmear.bisect(box);

Peux-tu me dire si tu parviens à le reproduire cette fois?

@bneveu
Copy link
Contributor

bneveu commented Jun 5, 2019 via email

@bneveu
Copy link
Contributor

bneveu commented Jun 6, 2019

J'ai corrigé le bug ;
Ca ne change rien aux résultats des benchs.

Voici la nouvelle version de ibex_LSmear.cpp (je n'arrive pas à attacher le fichier cpp)


//============================================================================
// I B E X
// File : ibex_LSmear.cpp
// Author : Ignacio Araya, Bertrand Neveu
// License : See the LICENSE file
// Created : May, 25 2017
// Last Update : June, 6 2019
//============================================================================

#include "ibex_LSmear.h"
#include "ibex_ExtendedSystem.h"
#include "ibex_Random.h"
#include "ibex_OptimLargestFirst.h"

using std::pair;

namespace ibex {

LSmear::~LSmear() {
delete mylinearsolver;
}

LPSolver::Status_Sol LSmear::getdual(IntervalMatrix& J, const IntervalVector& box, Vector& dual) const {

int  _goal_var = goal_var();
bool minimize=true;
if (_goal_var == -1){
  _goal_var = RNG::rand()%box.size();
  minimize=RNG::rand()%2;
}
 
// The linear system is created
mylinearsolver->clean_ctrs();
mylinearsolver->set_bounds(box);
mylinearsolver->set_bounds_var(_goal_var, Interval(-1e10,1e10));

int nb_lctrs[sys.f_ctrs.image_dim()]; /* number of linear constraints generated by nonlinear constraint*/

for (int i=0; i<sys.f_ctrs.image_dim(); i++) {
  
	Vector row1(sys.nb_var);
	Interval ev(0.0);
	for (int j=0; j<sys.nb_var; j++) {
		row1[j] = J[i][j].mid();
		ev -= Interval(row1[j])*box[j].mid();
	}
	ev+= sys.f_ctrs.eval(i,box.mid()).mid();

	nb_lctrs[i]=1;
	if (i!=goal_ctr()) {
	  if (sys.ops[i] == LEQ || sys.ops[i] == LT){
	    mylinearsolver->add_constraint( row1, sys.ops[i], (-ev).ub());
	  }
	  else if (sys.ops[i] == GEQ || sys.ops[i] == GT)
			mylinearsolver->add_constraint( row1, sys.ops[i], (-ev).lb());
	  else { //op=EQ
			mylinearsolver->add_constraint( row1, LT, (-ev).ub());
			mylinearsolver->add_constraint( row1, GT, (-ev).lb());
			nb_lctrs[i]=2;
	  }
	}
	else if (goal_to_consider(J,i) ||sys.f_ctrs.image_dim()==1 ) 
	  mylinearsolver->add_constraint( row1, LEQ, (-ev).ub());
	else // the goal is equal to a variable : the goal constraint is useless.
	  nb_lctrs[i]=0;
	
}


//the linear system is solved
LPSolver::Status_Sol stat=LPSolver::UNKNOWN;
try {
	mylinearsolver->set_obj_var(_goal_var, (minimize)? 1.0:-1.0);

	stat = mylinearsolver->solve();

	if (stat == LPSolver::OPTIMAL) {
	  // the dual solution : used to compute the bound
	  Vector dual_solution(mylinearsolver->get_nb_rows());  //
	  dual_solution = mylinearsolver->get_dual_sol();

	  int k=0; //number of multipliers != 0
	  int ii=0;
	  // writing the dual solution in the dual Vector of dimension +
	  for (int i=0; i< sys.nb_var; i++)
	    dual[i]=dual_solution[i];
	  for (int i=0; i<sys.f_ctrs.image_dim(); i++) {
	    if (nb_lctrs[i]==2) {
	      dual[sys.nb_var+i]=dual_solution[sys.nb_var+ii]+dual_solution[sys.nb_var+ii+1]; ii+=2;
	    }
	    else  if (nb_lctrs[i]==1) {
	      dual[sys.nb_var+i]=dual_solution[sys.nb_var+ii]; ii++;
	    }
	    else {
	      dual[sys.nb_var+i]=0.0;
	    }
	    if (std::abs(dual[sys.nb_var+i])>1e-10) k++;
	  }
	  
	  if(k<2) { stat = LPSolver::UNKNOWN; }
	}
} catch (LPException&) {
	stat = LPSolver::UNKNOWN;
}
return stat;

}

int LSmear::var_to_bisect(IntervalMatrix& J, const IntervalVector& box) const {
int lvar = -1;

//Linearization
LPSolver::Status_Sol stat = LPSolver::UNKNOWN;

Vector dual_solution(sys.nb_var+sys.f_ctrs.image_dim());

if (lsmode==LSMEAR_MG) { //compute the Jacobian in the midpoint
	IntervalMatrix J2(sys.f_ctrs.image_dim(), sys.nb_var);
	IntervalVector box2(IntervalVector(box.mid()).inflate(1e-8));
	//		IntervalVector box2(IntervalVector(box.random()));
	box2 &= box;

	sys.f_ctrs.jacobian(box2,J2);
	stat = getdual(J2, box, dual_solution);

} else if (lsmode==LSMEAR) {
	stat = getdual(J, box, dual_solution);
}


if (stat == LPSolver::OPTIMAL) {
	double max_Lmagn = 0.0;
	int k=0;

	for (int j=0; j<sys.nb_var; j++) {
		Interval lsmear=Interval(0.0);
		if ((!too_small(box,j)) && (box[j].mag() <1 ||  box[j].diam()/ box[j].mag() >= prec(j))){
			lsmear=dual_solution[j];

			for (int i=0; i<sys.f_ctrs.image_dim(); i++){
			  lsmear += dual_solution[sys.nb_var+i] * J[i][j];
			}
		}

		lsmear*=(box[j].diam());

		if (lsmear.mag() > 1e-10  && (j!=goal_var() || mylinearsolver->get_obj_value().mid() > box[goal_var()].lb() )) {
			k++;
			if (lsmear.mag() > max_Lmagn) {
				max_Lmagn = lsmear.mag();
				lvar = j;
			}
		}
	}

	if (k==1 && lvar==goal_var()) { lvar=-1; }
}
if (lvar==-1) {
  //	  std::cout << "ssr " << std::endl;
  lvar=SmearSumRelative::var_to_bisect(J, box);
}
//	std::cout << "lsmear " << lvar << std::endl;
return lvar;

}

} /* namespace ibex */

@gchabert
Copy link
Contributor

gchabert commented Jun 6, 2019

Merci Bertrand.
Pourquoi ne fais-tu pas un "push" du code (plutôt que de le copier ici)?

@bneveu
Copy link
Contributor

bneveu commented Jun 6, 2019 via email

gchabert pushed a commit that referenced this issue Jun 21, 2019
@gchabert
Copy link
Contributor

J'ai refait le patch de gaol pour supprimer tous les warnings en mode debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants