trustworthyAI
trustworthyAI copied to clipboard
error in convert_graph_int_to_adj_mat
Hello,
I am trying to use Causal Disocvery RL on bnlearn benchmarks. I encounter the error in convert_graph_int_to_adj_mat function.
The input to this function is
[-1903318164 235405414 101482606 495790951 201853294 378349935
-1634426101 -1718146065 134742090 64 134742086 134742084
446475107 470616428 -1785775892 -1768316434 201884524 134217728
201949548 -1903613075 470286702 101187694 -1734505621 503843118
-2070074547 134217838 513518542 503875886 235405386 445754223
0 524358 236432367 134742086 134217792 134217792
503908622]
And the error message follows:
Traceback (most recent call last):
File "main.py", line 337, in <module>
main()
File "main.py", line 285, in main
graph_batch = convert_graph_int_to_adj_mat(graph_int)
File "/home/user/Causal_Discovery_RL/src/helpers/analyze_utils.py", line 156, in convert_graph_int_to_adj_mat
for curr_int in graph_int], dtype=int)
File "/home/user/Causal_Discovery_RL/src/helpers/analyze_utils.py", line 156, in <listcomp>
for curr_int in graph_int], dtype=int)
ValueError: invalid literal for int() with base 10: '-'
the issue is fixed by changing np.int32
to int
in several places of the codebase. the error is due to the overflow of int32.
The error would occur again when the node size exceeds 64 (which is the precision limit of int long
).
There is an np.int64
used here which could be the reason for the error. You can try to change it to int
similarly to how the np.int32
were changed.
Thanks for your prompt reply. It looks like the URL does not point to the codebase of Causal Discovery with RL. Nevertheless, I have already changed the place in the codebase of Causal Discovery with RL. But it looks like a limitation for numpy to process such lengthy int variable.
Traceback (most recent call last):
File "main.py", line 344, in <module>
main()
File "main.py", line 280, in main
graph_int, score_min, cyc_min = np.array(ls_kv[0][0], dtype=np.int), ls_kv[0][1][1], ls_kv[0][1][-1]
OverflowError: Python int too large to convert to C long
I guess changing np.int
to np.longlong
may be a workaround. but how could I work with larger graphs like andes
?
It turns out that changing the precision cannot deal with the issue when the node size is higher than 64.
Traceback (most recent call last):
File "main.py", line 344, in <module>
main()
File "main.py", line 280, in main
graph_int, score_min, cyc_min = np.array(ls_kv[0][0], dtype=np.longlong), ls_kv[0][1][1], ls_kv[0][1][-1]
OverflowError: int too big to convert
It turns out that changing the precision cannot deal with the issue when the node size is higher than 64.
Traceback (most recent call last): File "main.py", line 344, in <module> main() File "main.py", line 280, in main graph_int, score_min, cyc_min = np.array(ls_kv[0][0], dtype=np.longlong), ls_kv[0][1][1], ls_kv[0][1][-1] OverflowError: int too big to convert
Sorry for a late reply. A quick fix is to use string, instead of int type, as key. E.g., 000111 is converted to ‘000111‘. We have change this part in internal codes but seemed not to update the github ..
Again, sorry for this.