byuflowlab / pyfmincon

A Python bridge to Matlab's fmincon (requires a Matlab license).
MIT License
24 stars 10 forks source link

python3.5 support #1

Open robotsorcerer opened 7 years ago

robotsorcerer commented 7 years ago

Hey,

Thanks for this. Did you per chance test this with python3.5 yet?

I tried the example.py file. Here's what I got:

Python 3.5.3 :: Continuum Analytics, Inc.
(py35) lex@lex:~/Documents/pyfmincon$ python example.py 
--- starting matlab engine ---
--- calling fmincon ---
Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects.

Error in optimize/matrixfromnumpy (line 30)
        data_size = cell2mat(cell(array.shape));

Error in optimize/fupdate (line 49)
            gcin = matrixfromnumpy(output{4});

Error in optimize/obj (line 59)
        [J, cin, gJ, gcin] = fupdate(x);

Error in fmincon (line 545)
      [initVals.f,initVals.g] = feval(funfcn{3},X,varargin{:});

Error in optimize (line 25)
    [xopt, fopt, exitflag, output] = fmincon(@obj, x0, A, b, Aeq, beq, lb, ub, @con, options);

Caused by:
    Failure in initial objective function evaluation. FMINCON cannot continue.

Traceback (most recent call last):
  File "example.py", line 110, in <module>
    providegradients=providegradients)
  File "/home/lex/Documents/pyfmincon/opt.py", line 47, in fmincon
    Aeq, beq, lb, ub, options, providegradients, nargout=4)
  File "/home/lex/anaconda3/envs/py35/lib/python3.5/site-packages/matlab/engine/matlabengine.py", line 84, in __call__
    _stderr, feval=True).result()
  File "/home/lex/anaconda3/envs/py35/lib/python3.5/site-packages/matlab/engine/futureresult.py", line 68, in result
    return self.__future.result(timeout)
  File "/home/lex/anaconda3/envs/py35/lib/python3.5/site-packages/matlab/engine/fevalfuture.py", line 82, in result
    self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
matlab.engine.MatlabExecutionError: 
  File /usr/local/MATLAB/R2016b/toolbox/matlab/datatypes/cell2mat.p, line 52, in cell2mat

  File /home/lex/Documents/pyfmincon/optimize.m, line 30, in optimize/matrixfromnumpy

  File /home/lex/Documents/pyfmincon/optimize.m, line 49, in optimize/fupdate

  File /home/lex/Documents/pyfmincon/optimize.m, line 59, in optimize/obj

  File /usr/local/MATLAB/R2016b/toolbox/shared/optimlib/fmincon.p, line 545, in fmincon

  File /home/lex/Documents/pyfmincon/optimize.m, line 25, in optimize
CELL2MAT does not support cell arrays containing cell arrays or objects.
andrewning commented 7 years ago

No we haven't. We currently only use Python 2.X.

robotsorcerer commented 7 years ago

Still, it doesn't look like a python version problem. What do you think?

blouvard commented 6 years ago

@lakehanne use following on line 40 of optimize.m, it should take care of your pb data_size = [int64(array.shape{1}), int64(array.shape{2})];