Merge branch 'version-1.0.1'
[jackhill/guix/guix.git] / gnu / packages / graph.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2018 Joshua Sierles, Nextjournal <joshua@nextjournal.com>
4 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
5 ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
6 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
13 ;;;
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21
22 (define-module (gnu packages graph)
23 #:use-module (guix download)
24 #:use-module (guix git-download)
25 #:use-module (guix packages)
26 #:use-module (guix utils)
27 #:use-module (guix build-system cmake)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system python)
30 #:use-module (guix build-system r)
31 #:use-module ((guix licenses) #:prefix license:)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages gcc)
34 #:use-module (gnu packages bioconductor)
35 #:use-module (gnu packages bioinformatics)
36 #:use-module (gnu packages check)
37 #:use-module (gnu packages compression)
38 #:use-module (gnu packages cran)
39 #:use-module (gnu packages graphviz)
40 #:use-module (gnu packages maths)
41 #:use-module (gnu packages multiprecision)
42 #:use-module (gnu packages pkg-config)
43 #:use-module (gnu packages python)
44 #:use-module (gnu packages python-web)
45 #:use-module (gnu packages python-xyz)
46 #:use-module (gnu packages statistics)
47 #:use-module (gnu packages swig)
48 #:use-module (gnu packages time)
49 #:use-module (gnu packages xml))
50
51 (define-public igraph
52 (package
53 (name "igraph")
54 (version "0.7.1")
55 (source
56 (origin
57 (method url-fetch)
58 (uri (string-append "http://igraph.org/nightly/get/c/igraph-"
59 version ".tar.gz"))
60 (sha256
61 (base32
62 "1pxh8sdlirgvbvsw8v65h6prn7hlm45bfsl1yfcgd6rn4w706y6r"))))
63 (build-system gnu-build-system)
64 (arguments
65 `(#:configure-flags
66 (list "--with-external-glpk"
67 "--with-external-blas"
68 "--with-external-lapack")))
69 (inputs
70 `(("gmp" ,gmp)
71 ("glpk" ,glpk)
72 ("libxml2" ,libxml2)
73 ("lapack" ,lapack)
74 ("openblas" ,openblas)
75 ("zlib" ,zlib)))
76 (home-page "http://igraph.org")
77 (synopsis "Network analysis and visualization")
78 (description
79 "This package provides a library for the analysis of networks and graphs.
80 It can handle large graphs very well and provides functions for generating
81 random and regular graphs, graph visualization, centrality methods and much
82 more.")
83 (license license:gpl2+)))
84
85 (define-public python-igraph
86 (package (inherit igraph)
87 (name "python-igraph")
88 (version "0.7.1.post6")
89 (source
90 (origin
91 (method url-fetch)
92 (uri (pypi-uri "python-igraph" version))
93 (sha256
94 (base32
95 "0xp61zz710qlzhmzbfr65d5flvsi8zf2xy78s6rsszh719wl5sm5"))))
96 (build-system python-build-system)
97 (arguments '())
98 (inputs
99 `(("igraph" ,igraph)))
100 (native-inputs
101 `(("pkg-config" ,pkg-config)))
102 (home-page "http://pypi.python.org/pypi/python-igraph")
103 (synopsis "Python bindings for the igraph network analysis library")))
104
105 (define-public r-igraph
106 (package
107 (name "r-igraph")
108 (version "1.2.4.1")
109 (source
110 (origin
111 (method url-fetch)
112 (uri (cran-uri "igraph" version))
113 (sha256
114 (base32
115 "1074y8mvprrqlkb4vwa2qc9l03r8d7p5vaaqacj4ljjs7dvcq6l9"))))
116 (build-system r-build-system)
117 (native-inputs
118 `(("gfortran" ,gfortran)))
119 (inputs
120 `(("gmp" ,gmp)
121 ("glpk" ,glpk)
122 ("libxml2" ,libxml2)
123 ("zlib" ,zlib)))
124 (propagated-inputs
125 `(("r-magrittr" ,r-magrittr)
126 ("r-matrix" ,r-matrix)
127 ("r-pkgconfig" ,r-pkgconfig)))
128 (home-page "http://igraph.org")
129 (synopsis "Network analysis and visualization")
130 (description
131 "This package provides routines for simple graphs and network analysis.
132 It can handle large graphs very well and provides functions for generating
133 random and regular graphs, graph visualization, centrality methods and much
134 more.")
135 (license license:gpl2+)))
136
137 (define-public r-diffusionmap
138 (package
139 (name "r-diffusionmap")
140 (version "1.1-0.1")
141 (source
142 (origin
143 (method url-fetch)
144 (uri (cran-uri "diffusionMap" version))
145 (sha256
146 (base32
147 "11l4kbciawvli5nlsi4qaf8afmgk5xgqiqpdyhvaqri5mx0zhk5j"))))
148 (properties `((upstream-name . "diffusionMap")))
149 (build-system r-build-system)
150 (propagated-inputs
151 `(("r-igraph" ,r-igraph)
152 ("r-matrix" ,r-matrix)
153 ("r-scatterplot3d" ,r-scatterplot3d)))
154 (home-page "https://www.r-project.org")
155 (synopsis "Diffusion map")
156 (description "This package implements the diffusion map method of data
157 parametrization, including creation and visualization of diffusion maps,
158 clustering with diffusion K-means and regression using the adaptive regression
159 model.")
160 (license license:gpl2)))
161
162 (define-public r-rgraphviz
163 (package
164 (name "r-rgraphviz")
165 (version "2.28.0")
166 (source
167 (origin
168 (method url-fetch)
169 (uri (bioconductor-uri "Rgraphviz" version))
170 (sha256
171 (base32
172 "0nivz8fshaqig6ynjqbya2gmxsy4hm7jnd8fhb853z5g0ydp7g0c"))))
173 (properties `((upstream-name . "Rgraphviz")))
174 (build-system r-build-system)
175 ;; FIXME: Rgraphviz bundles the sources of an older variant of
176 ;; graphviz. It does not build with the latest version of graphviz, so
177 ;; we do not add graphviz to the inputs.
178 (inputs `(("zlib" ,zlib)))
179 (propagated-inputs
180 `(("r-graph" ,r-graph)))
181 (native-inputs
182 `(("pkg-config" ,pkg-config)))
183 (home-page "http://bioconductor.org/packages/Rgraphviz")
184 (synopsis "Plotting capabilities for R graph objects")
185 (description
186 "This package interfaces R with the graphviz library for plotting R graph
187 objects from the @code{graph} package.")
188 (license license:epl1.0)))
189
190 (define-public r-rbiofabric
191 (let ((commit "666c2ae8b0a537c006592d067fac6285f71890ac")
192 (revision "1"))
193 (package
194 (name "r-rbiofabric")
195 (version (string-append "0.3-" revision "." (string-take commit 7)))
196 (source (origin
197 (method git-fetch)
198 (uri (git-reference
199 (url "https://github.com/wjrl/RBioFabric.git")
200 (commit commit)))
201 (file-name (string-append name "-" version "-checkout"))
202 (sha256
203 (base32
204 "1yahqrcrqpbcywv73y9rlmyz8apdnp08afialibrr93ch0p06f8z"))))
205 (build-system r-build-system)
206 (propagated-inputs
207 `(("r-igraph" ,r-igraph)))
208 (home-page "http://www.biofabric.org/")
209 (synopsis "BioFabric network visualization")
210 (description "This package provides an implementation of the function
211 @code{bioFabric} for creating scalable network digrams where nodes are
212 represented by horizontal lines, and edges are represented by vertical
213 lines.")
214 (license license:expat))))
215
216 (define-public python-plotly
217 (package
218 (name "python-plotly")
219 (version "2.4.1")
220 (source
221 (origin
222 (method url-fetch)
223 (uri (pypi-uri "plotly" version))
224 (sha256
225 (base32
226 "0s9gk2fl53x8wwncs3fwii1vzfngr0sskv15v3mpshqmrqfrk27m"))))
227 (build-system python-build-system)
228 (arguments
229 '(#:tests? #f)) ; The tests are not distributed in the release
230 (propagated-inputs
231 `(("python-decorator" ,python-decorator)
232 ("python-nbformat" ,python-nbformat)
233 ("python-pandas" ,python-pandas)
234 ("python-pytz" ,python-pytz)
235 ("python-requests" ,python-requests)
236 ("python-six" ,python-six)))
237 (home-page "https://plot.ly/python/")
238 (synopsis "Interactive plotting library for Python")
239 (description "Plotly's Python graphing library makes interactive,
240 publication-quality graphs online. Examples of how to make line plots, scatter
241 plots, area charts, bar charts, error bars, box plots, histograms, heatmaps,
242 subplots, multiple-axes, polar charts, and bubble charts. ")
243 (license license:expat)))
244
245 (define-public python2-plotly
246 (package-with-python2 python-plotly))
247
248 (define-public python-louvain
249 (package
250 (name "python-louvain")
251 (version "0.6.1")
252 ;; The tarball on Pypi does not include the tests.
253 (source (origin
254 (method git-fetch)
255 (uri (git-reference
256 (url "https://github.com/vtraag/louvain-igraph.git")
257 (commit version)))
258 (file-name (git-file-name name version))
259 (sha256
260 (base32
261 "0w31537sifkf65sck1iaip5i6d8g64pa3wdwad83d6p9jwkck57k"))))
262 (build-system python-build-system)
263 (propagated-inputs
264 `(("python-ddt" ,python-ddt)
265 ("python-igraph" ,python-igraph)))
266 (inputs
267 `(("igraph" ,igraph)))
268 (native-inputs
269 `(("pkg-config" ,pkg-config)
270 ("python-pytest" ,python-pytest)))
271 (home-page "https://github.com/vtraag/louvain-igraph")
272 (synopsis "Algorithm for methods of community detection in large networks")
273 (description
274 "This package provides an implementation of the Louvain algorithm for use
275 with igraph. Louvain is a general algorithm for methods of community
276 detection in large networks.
277
278 This package has been superseded by the @code{leidenalg} package and should
279 not be used for new projects.")
280 (license license:gpl3+)))
281
282 (define-public faiss
283 (package
284 (name "faiss")
285 (version "1.5.0")
286 (source (origin
287 (method git-fetch)
288 (uri (git-reference
289 (url "https://github.com/facebookresearch/faiss.git")
290 (commit (string-append "v" version))))
291 (file-name (git-file-name name version))
292 (sha256
293 (base32
294 "0pk15jfa775cy2pqmzq62nhd6zfjxmpvz5h731197c28aq3zw39w"))
295 (modules '((guix build utils)))
296 (snippet
297 '(begin
298 (substitute* "utils.cpp"
299 (("#include <immintrin.h>")
300 "#ifdef __SSE__\n#include <immintrin.h>\n#endif"))
301 #t))))
302 (build-system cmake-build-system)
303 (arguments
304 `(#:configure-flags
305 (list "-DBUILD_WITH_GPU=OFF" ; thanks, but no thanks, CUDA.
306 "-DBUILD_TUTORIAL=OFF") ; we don't need those
307 #:phases
308 (modify-phases %standard-phases
309 (add-after 'unpack 'prepare-build
310 (lambda _
311 (let ((features (list ,@(let ((system (or (%current-target-system)
312 (%current-system))))
313 (cond
314 ((string-prefix? "x86_64" system)
315 '("-mavx" "-msse2" "-mpopcnt"))
316 ((string-prefix? "i686" system)
317 '("-msse2" "-mpopcnt"))
318 (else
319 '()))))))
320 (substitute* "CMakeLists.txt"
321 (("-m64") "")
322 (("-mpopcnt") "") ; only some architectures
323 (("-msse4")
324 (string-append
325 (string-join features)
326 " -I" (getcwd)))
327 ;; Build also the shared library
328 (("ARCHIVE DESTINATION lib")
329 "LIBRARY DESTINATION lib")
330 (("add_library.*" m)
331 "\
332 add_library(objlib OBJECT ${faiss_cpu_headers} ${faiss_cpu_cpp})
333 set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
334 add_library(${faiss_lib}_static STATIC $<TARGET_OBJECTS:objlib>)
335 add_library(${faiss_lib} SHARED $<TARGET_OBJECTS:objlib>)
336 install(TARGETS ${faiss_lib}_static ARCHIVE DESTINATION lib)
337 \n")))
338
339 ;; See https://github.com/facebookresearch/faiss/issues/520
340 (substitute* "IndexScalarQuantizer.cpp"
341 (("#define USE_AVX") ""))
342
343 ;; Make header files available for compiling tests.
344 (mkdir-p "faiss")
345 (for-each (lambda (file)
346 (mkdir-p (string-append "faiss/" (dirname file)))
347 (copy-file file (string-append "faiss/" file)))
348 (find-files "." "\\.h$"))
349 #t))
350 (replace 'check
351 (lambda _
352 (invoke "make" "-C" "tests"
353 (format #f "-j~a" (parallel-job-count)))))
354 (add-after 'install 'remove-tests
355 (lambda* (#:key outputs #:allow-other-keys)
356 (delete-file-recursively
357 (string-append (assoc-ref outputs "out")
358 "/test"))
359 #t)))))
360 (inputs
361 `(("openblas" ,openblas)))
362 (native-inputs
363 `(("googletest" ,googletest)))
364 (home-page "https://github.com/facebookresearch/faiss")
365 (synopsis "Efficient similarity search and clustering of dense vectors")
366 (description "Faiss is a library for efficient similarity search and
367 clustering of dense vectors. It contains algorithms that search in sets of
368 vectors of any size, up to ones that possibly do not fit in RAM. It also
369 contains supporting code for evaluation and parameter tuning.")
370 (license license:bsd-3)))
371
372 (define-public python-faiss
373 (package (inherit faiss)
374 (name "python-faiss")
375 (build-system python-build-system)
376 (arguments
377 `(#:phases
378 (modify-phases %standard-phases
379 (add-after 'unpack 'chdir
380 (lambda _ (chdir "python") #t))
381 (add-after 'chdir 'build-swig
382 (lambda* (#:key inputs #:allow-other-keys)
383 (with-output-to-file "../makefile.inc"
384 (lambda ()
385 (let ((python-version ,(version-major+minor (package-version python))))
386 (format #t "\
387 PYTHONCFLAGS =-I~a/include/python~am/ -I~a/lib/python~a/site-packages/numpy/core/include
388 LIBS = -lpython~am -lfaiss
389 SHAREDFLAGS = -shared -fopenmp
390 CXXFLAGS = -fpermissive -std=c++11 -fopenmp -fPIC
391 CPUFLAGS = ~{~a ~}~%"
392 (assoc-ref inputs "python*") python-version
393 (assoc-ref inputs "python-numpy") python-version
394 python-version
395 (list ,@(let ((system (or (%current-target-system)
396 (%current-system))))
397 (cond
398 ((string-prefix? "x86_64" system)
399 '("-mavx" "-msse2" "-mpopcnt"))
400 ((string-prefix? "i686" system)
401 '("-msse2" "-mpopcnt"))
402 (else
403 '()))))))))
404 (substitute* "Makefile"
405 (("../libfaiss.a") ""))
406 (invoke "make" "cpu"))))))
407 (inputs
408 `(("faiss" ,faiss)
409 ("openblas" ,openblas)
410 ("python*" ,python)
411 ("swig" ,swig)))
412 (propagated-inputs
413 `(("python-matplotlib" ,python-matplotlib)
414 ("python-numpy" ,python-numpy)))
415 (description "Faiss is a library for efficient similarity search and
416 clustering of dense vectors. This package provides Python bindings to the
417 Faiss library.")))
418
419 (define-public python-leidenalg
420 (package
421 (name "python-leidenalg")
422 (version "0.7.0")
423 (source
424 (origin
425 (method url-fetch)
426 (uri (pypi-uri "leidenalg" version))
427 (sha256
428 (base32
429 "15fwld9hdw357rd026mzcwpah5liy4f33vc9x9kwy37g71b2rjf1"))))
430 (build-system python-build-system)
431 (arguments '(#:tests? #f)) ; tests are not included
432 (native-inputs
433 `(("pkg-config" ,pkg-config)))
434 (inputs
435 `(("igraph" ,igraph)))
436 (propagated-inputs
437 `(("python-igraph" ,python-igraph)))
438 (home-page "https://github.com/vtraag/leidenalg")
439 (synopsis "Community detection in large networks")
440 (description
441 "Leiden is a general algorithm for methods of community detection in
442 large networks. This package implements the Leiden algorithm in C++ and
443 exposes it to Python. Besides the relative flexibility of the implementation,
444 it also scales well, and can be run on graphs of millions of nodes (as long as
445 they can fit in memory). The core function is @code{find_partition} which
446 finds the optimal partition using the Leiden algorithm, which is an extension
447 of the Louvain algorithm, for a number of different methods.")
448 (license license:gpl3+)))