sthiele / pyasp Goto Github PK
View Code? Open in Web Editor NEWA convenience wrapper for the ASP tools gringo, gringo4 and clasp
Home Page: https://pypi.python.org/pypi/pyasp
License: GNU General Public License v3.0
A convenience wrapper for the ASP tools gringo, gringo4 and clasp
Home Page: https://pypi.python.org/pypi/pyasp
License: GNU General Public License v3.0
On FreeBSD, I only have gringo-4. Sholdn't the latest version be enough?
Here is the p.py file:
from pyasp import asp
solver = asp.Gringo4Clasp(gringo_options='-c v="text with spaces in it"')
solver.run([], additionalProgramText='#const v=1. p(v).') # error here
Here is the stack trace (python 3):
Traceback (most recent call last):
File "p.py", line 6, in <module>
solver.run([], additionalProgramText='#const v=1. p(v).')
File "/udd/lbourneu/.local/lib/python3.4/site-packages/pyasp/asp.py", line 383, in run
grounding = self.__ground__(programs, additionalProgramText)
File "/udd/lbourneu/.local/lib/python3.4/site-packages/pyasp/asp.py", line 345, in __ground__
(self._gringo.returncode, self.gringo_stderr))
Exception: got error 1 from gringo: 'b'<v="text>:1:4: error: lexer error, unexpected "\n\n<cmd>: error: file could not be opened:\n with\n\n<cmd>: error: file could not be opened:\n spaces\n\n<cmd>: error: file could not be opened:\n in\n\n<cmd>: error: file could not be opened:\n it"\n\n*** ERROR: (gringo): grounding stopped because of errors\n''
Using gringo CLI, an error appears if supplementary quotes are not provided:
gringo4 l.lp -c v='"text with spaces in it"'
(with "l.lp" file containing "#const v=1. p(v).")
I tried an example from:
https://sthiele.github.io/posts/2015/october/pyasp_intro.html
When .lp files are missing, this statement
solver.run([encoding, facts], collapseTerms=True, collapseAtoms=False)
doesn't print error messages.
Using the --time-limit=1
option of clasp, the following error should appear when the solver is stopped by the signal.
I think its because pyasp
is not designed to handle any outputed data when an interruption occurs.
File "/udd/lbourneu/.local/lib/python3.4/site-packages/pyasp/asp.py", line 146, in run
solving = self.__solve__(grounding)
File "/udd/lbourneu/.local/lib/python3.4/site-packages/pyasp/asp.py", line 136, in __solve__
raise EnvironmentError(error)
OSError: got error 1 from clasp:
{
"Solver": "clasp version 3.1.3",
"Input": [
"stdin"
],
"Call": [
{
}
],
"Result": "UNKNOWN",
"TIME LIMIT": 1,
"Models": {
"Number": 0,
"More": "yes"
},
"Calls": 1,
"Time": {
"Total": 1.000,
"Solve": 0.788,
"Model": 0.000,
"Unsat": 0.000,
"CPU": 0.990
}
}
*** Info : (clasp): INTERRUPTED by signal!
This should be supported in a next pyasp
version.
I will work on a minimal reproductible code example to getting this error.
Fixing it will require some work on the parser, in order to extract all models found before interruption.
For logging and testing purpose, the versions and version text of binaries of clasp and gringo can be useful. These information could be accessed programatically.
API exemple for gringo:
from pyasp import asp
print('GRINGO VERSION:', asp.Gringo4.version(), '\n')
print(asp.Gringo4.version(full_text=True))
output:
GRINGO VERSION: 4.5.3
gringo version 4.5.3
Address model: 64-bit
Configuration: without Python, with Lua 5.2.3
Copyright (C) Roland Kaminski
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
Gringo is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
API exemple for clasp:
from pyasp import asp
print('CLASP VERSION:', asp.Clasp.version(), '\n')
print(asp.Clasp.version(full_text=True))
output:
CLASP VERSION: 3.1.4
clasp version 3.1.4
Address model: 32-bit
Configuration: WITH_THREADS=1 (Intel TBB version 4.0)
Copyright (C) Benjamin Kaufmann
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
clasp is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Currently, just call the solver with the --version option is not working, because of the parser that try to parse the version text.
A routine that call the binaries without call the parser could return the stdout output. (or use a regex to extract the version number)
It appears that define the --parallel-mode clasp option leads to a warning, and an unsatisfiable result. (no model found)
Here is the python program:
from pyasp import asp
PROGRAM = """
% choose two values
values(1..10).
2 {choosen(X): values(X)} 2.
% score is the sum of the values
score(S):- S=#sum{X:choosen(X)}.
% maximize the score
#maximize{S:score(S)}.
#show.
#show choosen/1.
#show score/1.
"""
def test(clasp_options):
solver = asp.Gringo4Clasp(clasp_options=clasp_options)
return solver.run([], additionalProgramText=PROGRAM)
print('FIRST: no clasp option:')
print('answers:', test(''))
print('-----------------------')
print('SECOND: use 2 threads:')
print('answers:', test('--parallel-mode=2'))
Result (python 3.4.3):
FIRST: no clasp option:
answers: [TermSet({'score(19)', 'choosen(10)', 'choosen(9)'})]
-----------------------
SECOND: use 2 threads:
WARNING: OPTIMUM FOUND but zero optimals
answers: []
The file misc.py is not covered by unit testing, which raise no error after deleting all lines in that file.
The asp.py module import all objects of misc.py module, but don't use any of them.
Is misc.py only kept for further development ?
You can't download binaries without checking cryptographic hash: https://github.com/sthiele/pyasp/blob/master/setup.py#L128 Users will get MITMed. https://en.wikipedia.org/wiki/Man-in-the-middle_attack
Either delete these downloads, or store and check cryptographic hashes. I recommend: you should rely on the installed packages for gringo and clasp, and not try to install anything yourself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.