potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
601 stars 79 forks source link

Unable to use Domain heuristic in parallel mode with more than 14 competing threads. #398

Closed OllieKampo closed 1 year ago

OllieKampo commented 1 year ago

In the newest version of clingo, using the following options simultaneously: --heuristic=Domain and --parallel-mode=n,compete, with n > 14, throws an error *** ERROR: (clingo): <config>.[solver.14] : Heuristic requires lookback strategy!.

This is true on the command line and by using the python API. For example:

(ASH) PS C:\Users\OllieKampo\OneDrive\Code\ASH-Planner> python
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clingo
>>> clingo.control.Control(['--heuristic=Domain', '--parallel-mode=20,compete'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\OllieKampo\anaconda3\envs\ASH\lib\site-packages\clingo\control.py", line 172, in __init__
    self._rep = _c_call('clingo_control_t *', _lib.clingo_control_new,
  File "C:\Users\OllieKampo\anaconda3\envs\ASH\lib\site-packages\clingo\_internal.py", line 41, in _c_call
    _handle_error(c_fun(*args, p_ret), handler)
  File "C:\Users\OllieKampo\anaconda3\envs\ASH\lib\site-packages\clingo\_internal.py", line 65, in _handle_error
    raise RuntimeError(msg)
RuntimeError: <config>.[solver.14] : Heuristic requires lookback strategy!

Enabling parallel mode with more than 14 threads, compete enabled, but no domain heuristic with --parallel-mode=20,compete for example does work fine though.

If you use --heuristic=Domain and --parallel-mode=n,split, with n > 14 it also works fine. It seems to be the compete that causes this. For example:

(ASH) PS C:\Users\OllieKampo\OneDrive\Code\ASH-Planner> python
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clingo
>>> clingo.control.Control(['--heuristic=Domain', '--parallel-mode=20,split'])   
<clingo.control.Control object at 0x000001C0B2EEB6A0>

I couldn't find anything in the documentation that mentioned this, but perhaps I was searching for the wrong thing.

rkaminsk commented 1 year ago

Not all portfolios are compatible with all command line options. You can easily print and modify it. For example:

➜ clingo --print-portfolio | grep -v solver.14 > portfolio.txt
➜ echo | clingo --heuristic=Domain --parallel-mode=20 --configuration=portfolio.txt
clingo version 5.6.2 (e759a62)
Reading from stdin
Solving...
Answer: 1

SATISFIABLE

Models       : 1
Calls        : 1
Time         : 0.001s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time     : 0.003s
Threads      : 20       (Winner: 3)
OllieKampo commented 1 year ago

Thanks for the quick response. I understand, I will take a look at this, thanks!

I think the issue is though, that the error it reports with the lookback strategy isn't particularly helpful, since it is not obvious why changing the number of threads from 14 to 15 would suddenly cause an issue with the lookback strategy, which isn't mentioned on the command line.

Would I be correct in assuming that the problem happens because clingo changes its default configuration when the number of threads becomes large, therefore causing a conflict with other command line arguments (in this case the domain heuristic)?

I'm not sure how you'd make this error more helpful necessarily, but I hope you see what I mean.

rkaminsk commented 1 year ago

Command line options overwrite options in the portfolio configurations. This can lead to conflicts. The error might be a bit hard to read but but <config>.[solver.14] : Heuristic requires lookback strategy! indicates this conflict.

OllieKampo commented 1 year ago

Looks like I need to do a bit more experimenting and reading on this then.

Thanks for the help Roland.