Integrating algorithms implemented in C++ and Java into SageMath

63 views
Skip to first unread message

Jing Guo

unread,
Oct 8, 2023, 9:38:54 AM10/8/23
to sage-devel
Dear all,

Some days ago I asked a question [0] here regarding performance of Sage and fast graph algorithms.

For a project I am/will be working on, I am thinking about adding a interface/library for homomorphism counting into Sage, which should be helpful for many researchers. This implementation is largely written in C++ (including a little CUDA for parallel computation), with some Java code for tree decomposition (from the PACE 2017 challenge).

In the Sage developer documentation, it's only written for using external libraries [1] and packing third-party codes [2]. There are no results for "Java" or "GPU".

My questions:

1) What would be a good approach to integrate C++ codes into Sage, via Cython?

2) In the Sage repo on GitHub, there is no Java files. Is it possible to integrate Java into Sage as well, or it would involve some JVM/GraalVM issues?

3) Homomorphism counting can be slow on very large graphs, so it would helpful to use GPU for computation. My plan is to use CPU for computing by default, and allow users to enable GPU computing via an optional argument.

I couldn't find anything on GitHub Sage repo or the developer documentation, so I was wondering are GPU and CUDA currently supported by Sage? (In [0], cugraph [3] was also mentioned) If so, what would be the recommended approaches here?

Many thanks.


Jing

Dima Pasechnik

unread,
Oct 9, 2023, 6:26:16 AM10/9/23
to sage-...@googlegroups.com
On Sun, Oct 8, 2023 at 2:38 PM Jing Guo <dev....@gmail.com> wrote:
> Some days ago I asked a question [0] here regarding performance of Sage and fast graph algorithms.
>
> For a project I am/will be working on, I am thinking about adding a interface/library for homomorphism counting into Sage, which should be helpful for many researchers. This implementation is largely written in C++ (including a little CUDA for parallel computation), with some Java code for tree decomposition (from the PACE 2017 challenge).

How is your implementation dealing with Java vs C++ interface? Do you
call JVM from C++?
Something else?

Why you can't use tree decomposition available in Sage?
https://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_decompositions/tree_decomposition.html
E.g. it has an interface to tdlib:
https://github.com/freetdi/tdlib
(tdlib is written in C++, so that's one language less - it's not clear
to me at all why anyone would use Java to code computationally
intensive
procedures which don't need anything from Java ecosystem...)

>
> In the Sage developer documentation, it's only written for using external libraries [1] and packing third-party codes [2]. There are no results for "Java" or "GPU".
>
> My questions:
>
> 1) What would be a good approach to integrate C++ codes into Sage, via Cython?
It's really a general Python question.
Yes, Cython is one option, another option is pybind11 (contourpy, a
Sage package, is using the latter, see
https://pypi.org/project/contourpy/; scipy is using
pybind11 too)

>
> 2) In the Sage repo on GitHub, there is no Java files. Is it possible to integrate Java into Sage as well, or it would involve some JVM/GraalVM issues?

it's really a general Python question. Can Java code be called from
Python ? Is there a Python extension to do just this (i.e. embed JVM
into a Python extension module). A quick search finds
https://pypi.org/project/jni/ - but I know next to nothing about Java,
so you'd have to look yourself.



>
> 3) Homomorphism counting can be slow on very large graphs, so it would helpful to use GPU for computation. My plan is to use CPU for computing by default, and allow users to enable GPU computing via an optional argument.

It's a general Python question, again.
I don't think GPU needs any special handling on the Python side; you
have examples such as PyTorchh https://github.com/pytorch/pytorch/

HTH
Dima
>
> I couldn't find anything on GitHub Sage repo or the developer documentation, so I was wondering are GPU and CUDA currently supported by Sage? (In [0], cugraph [3] was also mentioned) If so, what would be the recommended approaches here?

>
> Many thanks.
>
> [0]: https://groups.google.com/g/sage-devel/c/c7wZIrMGqIE
> [1]: https://doc.sagemath.org/html/en/developer/coding_in_other.html
> [2]: https://doc.sagemath.org/html/en/developer/packaging.html
> [3]: https://github.com/rapidsai/cugraph
>
> Jing
>
> --
> You received this message because you are subscribed to the Google Groups "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/db20b872-68f8-4543-843f-25364f73584bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages