tag:blogger.com,1999:blog-85580010061262169322017-06-19T12:14:44.409-07:00Performance Improvements for the Graph Module of SagemathMichele Borassinoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8558001006126216932.post-31801501434333844272015-08-16T06:59:00.001-07:002015-08-16T06:59:35.624-07:00Conclusion of the Main Part of the Project<span style="font-size: small;">Hi!</span><br /><span style="font-size: small;">In this post, I will summarize the results obtained with the inclusion in Sage of Boost and igraph libraries. This was the main part of my Google Summer of Code project, and it was completed yesterday, when ticket 19003 was closed.</span><br /><br /><span style="font-size: small;">We have increased the number of graph algorithms available in Sage from 66 to 98 (according to the list used in the initial comparison of the graph libraries [1]). Furthermore, we decreased the running-time of several Sage algorithms: in some cases, we have been able to improve the asymptotic running-time, obtaining up to 10000x improvements in our tests. Finally, during the inclusion of external algorithms, we have refactored and cleaned some of Sage source code, like the shortest path routines: we have standardized the input and the output of 15 routines related to shortest paths, and we have removed duplicate code as much as possible.</span><br /><br /><span style="font-size: small;">More specifically, the first part of the project was the inclusion of Boost graph library: since the library is only available in C++, we had to develop an interface. This interface lets us convert easily a Sage graph into a Boost graph, and run algorithms on the converted graph. Then, we have written routines to re-translate the output into a Sage-readable format: this way, the complicated Boost library is "hidden", and users can interact with it as they do with Sage. In particular, we have interfaced the following algorithms:</span><br /><ul><li><span style="font-size: small;">Edge connectivity (trac.sagemath.org/ticket/18564);</span></li><li><span style="font-size: small;">Clustering coefficient </span><span style="font-size: small;">(trac.sagemath.org/ticket/18811);</span></li><li><span style="font-size: small;">Cuthill-McKee and King vertex orderings </span><span style="font-size: small;">(trac.sagemath.org/ticket/18876);</span></li><li><span style="font-size: small;">Minimum spanning tree</span><span style="font-size: small;"> </span><span style="font-size: small;">(trac.sagemath.org/ticket/18910);</span></li><li><span style="font-size: small;">Dijkstra, Bellman-Ford, Johnson shortest paths</span><span style="font-size: small;"> </span><span style="font-size: small;">(trac.sagemath.org/ticket/18931);</span></li></ul><span style="font-size: small;">All these algorithms were either not available in Sage, or quite slow, compared to the Boost routines. As far as we know, Boost does not offer other algorithms that improve Sage algorithms: however, if such algorithms are developed in the future, it will be very easy to include them, using the new interface.</span><br /><span style="font-size: small;"><br /></span><span style="font-size: small;">In the second part of the project, we included igraph: since this library already offers a Python interface, we decided to include it as an optional package (before it becomes a standard package, at least an year should pass [2]). To install the package, it is enough to type the following instruction from the Sage root folder:</span><br /><br /><span style="font-family: "Courier New",Courier,monospace;"><span style="font-size: small;">sage -i igraph # To install the igraph C core</span></span><br /><span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;">sage -i python_igraph # To install the Python interface</span></span><br /><br />Then, we can easily interact with igraph: for a list of available routines, it is enough to type "<span style="font-family: "Courier New",Courier,monospace;">igraph.</span>" and click tab twice. To convert a Sage graph <span style="font-family: "Courier New",Courier,monospace;">g_sage</span> into an igraph graph it is enough to type <span style="font-family: "Courier New",Courier,monospace;">g_igraph = g_sage.igraph_graph()</span>, while a Sage graph can be instantiated from an igraph graph through <span style="font-family: "Courier New",Courier,monospace;">g_sage=Graph(g_igraph)</span> or <span style="font-family: "Courier New",Courier,monospace;">g_sage=DiGraph(g_igraph)</span>. This way, all igraph algorithms are now available in Sage.<br /><br />Furthermore, we have included the igraph maximum flow algoritm inside the Sage corresponding function, obtaining significant improvements (for more information and benchmarks, we refer to ticket 19003 [3]).<br /><br />In conclusion, I think the project reached its main goal, the original plan was followed very closely, and we have been able to overcome all problems.<br /><br />Before closing this post, I would like to thank many people that helped me with great advices, and who provided great solutions to all the problems I faced. First of all, my mentor David Coudert: he always answered very fast to all my queries, and he gave me great suggestions to improve the quality of the code I wrote. Then, a very big help came from Nathann Cohen, who often cooperated with David in reviewing my code and proposing new solutions. Moreover, I have to thank Martin Cross, who gave me good suggestions with Boost graph library, and Volker Braun, who closed all my ticket. Finally, I have to thank the whole Sage community for giving me this great opportunity!<br /><br />[1] https://docs.google.com/spreadsheets/d/1Iu1hkQtRn9J-sgfZbQTu2RoXzyjoMEWP5-cm3nAwnWE/edit?usp=sharing<br />[2] http://doc.sagemath.org/html/en/developer/coding_in_other.html<br />[3] http://trac.sagemath.org/ticket/19003Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0tag:blogger.com,1999:blog-8558001006126216932.post-20605577668714805712015-07-27T09:07:00.001-07:002015-07-27T09:07:42.429-07:00Including igraph LibraryHello!<br />In this new blog post, I would like to discuss the inclusion of igraph library inside Sage.<br />Up to now, I have interfaced Sagemath with Boost graph library, in order to run Boost algorithms inside Sage. Now, I want to do the same with igraph, the other major C++ graph library, which stands out because it contains 62 routines, 29 of which are not available in Sage. Moreover, igraph library is very efficient, as shown in [1] and in the previous post on library comparison.<br /><br />This inclusion of igraph in Sage is quite complicated, because we have to include a new external library [2] (while in the Boost case we already had the sources). We started this procedure through ticket <a href="http://trac.sagemath.org/ticket/18929">18929</a>: unfortunately, after this ticket is closed, igraph will only be an optional package, and we will have to wait one year before it becomes standard. The disadvantage of optional packages is that they must be installed before being able to use them; however, the installation is quite easy: it is enough to run Sage with option <span style="font-family: "Courier New",Courier,monospace;">-i python_igraph</span>.<br /><br />After the installation, the usage of igraph library is very simple, because igraph already provides a Python interface, that can be used in Sage. To transform the Sagemath network <span style="font-family: "Courier New",Courier,monospace;">g_sage</span> into an igraph network <span style="font-family: "Courier New",Courier,monospace;">g_igraph</span>, it is enough to type <span style="font-family: "Courier New",Courier,monospace;">g_igraph=g_sage.igraph_graph()</span>, while to create a Sagemath network from an igraph network it is enough to type <span style="font-family: "Courier New",Courier,monospace;">g_sage = Graph(g_igraph)</span> or <span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;"></span>g_sage=DiGraph(g_igraph)<span style="font-family: Arial,Helvetica,sans-serif;"></span></span>. After this conversion, we can use all routines offered by igraph!<br />For instance, if we want to create a graph through the preferential attachment model, we can do it with the Sagemath routine, or with the igraph routine:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.RandomBarabasiAlbert(100, 2)<br />sage: G.num_verts()<br />100<br />sage: G = Graph(igraph.Graph.Barabasi(100, int(2)))<br />sage: G.num_verts()<br />100</span><br /><br />The result is the same (apart from randomness), but the time is very different:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: import igraph<br />sage: %timeit G = Graph(igraph.Graph.Barabasi(10000000, int(2)))<br />1 loops, best of 3: 46.2 s per loop</span><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.RandomBarabasiAlbert(10000000, 2)</span><br /><span style="font-family: "Courier New",Courier,monospace;">Stopped after 3 hours.</span><br /><br />Otherwise, we may use igraph to generate graphs with Forest-Fire algorithm, which is not available in Sagemath:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = Graph(igraph.Graph.Forest_Fire(10, 0.1))<br />sage: G.edges()<br />[(0, 1, None), (0, 2, None), (1, 7, None), (2, 3, None), (2, 4, None), (3, 5, None), (3, 8, None), (4, 6, None), (8, 9, None)]</span><br /><br /><br />We may also do the converse: transform a Sage network into an igraph network and apply an igraph algorithm. For instance, we can use label propagation to find communities (a task which is not implemented in Sage):<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.CompleteGraph(5)+graphs.CompleteGraph(5)</span><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G.add_edge(0,5)<br />sage: com = G.igraph_graph().community_label_propagation()<br />sage: len(com)<br />2<br />sage: com[0]<br />[0, 1, 2, 3, 4]<br />sage: com[1]<br />[5, 6, 7, 8, 9]</span><br /><br />The algorithm found the two initial cliques as communities.<br /><br />I hope that these examples are enough to show the excellent possibilities offered by igraph library, and that these features will soon be available in Sagemath!<br /><br />[1] <a href="https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code/library-comparison">https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code/library-comparison</a><br />[2] <a href="http://doc.sagemath.org/html/en/developer/packaging.html">http://doc.sagemath.org/html/en/developer/packaging.html</a>Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com1tag:blogger.com,1999:blog-8558001006126216932.post-25951083974405605132015-07-09T12:51:00.002-07:002015-07-09T12:51:47.054-07:00New Boost Algorithms<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script><script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$', '$'], ['\\(', '\\)']]}}); </script>Hello!<br />My Google Summer of Code project is continuing, and I am currently trying to include more Boost algorithms in Sage. In this post, I will make a list of the main algorithms I'm working on.<br /><br /><h4>Clustering Coefficient</h4><br />If two different people have a friend in common, there is a high chance that they will become friends: this is the property that the clustering coefficient tries to capture. For instance, if I pick two random people, very probably they will not know each other, but if I pick two of my acquaintances, very probably they will know each other. In this setting, the clustering coefficient of a person is the probability that two random acquaintances of this person know each other. In order to quantify this phenomenon, we can formalize everything in terms of graphs: people are nodes and two people are connected if they are acquaintances. Hence, we define the clustering coefficient of a vertex \(v\) in a graph \(G=(V,E)\) as:<br />$$\frac{2|\{(x,y) \in E:x,y \in N_v\}|}{\deg(v)(\deg(v)-1)}$$ where \(N_v\) is the set of neighbors of \(v\) and \(\deg(v)\) is the number of neighbors of \(v\). This is exactly the probability that two random neighbors of \(v\) are linked with an edge.<br />My work has included in Sagemath the Boost algorithm to compute the clustering coefficient, which is more efficient that the previous algorithm, which was based on NetworkX:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: g = graphs.RandomGNM(20000,100000)</span><br /><span style="font-family: "Courier New",Courier,monospace;">sage: %timeit g.clustering_coeff(implementation='boost')</span><br /><span style="font-family: "Courier New",Courier,monospace;">10 loops, best of 3: 258 ms per loop</span><br /><span style="font-family: "Courier New",Courier,monospace;">sage: %timeit g.clustering_coeff(implementation='networkx')</span><br /><span style="font-family: "Courier New",Courier,monospace;">1 loops, best of 3: 3.99 s per loop</span><br /><br />But Nathann did better: he implemented a clustering coefficient algorithm from scratch, using Cython, and he managed to outperform the Boost algorithm, at least when the graph is dense. Congratulations, Nathann! However, when the graph is sparse, Boost algorithm still seems to be faster.<br /><br /><h4>Dominator tree</h4><br />Let us consider a road network, that is, a graph where vertices are street intersections, and edges are streets. The question is: if I close an intersection, where am I still able to go, assuming I am at home?<br />The answer to this question can be summarized in a dominator tree. Assume that, in order to go from my home to my workplace, I can choose many different paths, but all these paths pass through the café, then they pass through the square (that is, if either the café or the square is closed, then there is no way I can go to work). In this case, in the dominator tree, the father of my workplace is the square, the father of the square is the café, and the father of the café is my home, that is also the root of the tree. More formally, given a graph \(G\), the dominator tree of \(G\) rooted at a vertex \(v\) is defined by connecting each vertex \(x\) with the last vertex \(y \neq x\) that belongs to each path from \(v\) to \(x\) (note that this vertex always exists, because \(v\) belongs to each path from \(v\) to \(x\)).<br />Until now, Sagemath did not have a routine to compute the dominator tree: I have been able to include the Boost algorithm. Unfortunately, due to several suggestions and improvements in the code, the ticket is not closed, yet. Hopefully, it will be closed very soon!<br /><br /><h4>Cuthill-McKee ordering / King ordering</h4><br />Let us consider a graph \(G=(V,E)\): a matrix \(M\) of size \(|V|\) can be associated to this graph, where \(M_{i,j}=1\) if and only if there is an edge between vertices \(i\) and \(j\).<br />In some cases, this matrix can have specific properties, that can be exploited for many purposes, like speeding-up algorithms. One of this properties is bandwidth, which measures how far the matrix is from a diagonal matrix: it is defined as \(\max_{M_{i,j} \neq 0}|i-j|\). A small bandwidth might help in computing several properties of the graph, like eigenvalues and eigenvectors.<br />Since the bandwidth depends on the order of vertices, we can try to permute them in order to obtain a smaller value: in Sage, we have a routine that performs this task. However, this routine is very slow, and it is prohibitive even for very small graphs (in any case, finding an optimal ordering is NP-hard).<br />Hence, researchers have developed heuristics to compute good orderings: the most important ones are Cuthill-McKee ordering and King ordering. Boost contains both routines, but Sage does not: for this reason, I would like to insert these two functions. The code is almost ready, but part of it depends on the code of the dominator tree: as soon as the dominator tree is reviewed, I will open a ticket on these two routines!<br /><br /><h4>Dijkstra/Bellman-Ford/Johnson shortest paths</h4><br />Let us consider again a road network. In this case, we are building a GPS software, which has to compute the shortest path between the place where we are and the destination. The textbook algorithm that performed this task is Dijkstra algorithm, which computes the distance between the starting point and any other reachable point (of course, there are more efficient algorithms involving a preprocessing, but Dijkstra is the most simple, and its running-time is asymptotically optimal). This algorithm is already implemented in Sagemath.<br />Let's spice things up: what if that there are some streets with negative length? For instance, we like a street so much that we are willing to drive 100km more just to pass from that street, which is 50km long. It is like that street is -50km long!<br />First of all, under these assumptions, a shortest path might not exist: if there is a cycle with negative length, we may drive along that cycle all the times we want, decreasing more and more the distance to the destination. At least, we have to assume that no negative cycle exists.<br />Even with this assumption, Dijkstra algorithm does not work, and we have to perform Bellman-Ford algorithm, which is less efficient, but more general. Now, assume that we want something more: we are trying to compute the distance between all possible pairs of vertices. The first possibility is to run Bellman-Ford algorithm \(n\) times, where \(n\) is the number of nodes in the graph. But there is a better alternative: it is possible to perform Bellman-Ford algorithm only once, and then to modify the lengths of edges, so that all lengths are positive, and shortest paths are not changed. This way, we run Dijkstra algorithm \(n\) times on this modified graph, obtaining a better running time. This is Johnson algorithm.<br />Both Bellman-Ford and Johnson algorithms are implemented in Boost and not in Sagemath. As soon as I manage to create weighted Boost graphs (that is, graphs where edges have a length), I will include also these two algorithm!Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0tag:blogger.com,1999:blog-8558001006126216932.post-75474834218034605952015-06-25T00:56:00.003-07:002015-06-25T00:56:40.472-07:00Edge Connectivity through Boost Graph LibraryAfter two weeks, we have managed to interface Boost and Sagemath! <br /><br />However, the interface was not as simple as it seemed. The main problem we found is the genericity of Boost: almost all Boost algorithms work with several graph implementations, which differ in the data structures used to store edges and vertices. For instance, the code that implements breadth-first search works if the adjacency list of a vertex v is a vector, a list, a set, etc. This result is accomplished by using templates [1]. Unfortunately, the only way to interface Sagemath with C++ code is Cython, which is not template-friendly, yet. In particular, Cython provides genericity through fused types [2], whose support is still experimental, and which do not offer full integration with templates [3-5].<br /><br />After a thorough discussion with David, Nathann, and Martin (thank you very much!), we have found a solution: for the input, we have defined a fused type "BoostGenGraph", including all Boost graph implementations, and all functions that interface Boost and Sagemath use this fused type. This way, for each algorithm, we may choose the most suitable graph implementation. For the output, whose type might be dependent on the input type, we use C++ to transform it into a "standard" type (vector, or struct).<br /><br />We like this solution because it is very clean, and it allows us to exploit Boost genericity without any copy-paste. Still, there are some drawbacks:<br />1) Cython fused types do not allow nested calls of generic functions;<br />2) Boost graphs cannot be converted to Python objects: they must be defined and deleted in the same Cython function;<br />3) No variable can have a generic type, apart from the arguments of generic functions.<br /><br />These drawbacks will be overcome as soon as Cython makes templates and generic types interact: this way, we will be able create a much stronger interface, by writing a graph backend based on Boost, so that the user might create, convert, and modify Boost graphs directly from Python. However, for the moment, we will implement all algorithms using the current interface, which already provides genericity, and which has no drawback if the only goal is to "steal" algorithms from Boost.<br /><br />As a test, we have computed the edge connectivity of a graph through Boost: the code is available in ticket 18564 [6]. Since the algorithm provided by Sagemath is not optimal (it is based on linear programming), the difference in the running time is impressive, as shown by the following tests:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.RandomGNM(100,1000)<br />sage: %timeit G.edge_connectivity()<br />100 loops, best of 3: 1.42 ms per loop<br />sage: %timeit G.edge_connectivity(implementation="sage")<br />1 loops, best of 3: 11.3 s per loop</span><br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.RandomBarabasiAlbert(300,3)<br />sage: %timeit G.edge_connectivity(implementation="sage")<br />1 loops, best of 3: 9.96 s per loop<br />sage: %timeit G.edge_connectivity()<br />100 loops, best of 3: 3.33 ms per loop</span><br /><br />Basically, on a random Erdos-Renyi graph with 100 vertices and 1000 edges, the new algorithm is 8,000 times faster, and on a random Barabasi-Albert graph with 300 nodes and average degree 3, the new algorithm is 3,000 times faster! This way, we can compute the edge connectivity of much bigger graphs, like a random Erdos-Renyi graph with 5,000 vertices and 50,000 edges:<br /><br /><span style="font-family: "Courier New",Courier,monospace;">sage: G = graphs.RandomGNM(5,000, 50,000)<br />sage: %timeit G.edge_connectivity()<br />1 loops, best of 3: 16.2 s per loop</span><br /><br />The results obtained with this first algorithm are very promising: in the next days, we plan to interface several other algorithms, in order to improve both the number of available routines and the speed of Sagemath graph library!<br /><br />[1] https://en.wikipedia.org/wiki/Template_%28C%2B%2B%29<br />[2] http://docs.cython.org/src/userguide/fusedtypes.html<br />[3] https://groups.google.com/forum/#!topic/cython-users/qQpMo3hGQqI<br />[4] https://groups.google.com/forum/#!searchin/cython-users/fused/cython-users/-7cHr6Iz00Y/Z8rS03P7-_4J<br />[5] https://groups.google.com/forum/#!searchin/cython-users/fused$20template/cython-users/-7cHr6Iz00Y/Z8rS03P7-_4J<br />[6] http://trac.sagemath.org/ticket/18564Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0tag:blogger.com,1999:blog-8558001006126216932.post-5171090360630535372015-06-09T07:24:00.003-07:002015-06-09T07:30:46.265-07:00Performance Comparison of Different Graph LibrariesAs promised in the last post, I have compared the performances of several graph libraries, in order to choose which ones should be deployed with Sagemath. Here, I provide the main results of this analysis, while more details are available on <a href="https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code/library-comparison">my website</a> (see also the links below).<br />The libraries chosen are the most famous graph libraries written in Python, C, or C++ (I have chosen these languages because they are easier to integrate in Sagemath, using Cython). Furthermore, I have excluded NetworkX, which is already deployed with Sagemath.<br />First of all, I have to enforce that no graph library comparison can be completely fair, and also this comparison can be criticized, due to the large amount of available routines, to the constant evolution of libraries, and to many small differences in the outputs (for instance, one library might compute the value of a maximum s-t flow, another library might actually compute the flow, and a third one might compute all maximum flows). Despite this, I have tried to be as fair as possible, through a deeper and more detailed analysis than previous comparisons (<a href="https://graph-tool.skewed.de/performance">https://graph-tool.skewed.de/performance</a>, <a href="http://www.programmershare.com/3210372/">http://www.programmershare.com/3210372/</a>, <a href="http://arxiv.org/pdf/1403.3005.pdf">http://arxiv.org/pdf/1403.3005.pdf</a>).<br />The first comparison deals with the number of algorithms implemented. I have chosen a set of 107 possible algorithms, trying to cover all possible tasks that a graph library should perform (avoiding easy tasks that are common to all libraries, like outputting the number of nodes, the number of edges, the neighbors of a node, etc). In some cases, two tasks were collapsed in one, if the algorithms solving these tasks are very similar (for instance, computing a maximum flow and computing a minimum cut, computing vertex betweenness and edge betweenness, etc).<br />The number of routines available for each library is plotted in the following chart, and a table containing all features is available in <a href="https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code/library-comparison/detailed-feature-comparison">HTML</a> or as a <a href="https://docs.google.com/spreadsheets/d/1Iu1hkQtRn9J-sgfZbQTu2RoXzyjoMEWP5-cm3nAwnWE/edit?usp=sharing">Google Sheet</a>.<br /><iframe frameborder="0" height="371" scrolling="no" seamless="" src="https://docs.google.com/spreadsheets/d/1Iu1hkQtRn9J-sgfZbQTu2RoXzyjoMEWP5-cm3nAwnWE/pubchart?oid=1599448996&format=interactive" width="600"></iframe> <br />The results show that Sagemath has more routines than all competitors (66), closely followed by igraph (62). All other libraries are very close to each other, having about 30 routines each. Furthermore, Sagemath could be improved in the fields of neighbor similarity measures (assortativity, bibcoupling, cocitation, etc), community detection, and random graph generators. For instance, igraph contains 29 routines that are not available in Sagemath.<br /><br />The second comparison analyzes the running-time of some of the algorithms implemented in the libraries. In particular, I have chosen 8 of the most common tasks in graph analysis: computing the diameter, computing the maximum flow between two vertices, finding connected components and strongly connected components, computing betweenness centrality, computing the clustering coefficient, computing the clique number, and generating a graph with the preferential attachment model. I have run each of these algorithms on 3 inputs, and I have considered the total execution time (excluding the time needed to load the graph). More details on this experiment are available <a href="https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code/library-comparison/detailed-performance-comparison">here</a>, and the results are also available in a <a href="https://docs.google.com/spreadsheets/d/1Iu1hkQtRn9J-sgfZbQTu2RoXzyjoMEWP5-cm3nAwnWE/edit?usp=sharing">Google Sheet</a>.<br />In order to make the results more readable, I have plotted the ratio between the time needed by a given library and the minimum time needed by any library. If an algorithm was not implemented, or it needed more than 3 hours to complete, the corresponding bar is not shown.<br /><iframe frameborder="0" height="558" scrolling="no" seamless="" src="https://docs.google.com/spreadsheets/d/1Iu1hkQtRn9J-sgfZbQTu2RoXzyjoMEWP5-cm3nAwnWE/pubchart?oid=2112149438&format=interactive" width="862"></iframe> <br />Overall, the results show that NetworKit is the fastest library, or one of the fastest, in all routines that are implemented (apart from the generation of preferential attachment graphs, where it is very slow). Boost graph library is very close to NetworKit, and it also contains more routines. Also Sagemath is quite efficient in all tasks, apart from the computation of strongly connected components and the generation of a preferential attachment graph, where it needed more than 3 hours. However, in the latter case, the main problem was not speed but memory consumption.<br /><br />In conclusion, Sagemath can highly benefit from the possibility of using algorithms from other libraries. First of all, it might improve the number of algorithms offered, especially by including igraph, and it also might improve its performance, by including Boost, NetworKit, or other fast graph libraries.Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0tag:blogger.com,1999:blog-8558001006126216932.post-57277685728642206592015-06-04T02:11:00.001-07:002015-06-04T02:11:58.614-07:00Comparison of Graph LibrariesMany times, people asked me "Which is the best available graph library?", or "Which graph library should I use to compute this, or that?".<br />Well, personally I love to use Sage, but there are also several good alternatives. Then, the question becomes "How could we improve Sage, so that people will choose it?".<br /><br />In my opinion, graph libraries are compared according to the following parameters:<br /><ol><li>simplicity and documentation: people have little time, and the faster they learn how to use the library, the better;</li><li>number of routines available;</li><li>speed: sometimes, the input is very big, and the algorithms take much time to finish, so that a fast implementation is fundamental.</li></ol>While it is very difficult to measure the first point, the others can be compared and improved. For this reason, in order to outperform other libraries, we should implement new features, and improve existing ones. You don't say!<br /><br />However, this answer is not satisfactory: in principle, we could add all features available in other libraries, but this is a huge translational work, and while we are doing this work the other libraries will change, making this effort a never-ending story.<br /><br />My project proposes an alternative: cooperating instead of competing. I will try to interface Sage with other libraries, and to use their algorithms when the Sage counterpart is not available, or less efficient. This way, with an affordable amount of work, we will be able to run all algorithms available in the best graph libraries!<br /><br />As a first step, I have compared all the most famous C, C++, and Python graph libraries according to points 2 and 3, in order to choose which libraries should be included. The next posts will analyze the results of this comparison.Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0tag:blogger.com,1999:blog-8558001006126216932.post-63716155805692566622015-06-04T01:10:00.000-07:002015-06-04T01:10:03.579-07:00Google Summer of Code: let's start!This blog will follow my Google Summer of Code project, entitled <i>Performance Improvements for the Graph Module of Sagemath</i>. The complete project is available <a href="https://sites.google.com/a/imtlucca.it/borassi/unpublished-works/google-summer-of-code">here</a>, and related documents with partial results will be available on the same website.<br />In this first post, I would like to thank my mentor David Coudert and Nathann Cohen, who helped me a lot in writing this project and understanding how the graph module of Sagemath works.<br />With their help, and with the help of the Sage community, I hope it will be a useful and funny work! Let's start!Michele Borassihttps://plus.google.com/103742177528816762937noreply@blogger.com0