Too many stacked Strings

Hi,
I am having this error, using prolog from python. In stackoverflow it says that, I could call the below command
swipl -G100g -T20g -L2g
or I could add the below lines.

:- set_prolog_stack(global, limit(100000000000)).
:- set_prolog_stack(trail,  limit(20000000000)).
:- set_prolog_stack(local,  limit(2000000000)).

None of them solved the problem in my case.
I found out the problem occurs due to a variable MAX_LG_STACKED_STRINGS which is set to 20. The related files are:
src/os/pl-buffer.h and src/os/pl-buffer.h

Can you please help me how to solve this problem? I do not have a C compiler? What should I update?
Many thanks,
Ferda

I have read that compiling for windows is very complicated here.
https://www.swi-prolog.org/build/windows.html
and here it is shown how to do it
https://www.swi-prolog.org/build/MinGW.txt

I do not have mingw and pacman in my pc.
I would appreciate help to solve this issue please.

Hi there! Could you tell us what the problem is, what error you’re getting, and what code (at least what query) you’re getting it in? I see a screenshot of the GitHub site but that doesn’t provide any information about what your problem actually is.

No matter what, you absolutely should not need to recompile Prolog itself, don’t worry about that!

1 Like

Hi
You are very right. I get the below error, when I run the pl code from python interface. It occurs on relatively larger data which caused more calls mainly (I guess).
I think if someone could update that constant to like 2000 or if they can make it configurable then the problem will be solved.
Many thanks and thank you for your interest…
Ferda

SWI-Prolog: [FATAL ERROR: at Fri Jul 30 21:01:39 2021
Too many stacked strings]

This link describes the error.

What would help others to help you would be to supply a Minimal and reproducible working example. :slightly_smiling_face:

Hi,
I pointed out the lines where the error comes from. I think, at this point it would be harder to try to recreate the error in your PCs. It works together with (it is called based on) some metadata stored in python files. So, very difficult to recreate the error in your PCs. I would have to share all my software. Instead, I already found the error source in the C source file. It is due to a limitation of a defined low number.

PL code is not very complicated, it basically makes some path searches in a tree based on some conditions.

Thanks for your interest.
Ferda

If you really think that building SWI-Prolog for Windows is one of your better options then see

I have not used it myself but if I had to build a Windows version of SWI-Prolog that is the first thing I would try.

Hi Again,
In the PL file I do not do anything related to string processing.
This is the content of the PL file. I call the path functions from python.

path_generic(A,B,Path) :- path(X,Y,Path),sub_atom(X,0,_,_,A), sub_atom(Y,0,_,_,B).
path(A,B,Path) :- travel(A,B,[A],Q), reverse(Q,Path).
travel(A,B,P,[B|P]) :- arc(A,B).
travel(A,B,Visited,Path) :- arc(A,C), C \== B, \+member(C,Visited), travel(C,B,[C|Visited],Path).
%arc_ext(A,B) :- arc(X,Y),sub_atom(X,0,_,_,A), sub_atom(Y,0,_,_,B).


path_generic_nested(A,B,PathN) :- path_nested(X,Y,PathN),sub_atom(X,0,_,_,A), sub_atom(Y,0,_,_,B).
path_nested(A,B,PathN) :- travel_nested(A,B,[A],Q), reverse(Q,PathN).
travel_nested(A,B,P,[B|P]) :- arc(A,B).
travel_nested(A,B,Visited,PathN) :- arc(A,C), C \== B, \+member(C,Visited), travel_nested(C,B,[C|Visited],PathN).
adjacent(E0, E1, L) :- append(_, [E0,E1|_], L).
arc_generic(A,B) :- arc(X,Y),sub_atom(X,0,_,_,A),sub_atom(Y,0,_,_,B).
arc_start_generic(A,B) :- arc(X,Y),sub_atom(X,0,_,_,A).
arc_end_generic(A,B) :- arc(X,Y),sub_atom(Y,0,_,_,B).
arc_with_specific_start(A,B) :- arc(A,_).
arc_with_specific_end(A,B) :- arc(_,B).
path_start_generic(A,B) :- arc(X,Y), sub_atom(X,0,_,_,A).
path_end_generic(A,B) :- arc(X,Y),sub_atom(Y,0,_,_,B).

The error occurs when I call path_generic. I need to use sub_atom’s cause my program needs it. This is all I can say. I am sorry. This is part of an academic study and I do not feel very comfortable discussing the details of my code and I am not allowed to do also.

