Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.97k stars 504 forks source link

Mindtpy seems to sent a float value to MIP solver #1095

Closed sferenz closed 5 years ago

sferenz commented 5 years ago

I'm running multiple MINLP with mindtpy and pyomo. Between the problems I change some values in the constrains and in the objective. The first problems can be solved by mindtpy and pyomo without any issues.

At a certain point, the code crashes with the following error:

INFO: ---Starting MindtPy---
INFO:pyomo.contrib.mindtpy:---Starting MindtPy---
INFO: Original model has 187 constraints (52 nonlinear) and 0 disjunctions,
    with 194 variables, of which 95 are binary, 0 are integer, and 99 are
    continuous.
INFO:pyomo.contrib.mindtpy:Original model has 187 constraints (52 nonlinear) and 0 disjunctions, with 194 variables, of which 95 are binary, 0 are integer, and 99 are continuous.
INFO: Objective is nonlinear. Moving it to constraint set.
INFO:pyomo.contrib.mindtpy:Objective is nonlinear. Moving it to constraint set.
INFO: NLP 1: Solve relaxed integrality
INFO:pyomo.contrib.mindtpy:NLP 1: Solve relaxed integrality
INFO: NLP 1: OBJ: 10.29694308201705  LB: 10.29694308201705  UB: inf
INFO:pyomo.contrib.mindtpy:NLP 1: OBJ: 10.29694308201705  LB: 10.29694308201705  UB: inf
INFO: ---MindtPy Master Iteration 0---
INFO:pyomo.contrib.mindtpy:---MindtPy Master Iteration 0---
INFO: MIP 1: Solve master problem.
INFO:pyomo.contrib.mindtpy:MIP 1: Solve master problem.
RemoteException:
Traceback (most recent call last):
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/aiomas/rpc.py", line 158, in _handle_request
    res = await loop.create_task(res)
  File "/home/test/ma_code/mas/mas_api.py", line 288, in step
    mas_commands, self.mas_accounting = await self.ma.agents_processing(t, inputs)
  File "/home/test/ma_code/mas/mas_api.py", line 428, in agents_processing
    await asyncio.gather(*futs_steps)
aiomas.exceptions.RemoteException: Origin: ('127.0.0.1', 5679)
Traceback (most recent call last):
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/aiomas/rpc.py", line 158, in _handle_request
    res = await loop.create_task(res)
  File "/home/test/ma_code/mas/strategy2/grid_agent.py", line 94, in step
    await self.__compute_reactive_flow()
  File "/home/test/ma_code/mas/strategy2/grid_agent.py", line 146, in __compute_reactive_flow
    self.__net['y_re_pu'],self.__net['y_im_pu'],self.__net['voltage_band'], self.__net['sn_kva'], self.__path, output = True, optimization_model_type = self.__optimization_type)
  File "/home/test/ma_code/mas/strategy2/orpf/main.py", line 46, in compute_orpf
    model.compute_orpf_model('mindtpy')
  File "/home/test/ma_code/mas/strategy2/orpf/orpf_model.py", line 158, in compute_orpf_model
    self.results = opt.solve(self.model, mip_solver='gurobi', nlp_solver='ipopt', obj_bound=100, tee = True)
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/contrib/mindtpy/MindtPy.py", line 357, in solve
    MindtPy_iteration_loop(solve_data, config)
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/contrib/mindtpy/iterate.py", line 26, in MindtPy_iteration_loop
    solve_OA_master(solve_data, config)
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/contrib/mindtpy/mip_solve.py", line 59, in solve_OA_master
    config)
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/contrib/gdpopt/util.py", line 153, in copy_var_list_values
    v_to.set_value(value(v_from, exception=False))
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/core/base/var.py", line 172, in set_value
    if valid or self._valid_value(val):
  File "/home/test/.local/share/virtualenvs/ma_code-39705YHu/lib/python3.6/site-packages/pyomo/core/base/var.py", line 184, in _valid_value
    "domain %s" % (val, type(val), self.domain))
ValueError: Numeric value `2.07824503091e-05` (<class 'float'>) is not in domain Binary

Since I have no influence on the data mindtpy passes to the mip solver, I expect that there is some bug in the mindtpy code. Does anyone get the some error and have a fix or a workaround?

bernalde commented 5 years ago

Hi, thanks for reporting this. Can you share your model here? I cannot check where the error is coming from from your post. Thanks!

sferenz commented 5 years ago

Hey, thanks for the fast response! I exported the model which creates the crash as cloudpickle: test.txt

When I run the following code:

from pyomo.environ import *

import cloudpickle

with open('test.txt', mode='rb') as file:
    model = cloudpickle.load(file)

model.pprint()

opt = SolverFactory('mindtpy')

results = opt.solve(model, mip_solver='gurobi', nlp_solver='ipopt', tee=True)

I get the following error:

INFO: ---Starting MindtPy---
INFO: Original model has 187 constraints (104 nonlinear) and 0 disjunctions,
    with 194 variables, of which 95 are binary, 0 are integer, and 99 are
    continuous.
INFO: Objective is nonlinear. Moving it to constraint set.
INFO: NLP 1: Solve relaxed integrality
INFO: NLP 1: OBJ: -43.367431403910366  LB: -43.367431403910366  UB: inf
INFO: ---MindtPy Master Iteration 0---
INFO: MIP 1: Solve master problem.
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    results = opt.solve(model, mip_solver='gurobi', nlp_solver='ipopt', obj_bound=100, tee=True)
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/contrib/mindtpy/MindtPy.py", line 357, in solve
    MindtPy_iteration_loop(solve_data, config)
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/contrib/mindtpy/iterate.py", line 26, in MindtPy_iteration_loop
    solve_OA_master(solve_data, config)
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/contrib/mindtpy/mip_solve.py", line 59, in solve_OA_master
    config)
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/contrib/gdpopt/util.py", line 153, in copy_var_list_values
    v_to.set_value(value(v_from, exception=False))
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/core/base/var.py", line 172, in set_value
    if valid or self._valid_value(val):
  File "/home/ferenz/.local/share/virtualenvs/test_pyomo-lSMAhBuU/lib/python3.6/site-packages/pyomo/core/base/var.py", line 184, in _valid_value
    "domain %s" % (val, type(val), self.domain))
ValueError: Numeric value `7.13998815746e-05` (<class 'float'>) is not in domain Binary
bernalde commented 5 years ago

I cannot replicate your results because I'm missing a module 'mas', but from the error output, it looks like gurobi is returning a nonbinary value (7.13998815746e-05) for certain binary variable in the first MIP master. Are you passing some extra parameters to gurobi? Maybe the integer feasibility tolerance (IntFeasTol)? Try changing the parameter integer_tolerance for MindtPy (default 1E-5) to a higher value if the MIP master problem is that complicated.

sferenz commented 5 years ago

Sorry, that the test didn't work on your machine. It looks like when using cloudpickle, still all modules are necessary. I didn't find a better way to export and import the model, perhaps that could be added to pyomo one day?

I changed the integer_tolerance and the error disappeared! Thanks for the help!