logic-and-learning-lab/Popper

A PrologError raise in function success_set when using build-in predicates

yangdinglou opened this issue · 2 comments

Hello. I tried using the system to learn some properties (expressed by predicates), and the python program returned some error messages. For simplicity, I attempted to locate the problem, and found the issue was accompanied with the use of build-in predicates.

Example1 (with error)

%% The expected predicate is 
%% f(Num, Lst) :- succ(A, Num), last(Lst, A).

%% bias.pl as follows
max_vars(3).
max_body(3).
max_clauses(2).

head_pred(f,2).
body_pred(last,2).
body_pred(succ,2).

%% no content needed in bk.pl, exs.pl as follows
pos(f(3,[4,3,1,2])).
pos(f(3,[4,3,2])).
pos(f(5,[3,4])).

neg(f(1,[4,1,2])).
neg(f(1,[4,3,5,2])).
neg(f(2,[4,3,2])).
neg(f(5,[4,3,2,7])).
neg(f(2,[3,4,5])).

returns the following messages.

Traceback (most recent call last):
  File "popper.py", line 11, in <module>
    _prog, stats = learn_solution(settings)
  File "/home/ydl/Popper/popper/loop.py", line 181, in learn_solution
    timeout(popper, (settings, stats), timeout_duration=int(settings.timeout))
  File "/home/ydl/Popper/popper/util.py", line 47, in timeout
    result = func(*args, **kwargs)
  File "/home/ydl/Popper/popper/loop.py", line 142, in popper
    conf_matrix = tester.test(program)
  File "/home/ydl/Popper/popper/tester.py", line 90, in test
    covered.update(self.success_set([rule]))
  File "/home/ydl/Popper/popper/tester.py", line 83, in success_set
    self.seen_prog[prog_hash] = set(next(self.prolog.query('success_set(Xs)'))['Xs'])
  File "/home/ydl/.local/lib/python3.8/site-packages/pyswip/prolog.py", line 126, in __call__
    raise PrologError("".join(["Caused by: '", query, "'. ",
pyswip.prolog.PrologError: Caused by: 'success_set(Xs)'. Returned: 'error(type_error(integer, [4, 3, 1, 2]), context(:(system, /(succ, 2)), _1654))'.

Example2 (worked)

Based on Example1, by replaceing body_pred(succ,2). with body_pred(my_succ,2). and adding

my_succ(1,2).
my_succ(2,3).
my_succ(3,4).
my_succ(4,5).
my_succ(5,6).

in the background file, the correct predicate f(A,B):-my_succ(C,A),last(B,C). was learned.

Example3 (with error)

Then based on Example2, I tried replacing the predicate last with min_list. One modify is needed in the example file.

%% The expected predicate is 
%% f(Num, Lst) :- my_succ (A, Num), min_list(Lst, A).
%% bias.pl as follows
max_vars(3).
max_body(3).
max_clauses(2).

head_pred(f,2).
body_pred(min_list,2).
body_pred(my_succ,2).
%% exs.pl as follows
pos(f(2,[4,3,1,2])).
pos(f(3,[4,3,2])).
pos(f(4,[3,4])).

neg(f(1,[4,1,2])).
neg(f(1,[4,3,5,2])).
neg(f(2,[4,3,2])).
neg(f(5,[4,3,2,7])).
neg(f(2,[3,4,5])).

then returns the following messages.

Traceback (most recent call last):
  File "popper.py", line 11, in <module>
    _prog, stats = learn_solution(settings)
  File "/home/ydl/Popper/popper/loop.py", line 181, in learn_solution
    timeout(popper, (settings, stats), timeout_duration=int(settings.timeout))
  File "/home/ydl/Popper/popper/util.py", line 47, in timeout
    result = func(*args, **kwargs)
  File "/home/ydl/Popper/popper/loop.py", line 142, in popper
    conf_matrix = tester.test(program)
  File "/home/ydl/Popper/popper/tester.py", line 90, in test
    covered.update(self.success_set([rule]))
  File "/home/ydl/Popper/popper/tester.py", line 83, in success_set
    self.seen_prog[prog_hash] = set(next(self.prolog.query('success_set(Xs)'))['Xs'])
  File "/home/ydl/.local/lib/python3.8/site-packages/pyswip/prolog.py", line 126, in __call__
    raise PrologError("".join(["Caused by: '", query, "'. ",
pyswip.prolog.PrologError: Caused by: 'success_set(Xs)'. Returned: 'error(existence_error(matching_rule, :(lists, min_list(3, [4, 3, 2]))), context(:(lists, /(min_list, 2)), _1026))'.

The environment is SWI-Prolog version 8.4.1 for x86_64-linux (on WSL). I am not sure it is a bug or due to violation of some constraints of the system.

Thanks. (Edited a typo)

Thanks Andrew! I get it now.