As I said, I can not provide all the details to reproduce it, for it to happen, I need to share all my software which is large and I need to share my metadata and data( which are private). All I can share was the pl file.

I did my best to figure out the origin of the problem and found the lines from the source code. Please help me to solve this problem cause I already lost so much time on this :frowning:

Many thanks,
Ferda

I call it like this

‘path_generic(‘B’,‘21’, P)’

ARCS are defined as below in python and the path generic is called like

prolog.assertz('arc(\'A\',\'1\')')

prolog.query('path_generic(\'B\',\'21\', P)')

Please use code blocks for code. You can put three ticks on a line before and after the lines of code. There should be a stickied post about how to use markdown on Discourse

Boris is correct. However until just a moment ago Python was not one of the options. I just added Python to the list. See: Language highlighting

In parallel to figuring out the markdown on Discourse, try to narrow down your problem. This is a necessary first step to reporting it. As @j4n_bur53 suggested, you can try to use bisection of your code, among other things. Once you create a minimal reproducible example you can share, it becomes possible for others to reproduce your problem and troubleshoot it. You can increase the limit but it will only push the problem to a bigger input, not solve it, as @j4n_bur53 also explained.

You can also use sub_string/5, with either atom or string argument. This will also avoid adding to the atom table, if that is the cause of your problem:

?- sub_string(abc, 0, _, _, A).
A = "" ;
A = "a" ;
A = "ab" ;
A = "abc".

Which version of swipl are you using? e.g.:

?- prolog_flag(version, Z).
Z = 'SWI-Prolog 8.3.27 (x86_64-linux): Jul 13 2021, 13:43:28'.

(I ran this on Windows, using the Windows Subsystem for Linux (WSL).)

Anyway, from a quick look at your code, you appear to be doing a backtracking search for a path through a graph (with the graph defined by arc/2 facts). This can quickly produce a huge amount of backtracking. How many facts are in the arc/2 predicate? How large are the strings (or atoms) that are given to sub_atom/5?

One more thing you can do, if you don’t want to show your data, is to give the output of a call to jiti_list(user:_) (assuming your code is in the default user module).

1 Like

Hi,
I am getting a feeling that nobody focuses on the lines pointed out in pl-buffer.c and pl-buffer.h.
Please can you focus on the solution. As you see, I am doing some path searches not String processing. I have ARCS and PATHS. I use ’ not " but when I pasted, somehow it looked different (as if I copied from a word doc.). The error message is below. I get this on larger data (meaning more number of arcs, in my case 38 arcs) not for smaller datasets (in my case 10 arcs). In the larger dataset I have some arcs starting with an alphabet continuing with numbers like ‘23_1’. The subatoms are needed to process that kind of arcs.
I hope this information becomes useful.
Many Thanks,
Ferda

SWI-Prolog: [FATAL ERROR: at Sat Jul 31 11:35:15 2021
Too many stacked strings]I am getting

It is not easy to find as Markdown by itself because it is a link from this topic.

Discourse New User Tips and Tricks

The relevant links:

Markdown reference
Markdown Tutorial


EDIT

In the topic Minimal and reproducible working examples is also a link to better Markdown documentation.

1 Like

This limit is there for a reason, we all assume. Maybe none of us truly understands the reason. With a reproducible example, it would be possible to establish that something that should obviously work is broken, and more importantly, know what it is. This way it is possible to fix it without violating the original reasoning behind this admittedly arbitrary limit.

You’re making a large assumption that these lines are the cause of the problem and not merely a symptom. Because you cannot give a “minimal reproducible example”, we are having to guess as to the cause.

@j4n_bur53 has suggested a way of finding the problem. You might want to modify that advice slightly, e.g.:

path_generic(A,B,Path) :- 
    writeln(user_error, 1-path_generic(A,B,Path)),
    path(X,Y,Path),
    writeln(user_error, 2-path_generic(A,B,Path)-[x=X,y=Y]),
    sub_atom(X,0,_,_,A), 
    writeln(user_error, 3-path_generic(A,B,Path)-[x=X,y=Y,a=A]),
    sub_atom(Y,0,_,_,B),
    writeln(user_error, 4-path_generic(A,B,Path)-[x=X,y=Y,a=A,b=B).

This might produce a lot of output, so you might wish to redirect the output to a file. I don’t know how to do this on Windows; on Linux, I’d do something like swipl ... 2>/tmp/msgs.

(Instead of using writeln/2, you might do:
format(user_error, '~q~n', [1-path_generic(A,B,Path)])
etc.)

1 Like