coin-or / rbfopt

RBFOpt library for black-box optimization
Other
188 stars 33 forks source link

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 81: character maps to <undefined> #42

Closed pascalzeugin closed 2 years ago

pascalzeugin commented 2 years ago

When I run the minimum working example as shown below

import rbfopt
import numpy as np
def obj_funct(x):
  return x[0]*x[1] - x[2]

bb = rbfopt.RbfoptUserBlackBox(3, np.array([0] * 3), np.array([10] * 3),
                               np.array(['R', 'I', 'R']), obj_funct)
settings = rbfopt.RbfoptSettings(minlp_solver_path=r'C:\ProjTMS\MecosTools\mbtools4x\bin\bonmin.exe', nlp_solver_path=r'C:\ProjTMS\MecosTools\mbtools4x\bin\ipopt.exe',max_evaluations=50)
alg = rbfopt.RbfoptAlgorithm(settings, bb)
val, x, itercount, evalcount, fast_evalcount = alg.optimize()

then I get the following error

  Iter  Cycle  Action             Objective value      Time      Gap
  ----  -----  ------             ---------------      ----      ---
     0      0  Initialization           -0.782797      0.00   100.00 *
     0      0  Initialization           69.095477      0.01   100.00  
     0      0  Initialization           20.000000      0.01   100.00  
     0      0  GlobalStep               -9.829600      0.02   100.00 *
     1      0  GlobalStep               -9.946732      0.04   100.00 *
     2      0  GlobalStep               -0.133622      0.05   100.00  
     3      0  GlobalStep               -8.304083      0.07   100.00  
     4      0  GlobalStep               -9.999968      0.09   100.00 *
Exception in thread Thread-8:
Traceback (most recent call last):
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\threading.py", line 950, in _bootstrap_inner
    self.run()
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\threading.py", line 888, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1475, in _readerthread
    buffer.append(fh.read())
  File "c:\users\c565785\appdata\local\programs\python\python39\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 81: character maps to <undefined>
Traceback (most recent call last):

  File "C:\ProjTMS\MecosTools\mbtools4x\scripts\untitled0.py", line 10, in <module>
    val, x, itercount, evalcount, fast_evalcount = alg.optimize()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 803, in optimize
    self.optimize_serial(pause_after_iters)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 1060, in optimize_serial
    (adj, next_p, ind) = local_step(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 2446, in local_step
    min_rbf = aux.minimize_rbf(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_aux_problems.py", line 297, in minimize_rbf
    if (not opt.available()):

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 115, in available
    return self.version() is not None

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\opt\base\solvers.py", line 421, in version
    self._version = self._get_version()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 96, in _get_version
    results = subprocess.run([solver_exec, "-v"],

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 503, in run
    stdout, stderr = process.communicate(input, timeout=timeout)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1130, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\subprocess.py", line 1525, in _communicate
    stdout = stdout[0]

IndexError: list index out of range

I'm using Python 3.9.6 by the way.

gnannicini commented 2 years ago

Hello, the minimal working example works on my machine, with different versions of Python up to 3.10 and different version of Pyomo up to the recent 6.2. I tried to replicate your error with Pyomo 5.7 all the way up to 6.2, and did not succeed in replicating.

The error you're seeing is because something goes wrong when Pyomo tries to find a solver (bonmin, I assume). Pyomo cannot find the solver, and Rbfopt is supposed to return an error, but something breaks before that happens; on my machine, if I provide the wrong solver path, I get a (graceful) error message explaining the situation. Note that the error happens inside Pyomo.

I used the same code you wrote above, just changing the path to the solver. I would need more information, because as things stand I cannot replicate the bug.

(The fact that the error trace mentions a UnicodeDecodeError makes me suspect it may have something to do with the string used to indicate the solver path.)

pascalzeugin commented 2 years ago

I updated the COIN-OR optimization suite to the newest version, i.e. 1.8.0 and the erorr traceback changed:

  Iter  Cycle  Action             Objective value      Time      Gap
  ----  -----  ------             ---------------      ----      ---
     0      0  Initialization           -0.782797      0.00   100.00 *
     0      0  Initialization           69.095477      0.00   100.00  
     0      0  Initialization           20.000000      0.00   100.00  
     0      0  GlobalStep               -9.829600      0.02   100.00 *
     1      0  GlobalStep               -9.946732      0.04   100.00 *
     2      0  GlobalStep               -0.133622      0.06   100.00  
     3      0  GlobalStep               -8.304083      0.07   100.00  
     4      0  GlobalStep               -9.999968      0.09   100.00 *
Traceback (most recent call last):

  File "C:\ProjTMS\MecosTools\mbtools4x\bin\untitled0.py", line 10, in <module>
    val, x, itercount, evalcount, fast_evalcount = alg.optimize()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 803, in optimize
    self.optimize_serial(pause_after_iters)

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 1060, in optimize_serial
    (adj, next_p, ind) = local_step(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_algorithm.py", line 2446, in local_step
    min_rbf = aux.minimize_rbf(

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\rbfopt\rbfopt_aux_problems.py", line 297, in minimize_rbf
    if (not opt.available()):

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 115, in available
    return self.version() is not None

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\opt\base\solvers.py", line 421, in version
    self._version = self._get_version()

  File "c:\users\c565785\appdata\local\programs\python\python39\lib\site-packages\pyomo\solvers\plugins\solvers\ASL.py", line 104, in _get_version
    if results.stdout.strip().split()[-1].startswith('ASL('):

IndexError: list index out of range

I could trace the problem back to the bonmin.exe itself. When it tries to retrieve the version of the solver, it fails because two dll's are not found svml_dispmd.dll and libifcoremd.dll.

image

I used the excutable installer to install the suite. Can you tell where the problem is?

gnannicini commented 2 years ago

I don't know where the problem is, but you seem to have found the source of the error: your bonmin executable causes a system error.

You may want to look for help with the COIN Optimization suite. You can also try to download the Windows executable for bonmin and ipopt provided by AMPL ( https://ampl.com/products/solvers/open-source/ ), and see if those work.

pascalzeugin commented 2 years ago

Hi Giacomo

Thank you for your help, substituting the solvers with the ones from the source you've provided works like charm! Your help is much appreciated!

Best regards Pascal

gnannicini commented 2 years ago

Ok, glad to know it worked. I'm closing this.