bathy_smoother submodule problem

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
apaloczy
Posts: 17
Joined: Tue Jan 07, 2014 4:18 pm
Location: Scripps Institution of Oceanography
Contact:

bathy_smoother submodule problem

#1 Unread post by apaloczy »

Hello,

I am having trouble using the LP_smoothing_rx0() and LP_smoothing_rx0_heuristic() functions of the bathy_smoother submodule of pyroms. It seems that I have built and installed bathy_smoother, lp_solve and lpsolve55 (with its python component) successfully, since bathy_smoother imports the lpsolve55 module without error messages. The traceback is:

=======================================================================================================
In [1]: run smooth_bath_LP.py
nbModif= 4115
---------------------------------------------------------------
iColor = 1 nbK = 1706
eta_rho = 130 xi_rho = 161
ListCoord built
Computing inequalities for r = 0.2
Inequalities for dh(iEta,iXi) and dh(iEta+1,iXi)
Inequalities for dh(iEta,iXi) and dh(iEta,iXi+1)
Inequalities dh <= ad and -dh <= ad
rx0: nbEntry = 64204 nbConst = 32102

eta_rho = 130 xi_rho = 161
Inequalities |h^{new} - h^{old}| <= alpha h^{old}
maxamp: nbEntry = 0 nbConst = 0

eta_rho = 130 xi_rho = 161
Inequalities dh >= 0 or dh <= 0
signs: nbEntry = 0 nbConst = 0

Solving a linear program of 11092 variables and 32102 Constraints
Write linear program
nbvar = 11092 nbConst = 32102

Linear program written in FileOutput= /tmp/lp_13_43_18.0_7.0_output.lp
---------------------------------------------------------------------------
error Traceback (most recent call last)
/home/andre/lado/MSc/work/ROMS/topo_BES/smooth_bath_LP.py in <module>()
73 AmpConst = 10000.*np.ones(hraw.shape)
74 # h = bathy_smoother.LP_bathy_smoothing.LP_smoothing_rx0(masktopo, hraw, rfac_max, SignConst, AmpConst)
---> 75 h = bathy_smoother.LP_bathy_smoothing.LP_smoothing_rx0_heuristic(masktopo, hraw, rfac_max, SignConst, AmpConst)

/home/andre/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/bathy_smoother/LP_bathy_smoothing.pyc in LP_smoothing_rx0_heuristic(MSK, Hobs, rx0max, SignConst, AmpConst)
164 MSKHobs = np.zeros((eta_rho, xi_rho))
165 MSKHobs[K] = Hobs[K].copy()
--> 166 TheNewBathy = LP_smoothing_rx0(MSKcolor, MSKHobs, rx0max, SignConst, AmpConst)
167 NewBathy[K] = TheNewBathy[K].copy()
168

/home/andre/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/bathy_smoother/LP_bathy_smoothing.pyc in LP_smoothing_rx0(MSK, Hobs, rx0max, SignConst, AmpConst)
60 ObjectiveFct[TotalNbVert+iVert,0] = 1
61
---> 62 ValueFct, ValueVar, testfeasibility = LP_tools.SolveLinearProgram(iList, jList, sList, Constant, ObjectiveFct)
63 if (testfeasibility == 0):
64 NewBathy = NaN * np.ones((eta_rho,xi_rho))

/home/andre/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/bathy_smoother/LP_tools.pyc in SolveLinearProgram(iList, jList, sList, Constant, ObjectiveFct)
129 print 'Linear program written in FileOutput=', FileOutput
130
--> 131 lp_handle = lpsolve('read_lp_file', FileInput)
132 result = lpsolve('solve', lp_handle)
133 obj, ValueVar, ValueFct, testfeasibility = lpsolve('get_solution', result)

error: Expecting a character element.

In [2]:
=======================================================================================================

There is something wrong with the lpsolve55.lpsolve function, which is a python wrapper to the lp_solve binary, if I understood it right. By googling around, I traced down the above error message in red to the following function, in the pythonmod.c source code:

========================================================================================================
int GetString(PyObject *pm, int element, char *buf, int size, int ShowError)
{
PyObject *item;
int size1;
char *ptr = NULL;

item = GetpMatrix(pm, element);
if((item == NULL) ||
(PyString_AsStringAndSize(item, &ptr, &size1) != 0) ||
(ptr == NULL)) {
PyErr_Clear();
if(ShowError)
ErrMsgTxt("Expecting a character element.");
return(FALSE);
}
if(size1 < size)
size = size1;
memcpy(buf, ptr, size);
buf[size] = 0;
return(TRUE);
}
================================================================================================

To see if the problem was with the *.lp file created by the WriteLinearProgram() function of bathy_tools, I tried running lp_solve on that file right from the terminal, and it generated a valid output:

================================================================================================
andre@sextant:/tmp$ lp_solve lp_10_57_23.0_10.0_input.lp

Value of objective function: 154632.97298663

Actual values of the variables:
X1 0
X2 0
X3 0
X4 0
X5 0
X6 1.75849
X7 6.54398
X8 4.28472
X9 -3.97917
X10 0
X11 0
X12 0
X13 0
X14 0
X15 0
X16 0
X17 0
(continues)

So it looks like the problem is in the lpsolve55.lpsolve() wrapper function, but I can't figure out what it is. For some reason the 'read_lp_file' command of the lpsolve55.lpsolve() function cannot read the *lp input file 'FileInput', which exists, and is successfully read and solved by the lp_solve program outside of python.

Thank you for your time, and any help is greatly appreciated.

Post Reply