Giter Site home page Giter Site logo

sthiele / pyasp Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 2.0 3.71 MB

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

Makefile 0.49% Python 96.77% Jupyter Notebook 2.75%

pyasp's People

Contributors

aluriak avatar cfrioux avatar sthiele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cfrioux aluriak

pyasp's Issues

Constants in parameters of solver.run() method can't have space in their names

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).")

`--time-limit` option not supported

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.

Access versions number and text of binaries programmatically

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)

Threading option of Clasp leads to 'OPTIMUM FOUND but zero optimals' warning and no model

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: []

Unit testing don't cover *misc.py*

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.