Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grounding with context fails in Python 3.6 #67

Closed
GrossTor opened this issue Oct 26, 2017 · 2 comments
Closed

Grounding with context fails in Python 3.6 #67

GrossTor opened this issue Oct 26, 2017 · 2 comments
Assignees
Labels

Comments

@GrossTor
Copy link

Hello,
I am facing a RuntimeError that is produced while working with the clingo Python API. Using previous clingo versions and Python 2, I was able to define a class, pass it to grounding via the named argument "context", and thereby use its methods from within a logic program through the @-syntax. Once I updated to clingo 5.2.1 and Python 3.6 this fails with a RuntimeError.
Here is a toy example of the problem.

import clingo
import sys
print(clingo.__version__)
print(sys.version)

def on_model(m):
    print(m)

class context_provider:
    def ausgeber(self,x):
        print('function call:',x)
        return clingo.Number(2)

context=context_provider()
prg=clingo.Control(['-n0'])
prg.add("base", [], "a(@ausgeber(1)).")
prg.ground([("base", [])],context=context)
prg.solve(on_model=on_model)

Under previous versions, running this Python script would return the expected output:

5.1.0
2.7.11 |Anaconda 2.2.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
('function call:', 1)
a(2)

Under Python 3.6 it no longer works:

5.2.1
3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/Desktop/steady_ready_projects/circuit_enumeration/ASP_files/taking_control/context_function_module.py in <module>()
     20 prg=clingo.Control(['-n0'])
     21 prg.add("base", [], "a(@ausgeber(1)).")
---> 22 prg.ground([("base", [])],context=context)
     23 prg.solve(on_model=on_model)
     24 

RuntimeError: <block>:1:3-15: error: error in context:
  SystemError: Objects/tupleobject.c:81: bad argument to internal function

Is there any way to overcome this problem? Thanks.

Best,
Torsten

@rkaminsk
Copy link
Member

This issue should be fixed with 5c67b29. It is already fixed in the master branch. At some point the fix will be included in clingo 5.2.2.

@rkaminsk rkaminsk self-assigned this Oct 26, 2017
@rkaminsk rkaminsk added the bug label Oct 26, 2017
@GrossTor
Copy link
Author

I did rebuild the Python library from the current master branch and that solved the problem. Thanks a lot!

Best,
Torsten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants