Error 'error(type_error(integer,...)` in v2.0.0
Closed this issue · 2 comments
hakank commented
I'm testing my old instances and got an error when running the following:
bias.pl (see below for a comment on the commented lines)
max_vars(5).
max_body(10).
max_clauses(2).
head_pred(f,2).
% type(f,(list,list)).
% direction(f,(in,out)).
body_pred(f,2).
body_pred(tail,2).
% type(tail,(list,list)).
% direction(tail,(in,out)).
body_pred(head,2).
% type(head,(list,element)).
% direction(head,(in,out)).
body_pred(last,2).
% type(last,(list,element)).
% direction(last,(in,out)).
body_pred(length,2).
% type(length,(list,int)).
% direction(length,(in,out)).
body_pred(sum,3).
% type(sum,(int,int,int)).
% direction(sum,(in,in,out)).
body_pred(cons,3).
% type(cons,(element,list,list)).
% direction(cons,(in,in,out)).
body_pred(empty,1).
% type(empty,(list,1)).
% direction(empty,(in,)).
body_pred(zero,1).
% type(zero,(int,)).
% direction(zero,(in,)).
bk.pl
cons(A,B,C):-
append([A],B,C).
tail([_|T],T).
head([H|_],H).
sum(A,B,C):-
C is A+B.
empty([]).
zero(0).
exs.pl
pos(f([65, 32, 87, 84, 25, 91, 36, 43, 64, 78, 51, 65, 90],[65, 32, 87, 84, 25, 91, 36, 43, 64, 78, 51, 65])).
pos(f([65, 32],[65])).
pos(f([1,2,3],[1,2])).
pos(f([65, 32,23],[65,32])).
neg(f([1,2,3],[1,2,3])).
neg(f([1,2,3],[1])).
Running the program:
$ time python3 popper.py --debug hakank/droplast
20:47:46 Max rules: 2
20:47:46 Max vars: 5
20:47:46 Max body: 10
20:47:46 Num. pos examples: 4
20:47:46 Num. neg examples: 2
Traceback (most recent call last):
File "popper.py", line 8, in <module>
prog, score, stats = learn_solution(settings)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/loop.py", line 198, in learn_solution
timeout(settings, popper, (settings,), timeout_duration=int(settings.timeout),)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/util.py", line 65, in timeout
result = func(*args, **kwargs)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/loop.py", line 83, in popper
pos_covered, inconsistent = tester.test_prog(prog)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/tester.py", line 83, in test_prog
pos_covered = frozenset(self.query('pos_covered(Xs)', 'Xs'))
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/tester.py", line 14, in query
return set(next(self.prolog.query(query))[key])
File "/usr/local/lib/python3.7/site-packages/pyswip/prolog.py", line 129, in __call__
"Returned: '", str(term), "'."]))
pyswip.prolog.PrologError: Caused by: 'pos_covered(Xs)'. Returned: 'error(type_error(integer, [1, 2]), context(/(length, 2), _54))'.
Originally bias.pl contained the commented lines, but then Popper found this solution directly and then hanged. For some reason it didn't timeout after 10 minutes (I stopped it manually after 12 minutes).
20:20:36 New best hypothesis:
20:20:36 tp:1 fn:3 size:5
20:20:36 f(A,B):- cons(E,C,B),tail(D,C),head(A,E),tail(A,D).
20:20:36 ********************
20:20:36 Searching programs of size: 6
With the --debug flag it hangs here:
...
20:51:52 f(A,B):- cons(C,A,B),f(B,A),head(A,C).
20:51:52 Program 64:
20:51:52 f(A,B):- tail(A,B).
20:51:52 f(A,B):- last(A,C),f(B,A),cons(C,A,B).
20:51:52 Program 65:
20:51:52 f(A,B):- tail(A,B).
20:51:52 f(A,B):- f(B,A),tail(A,C),tail(C,B).
andrewcropper commented
The type error is as expected because Popper is calling SWI-Prolog with incorrect types.
The looping bug is caused by a slightly new bias form. To learn recursive programs, a user must now add `enable_recursion` to the bias file. They no longer need to add the corresponding body_pred atom to the bias file. If you remove body_pred(f,2) and add enable_recursion, it should work.
Kind regards,
Andrew
… On 2 Jun 2022, at 19:55, Hakan Kjellerstrand ***@***.***> wrote:
I'm testing my old instances and got an error when running the following:
bias.pl (see below for a comment on the commented lines)
max_vars(5).
max_body(10).
max_clauses(2).
head_pred(f,2).
% type(f,(list,list)).
% direction(f,(in,out)).
body_pred(f,2).
body_pred(tail,2).
% type(tail,(list,list)).
% direction(tail,(in,out)).
body_pred(head,2).
% type(head,(list,element)).
% direction(head,(in,out)).
body_pred(last,2).
% type(last,(list,element)).
% direction(last,(in,out)).
body_pred(length,2).
% type(length,(list,int)).
% direction(length,(in,out)).
body_pred(sum,3).
% type(sum,(int,int,int)).
% direction(sum,(in,in,out)).
body_pred(cons,3).
% type(cons,(element,list,list)).
% direction(cons,(in,in,out)).
body_pred(empty,1).
% type(empty,(list,1)).
% direction(empty,(in,)).
body_pred(zero,1).
% type(zero,(int,)).
% direction(zero,(in,)).
bk.pl
cons(A,B,C):-
append([A],B,C).
tail([_|T],T).
head([H|_],H).
sum(A,B,C):-
C is A+B.
empty([]).
zero(0).
exs.pl
pos(f([65, 32, 87, 84, 25, 91, 36, 43, 64, 78, 51, 65, 90],[65, 32, 87, 84, 25, 91, 36, 43, 64, 78, 51, 65])).
pos(f([65, 32],[65])).
pos(f([1,2,3],[1,2])).
pos(f([65, 32,23],[65,32])).
neg(f([1,2,3],[1,2,3])).
neg(f([1,2,3],[1])).
Running the program:
$ time python3 popper.py --debug hakank/droplast
20:47:46 Max rules: 2
20:47:46 Max vars: 5
20:47:46 Max body: 10
20:47:46 Num. pos examples: 4
20:47:46 Num. neg examples: 2
Traceback (most recent call last):
File "popper.py", line 8, in <module>
prog, score, stats = learn_solution(settings)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/loop.py", line 198, in learn_solution
timeout(settings, popper, (settings,), timeout_duration=int(settings.timeout),)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/util.py", line 65, in timeout
result = func(*args, **kwargs)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/loop.py", line 83, in popper
pos_covered, inconsistent = tester.test_prog(prog)
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/tester.py", line 83, in test_prog
pos_covered = frozenset(self.query('pos_covered(Xs)', 'Xs'))
File "/home/hakank/inductive_programming/andrewcropper/popper/Popper/popper/tester.py", line 14, in query
return set(next(self.prolog.query(query))[key])
File "/usr/local/lib/python3.7/site-packages/pyswip/prolog.py", line 129, in __call__
"Returned: '", str(term), "'."]))
pyswip.prolog.PrologError: Caused by: 'pos_covered(Xs)'. Returned: 'error(type_error(integer, [1, 2]), context(/(length, 2), _54))'.
Originally bias.pl contained the commented lines, but then Popper found this solution directly and then hanged. For some reason it didn't timeout after 10 minutes (I stopped it manually after 12 minutes).
20:20:36 New best hypothesis:
20:20:36 tp:1 fn:3 size:5
20:20:36 f(A,B):- cons(E,C,B),tail(D,C),head(A,E),tail(A,D).
20:20:36 ********************
20:20:36 Searching programs of size: 6
With the --debug flag it hangs here:
...
20:51:52 f(A,B):- cons(C,A,B),f(B,A),head(A,C).
20:51:52 Program 64:
20:51:52 f(A,B):- tail(A,B).
20:51:52 f(A,B):- last(A,C),f(B,A),cons(C,A,B).
20:51:52 Program 65:
20:51:52 f(A,B):- tail(A,B).
20:51:52 f(A,B):- f(B,A),tail(A,C),tail(C,B).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
hakank commented
Thanks. After I fixed bias.pl this works as expected.