potassco / clingo

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

ProgramObserver raises unexpected exception with released externals #369

Closed Entze closed 2 years ago

Entze commented 2 years ago

Hello,

I stumbled upon this bug while playing around with telingo. It seems like released externals are not handled by ProgramObserver, as this code raises a TypeError: '<' not supported between instances of 'TruthValue' and 'TruthValue'

import clingo
import clingox.program
#%%
program = """

#external ext. [false]

aux.
derived :- ext, aux.

"""
#%%
ctl = clingo.Control()
prg = clingox.program.Program()
obs = clingox.program.ProgramObserver(prg)
ctl.register_observer(obs)
#%%
ctl.add('base', [], program)
ctl.ground([('base', [])])
ctl.release_external(clingo.Function('ext'))
#%%
print(prg) # TypeError: '<' not supported between instances of 'TruthValue' and 'TruthValue'

Probably the sort (clingox/program.py:685) needs a partial application s.t. TruthValue are considered equal, or TruthValue also perhaps should implement @total_order/__lt__ etc.?

My relevant library versions (reported by conda) are:

clingo                    5.6.0            py39h3fd9d12_0    potassco/label/dev # (also reproduced on 5.5.2)
python                    3.9.12       h2660328_1_cpython    conda-forge
python-clingox            1.1.0                      py_0    potassco

Best regards

rkaminsk commented 2 years ago

We should probably implement an order for enums. The python docs have an example:

rkaminsk commented 2 years ago

clingo is using orderable enums now. clingox should work now.