AttributeError: 'Task' object has no attribute '_Task__obj', mosek

229 views
Skip to first unread message

Grace G.

unread,
Aug 14, 2020, 1:51:02 AM8/14/20
to mosek
I use mosek mio optimizer, and it finished optimization with feasible solution. however when I try to fetch the solution result using:
        xx = [0.] * n
        task.getxxslice(mosek.soltype.itg, offsetx + 0, offsetx + n, xx)

it gives me this error:
Traceback (most recent call last):
  File "/home/ubuntu/.pyenv/versions/3.7.7/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-b7fe301b9f0d>", line 1, in <module>
    task.getxxslice(mosek.soltype.itg,offsetx,offsetx+n,xx)
  File "/home/ubuntu/.pyenv/versions/3.7.7/lib/python3.7/site-packages/mosek/__init__.py", line 5040, in getxxslice
    res = self.__obj.getxxslice(_arg1_whichsol_,_arg2_first_,_arg3_last_,_arg4_xx_)
AttributeError: 'Task' object has no attribute '_Task__obj'

Michal Adamaszek

unread,
Aug 14, 2020, 1:57:43 AM8/14/20
to mosek
That indicates that the task object had already been garbage collected before your call. The most typical scenario is that you are trying to use it outside of the "with" scope where it was created. You should track the structure of your code for such issues.

For example it can happen if you have:

def makemytask():
   with env.Task() as task:
      # make and solve the task
      return task

task=makemytask()
task.getxx(...)  #UPS!

If that doesn't help than a more complete reproducible example would be necessary.

Grace G.

unread,
Aug 14, 2020, 2:18:38 AM8/14/20
to mosek
you are absolutely right. Problem solved. Thanks a lot
Reply all
Reply to author
Forward
0 new messages