gnu: Add cl-ana.statistical-learning.
[jackhill/guix/guix.git] / gnu / packages / simulation.scm
index 7165fb5..edc8d6e 100644 (file)
 
 (define-module (gnu packages simulation)
   #:use-module (gnu packages)
+  #:use-module (gnu packages algebra)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages boost)
   #:use-module (gnu packages check)
+  #:use-module (gnu packages cmake)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages flex)
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
+  #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages readline)
   #:use-module (gnu packages tls)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages xml)
   #:use-module (gnu packages xorg)
   #:use-module (guix download)
-  #:use-module (guix build utils)
+  #:use-module (guix build-system cmake)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system python)
   #:use-module ((guix licenses) #:prefix license:)
        (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32 "0cgxh4h2hf50qbvvdg5miwc2nympb0nrv3md96vb3gbs9vk8vq9d"))
-       (patches (search-patches "openfoam-4.1-cleanup.patch"))))
+       (patches (search-patches "openfoam-4.1-cleanup.patch"))
+       (modules '((guix build utils)))
+       (snippet
+        '(begin
+           ;; Include <sys/sysmacros.h>, which is where glibc >= 2.28 provides
+           ;; 'major' and 'minor'.
+           (substitute* "src/OSspecific/POSIX/fileStat.C"
+             (("#include <unistd\\.h>")
+              "#include <unistd.h>\n#include <sys/sysmacros.h>\n"))
+           #t))))
     (build-system gnu-build-system)
     (inputs
      `(("boost" ,boost)
@@ -255,6 +268,11 @@ problems for efficient solution on parallel systems.")
              (setenv "PYTHONPATH"
                      (string-append (getcwd) ":" (getenv "PYTHONPATH")))
              (with-directory-excursion "test"
+               ;; Disable parallel tests to avoid race condition.  See
+               ;; https://github.com/pytest-dev/pytest-cov/issues/237.
+               (substitute* "runtests.sh"
+                 (("for p in 1 4 8 16; do")
+                  "for p in 1; do"))
                (invoke "./runtests.sh"))
              #t)))))
     (home-page "https://bitbucket.org/fenics-project/dijitso/")
@@ -307,3 +325,406 @@ forms in a notation close to mathematical notation.
 
 UFL is part of the FEniCS Project.")
     (license license:lgpl3+)))
+
+(define-public python-fenics-fiat
+  (package
+    (name "python-fenics-fiat")
+    (version "2018.1.0")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (pypi-uri "fenics-fiat" version))
+        (sha256
+          (base32
+            "0fmjd93r6bwf6xs8csw86qzphrnr66xwv7f372w59gmq8mg6rljc"))))
+    (build-system python-build-system)
+    (native-inputs
+     `(("python-pytest" ,python-pytest)))
+    (propagated-inputs
+     `(("python-numpy" ,python-numpy)
+       ("python-sympy" ,python-sympy)))
+    (arguments
+     '(#:phases
+       (modify-phases %standard-phases
+         (replace 'check
+           (lambda _
+             (setenv "PYTHONPATH"
+                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
+             (with-directory-excursion "test"
+               (invoke "py.test" "unit/"))
+             #t)))))
+    (home-page "https://bitbucket.org/fenics-project/fiat/")
+    (synopsis "Tabulation of finite element function spaces")
+    (description
+      "The FInite element Automatic Tabulator (FIAT) supports
+generation of arbitrary order instances of the Lagrange elements on
+lines, triangles, and tetrahedra.  It is also capable of generating
+arbitrary order instances of Jacobi-type quadrature rules on the same
+element shapes.  Further, H(div) and H(curl) conforming finite element
+spaces such as the families of Raviart-Thomas, Brezzi-Douglas-Marini
+and Nedelec are supported on triangles and tetrahedra.  Upcoming
+versions will also support Hermite and nonconforming elements.
+
+FIAT is part of the FEniCS Project.")
+    (license license:lgpl3+)))
+
+(define-public python-fenics-ffc
+  (package
+    (name "python-fenics-ffc")
+    (version "2018.1.0")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (pypi-uri "fenics-ffc" version))
+        (sha256
+          (base32
+            "1b2ia5vlkw298x7rf0k2p3ihlpwkwgc98p3s6sbpds3hqmfrzdz9"))))
+    (build-system python-build-system)
+    (native-inputs
+     `(("python-pytest" ,python-pytest)))
+    (propagated-inputs
+     `(("python-fenics-dijitso" ,python-fenics-dijitso)
+       ("python-fenics-fiat" ,python-fenics-fiat)
+       ("python-fenics-ufl" ,python-fenics-ufl)))
+    (arguments
+     '(#:phases
+       (modify-phases %standard-phases
+         (replace 'check
+           (lambda _
+             (setenv "HOME" (getcwd))
+             (setenv "PYTHONPATH"
+                     (string-append (getcwd) ":" (getenv "PYTHONPATH")))
+             (with-directory-excursion "test"
+               ;; FIXME: the tests in subdirectory
+               ;; 'unit/ufc/finite_element' require the ffc_factory
+               ;; extension module.  This module, located in the 'libs'
+               ;; subdirectory, needs to be built and made accessible
+               ;; prior to running the tests.
+               (invoke "py.test" "unit/" "--ignore=unit/ufc/")
+               (with-directory-excursion "uflacs"
+                 (invoke "py.test" "unit/")))
+             #t)))))
+    (home-page "https://bitbucket.org/fenics-project/ffc/")
+    (synopsis "Compiler for finite element variational forms")
+    (description "The FEniCS Form Compiler (FFC) is a compiler for
+finite element variational forms.  From a high-level description of
+the form, it generates efficient low-level C++ code that can be used
+to assemble the corresponding discrete operator (tensor).  In
+particular, a bilinear form may be assembled into a matrix and a
+linear form may be assembled into a vector.  FFC may be used either
+from the command line (by invoking the @code{ffc} command) or as a
+Python module (@code{import ffc}).
+
+FFC is part of the FEniCS Project.")
+    ;; There are two files released with a public domain licence;
+    ;; ufc.h and ufc_geometry.h, in subdirectory 'ffc/backends/ufc'.
+    (license (list license:public-domain license:lgpl3+))))
+
+(define-public fenics-dolfin
+  (package
+    (name "fenics-dolfin")
+    (version "2018.1.0.post1")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (string-append
+              "https://bitbucket.org/fenics-project/dolfin/get/"
+              version ".tar.gz"))
+        (file-name (string-append name "-" version ".tar.gz"))
+        (sha256
+          (base32
+           "12zkk8j3xsg6l8p0ggwsl03084vlcivw4h99b7z9kndg7k89b3ya"))
+        (modules '((guix build utils)))
+        (snippet
+         '(begin
+            ;; Make sure we don't use the bundled test framework.
+            (delete-file-recursively "test/unit/cpp/catch")
+            (substitute* "test/unit/cpp/main.cpp"
+              ;; Use standard search paths for 'catch' header file.
+              (("#include.*")
+               "#include <catch.hpp>\n"))
+            (substitute* "test/unit/cpp/CMakeLists.txt"
+              ;; Add extra include directories required by the unit tests.
+              (("(^target_link_libraries.*)" line)
+               (string-append line "\n"
+                              "target_include_directories("
+                              "unittests PRIVATE "
+                              "${DOLFIN_SOURCE_DIR} "
+                              "${DOLFIN_SOURCE_DIR}/dolfin "
+                              "${DOLFIN_BINARY_DIR})\n"))
+              (("(^set\\(CATCH_INCLUDE_DIR ).*(/catch\\))" _ front back)
+               (string-append front
+                              "$ENV{CATCH_DIR}"
+                              "/include" back "\n")))
+            (substitute* "demo/CMakeLists.txt"
+              ;; Add extra include directories required by the demo tests.
+              (("(^#find_package.*)" line)
+               (string-append line "\n"
+                              "include_directories("
+                              "${DOLFIN_SOURCE_DIR} "
+                              "${DOLFIN_SOURCE_DIR}/dolfin "
+                              "${DOLFIN_BINARY_DIR})\n")))
+            (substitute* "dolfin/nls/PETScSNESSolver.cpp"
+              ;; Remove SNESTEST mapping.  The SNESTEST symbol was removed
+              ;; from PETSc at version 3.10.3.
+              ((".*SNESTEST.*") "" ))
+            #t))))
+    (build-system cmake-build-system)
+    (inputs
+     `(("blas" ,openblas)
+       ("boost" ,boost)
+       ("eigen" ,eigen)
+       ("hdf5" ,hdf5-parallel-openmpi)
+       ("lapack" ,lapack)
+       ("libxml2" ,libxml2)
+       ("openmpi" ,openmpi)
+       ("python" ,python-3)
+       ("scotch" ,pt-scotch32)
+       ("suitesparse" ,suitesparse)
+       ("sundials" ,sundials-openmpi)
+       ("zlib" ,zlib)))
+    (native-inputs
+     `(("catch" ,catch-framework2)
+       ("pkg-config" ,pkg-config)))
+    (propagated-inputs
+     `(("ffc" ,python-fenics-ffc)
+       ("petsc" ,petsc-openmpi)
+       ("slepc" ,slepc-openmpi)))
+    (arguments
+     `(#:configure-flags
+       `("-DDOLFIN_ENABLE_DOCS:BOOL=OFF"
+         "-DDOLFIN_ENABLE_HDF5:BOOL=ON"
+         "-DDOLFIN_ENABLE_MPI:BOOL=ON"
+         "-DDOLFIN_ENABLE_PARMETIS:BOOL=OFF"
+         "-DDOLFIN_ENABLE_SCOTCH:BOOL=ON"
+         "-DDOLFIN_ENABLE_SUNDIALS:BOOL=ON"
+         "-DDOLFIN_ENABLE_TRILINOS:BOOL=OFF")
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'patch-usr-bin-file 'mpi-setup
+           ,%openmpi-setup)
+         (add-after 'patch-source-shebangs 'set-paths
+           (lambda _
+             ;; Define paths to store locations.
+             (setenv "BLAS_DIR" (assoc-ref %build-inputs "blas"))
+             (setenv "CATCH_DIR" (assoc-ref %build-inputs "catch"))
+             (setenv "LAPACK_DIR" (assoc-ref %build-inputs "lapack"))
+             (setenv "PETSC_DIR" (assoc-ref %build-inputs "petsc"))
+             (setenv "SLEPC_DIR" (assoc-ref %build-inputs "slepc"))
+             (setenv "SCOTCH_DIR" (assoc-ref %build-inputs "scotch"))
+             (setenv "SUNDIALS_DIR" (assoc-ref %build-inputs "sundials"))
+             (setenv "UMFPACK_DIR" (assoc-ref %build-inputs "suitesparse"))
+             #t))
+         (add-before 'check 'pre-check
+           (lambda _
+             ;; The Dolfin repository uses git-lfs, whereby web links are
+             ;; substituted for large files.  Guix does not currently support
+             ;; git-lfs, so only the links are downloaded.  The tests that
+             ;; require the absent meshes cannot run and are skipped.
+             ;;
+             ;; Two other serial tests fail and are skipped.
+             ;; i) demo_stokes-iterative_serial,
+             ;;   The MPI_Comm_rank() function was called before MPI_INIT was
+             ;;   invoked
+             ;; ii) demo_multimesh-stokes_serial:
+             ;;   Warning: Found no facets matching domain for boundary
+             ;;   condition.
+             ;;
+             ;; One mpi test fails and is skipped.
+             ;; i) demo_stokes-iterative_mpi:
+             ;;   The MPI_Comm_rank() function was called before MPI_INIT was
+             ;;   invoked
+             (call-with-output-file "CTestCustom.cmake"
+               (lambda (port)
+                 (display
+                   (string-append
+                    "set(CTEST_CUSTOM_TESTS_IGNORE "
+                    "demo_bcs_serial "
+                    "demo_bcs_mpi "
+                    "demo_eigenvalue_serial "
+                    "demo_eigenvalue_mpi "
+                    "demo_navier-stokes_serial "
+                    "demo_navier-stokes_mpi "
+                    "demo_stokes-taylor-hood_serial "
+                    "demo_stokes-taylor-hood_mpi "
+                    "demo_subdomains_serial "
+                    "demo_advection-diffusion_serial "
+                    "demo_advection-diffusion_mpi "
+                    "demo_auto-adaptive-navier-stokes_serial "
+                    "demo_contact-vi-snes_serial "
+                    "demo_contact-vi-snes_mpi "
+                    "demo_contact-vi-tao_serial "
+                    "demo_contact-vi-tao_mpi "
+                    "demo_curl-curl_serial "
+                    "demo_curl-curl_mpi "
+                    "demo_dg-advection-diffusion_serial "
+                    "demo_dg-advection-diffusion_mpi "
+                    "demo_elasticity_serial "
+                    "demo_elasticity_mpi "
+                    "demo_elastodynamics_serial "
+                    "demo_elastodynamics_mpi "
+                    "demo_lift-drag_serial "
+                    "demo_lift-drag_mpi "
+                    "demo_mesh-quality_serial "
+                    "demo_mesh-quality_mpi "
+                    "demo_multimesh-stokes_serial "
+                    "demo_stokes-iterative_serial "
+                    "demo_stokes-iterative_mpi "
+                    ")\n") port)))
+             #t))
+         (replace 'check
+           (lambda _
+             (and (invoke "make" "unittests")
+                  (invoke "make" "demos")
+                  (invoke "ctest" "-R" "unittests")
+                  (invoke "ctest" "-R" "demo" "-R" "serial")
+                  (invoke "ctest" "-R" "demo" "-R" "mpi")))))))
+    (home-page "https://bitbucket.org/fenics-project/dolfin/")
+    (synopsis "Problem solving environment for differential equations")
+    (description
+      "DOLFIN is a computational framework for finding numerical
+solutions to problems described by differential equations.  Numerical
+models in DOLFIN are constructed using general families of finite
+elements.  Data structures are provided for discretizing the governing
+system on a computational mesh.  A compact syntax, similar to
+mathematical notation, is made available for defining function spaces
+and expressing variational forms.  Interfaces to specialized matrix
+solvers are provided for solving the resultant linear systems.
+
+@code{fenics-dolfin} is part of the FEniCS project.  It is the C++
+user interface to the FEniCS core components and external libraries.")
+    ;; The source code for the DOLFIN C++ library is licensed under the
+    ;; GNU Lesser General Public License, version 3 or later, with the
+    ;; following exceptions:
+    ;;
+    ;; public-domain: dolfin/geometry/predicates.cpp
+    ;;                dolfin/geometry/predicates.h
+    ;;
+    ;; zlib:          dolfin/io/base64.cpp
+    ;;                dolfin/io/base64.h
+    ;;
+    ;; expat:         dolfin/io/pugiconfig.hpp
+    ;;                dolfin/io/pugixml.cpp
+    ;;                dolfin/io/pugixml.hpp
+    (license (list license:public-domain
+                   license:zlib
+                   license:expat
+                   license:lgpl3+))))
+
+(define-public fenics
+  (package (inherit fenics-dolfin)
+    (name "fenics")
+    (build-system python-build-system)
+    (inputs
+     `(("pybind11" ,pybind11)
+       ("python-matplotlib" ,python-matplotlib)
+       ,@(alist-delete "python" (package-inputs fenics-dolfin))))
+    (native-inputs
+     `(("cmake" ,cmake-minimal)
+       ("ply" ,python-ply)
+       ("pytest" ,python-pytest)
+       ("python-decorator" ,python-decorator)
+       ("python-pkgconfig" ,python-pkgconfig)
+       ,@(package-native-inputs fenics-dolfin)))
+    (propagated-inputs
+     `(("dolfin" ,fenics-dolfin)
+       ("petsc4py" ,python-petsc4py)
+       ("slepc4py" ,python-slepc4py)))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'patch-source-shebangs 'set-paths
+           (lambda _
+             ;; Define paths to store locations.
+             (setenv "PYBIND11_DIR" (assoc-ref %build-inputs "pybind11"))
+             ;; Move to python sub-directory.
+             (chdir "python")
+             #t))
+         (add-after 'build 'mpi-setup
+           ,%openmpi-setup)
+         (add-before 'check 'pre-check
+           (lambda _
+             ;; Exclude tests that require meshes supplied by git-lfs.
+             (substitute* "demo/test.py"
+               (("(.*stem !.*)" line)
+                (string-append
+                 line "\n"
+                 "excludeList = [\n"
+                 "'multimesh-quadrature', \n"
+                 "'multimesh-marking', \n"
+                 "'mixed-poisson-sphere', \n"
+                 "'mesh-quality', \n"
+                 "'lift-drag', \n"
+                 "'elastodynamics', \n"
+                 "'dg-advection-diffusion', \n"
+                 "'curl-curl', \n"
+                 "'contact-vi-tao', \n"
+                 "'contact-vi-snes', \n"
+                 "'collision-detection', \n"
+                 "'buckling-tao', \n"
+                 "'auto-adaptive-navier-stokes', \n"
+                 "'advection-diffusion', \n"
+                 "'subdomains', \n"
+                 "'stokes-taylor-hood', \n"
+                 "'stokes-mini', \n"
+                 "'navier-stokes', \n"
+                 "'eigenvalue']\n"
+                 "demos = ["
+                 "d for d in demos if d[0].stem not in "
+                 "excludeList]\n")))
+             (setenv "HOME" (getcwd))
+             (setenv "PYTHONPATH"
+                     (string-append
+                      (getcwd) "/build/lib.linux-x86_64-"
+                      ,(version-major+minor (package-version python)) ":"
+                      (getenv "PYTHONPATH")))
+             ;; Restrict OpenBLAS to MPI-only in preference to MPI+OpenMP.
+             (setenv "OPENBLAS_NUM_THREADS" "1")
+             #t))
+         (replace 'check
+           (lambda _
+             (with-directory-excursion "test"
+               ;; Note: The test test_snes_set_from_options() in the file
+               ;; unit/nls/test_PETScSNES_solver.py fails and is ignored.
+               (and (invoke "py.test" "unit" "--ignore"
+                            "unit/nls/test_PETScSNES_solver.py")
+                    (invoke "mpirun" "-np" "3" "python" "-B" "-m"
+                            "pytest" "unit" "--ignore"
+                            "unit/nls/test_PETScSNES_solver.py")))
+             (with-directory-excursion "demo"
+               ;; Check demos.
+               (invoke "python" "generate-demo-files.py")
+               (and (invoke "python" "-m" "pytest" "-v" "test.py")
+                    (invoke "python" "-m" "pytest" "-v" "test.py"
+                            "--mpiexec=mpiexec" "--num-proc=3")))
+             #t))
+         (add-after 'install 'install-demo-files
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let* ((demos (string-append
+                            (assoc-ref outputs "out")
+                            "/share/python-dolfin/demo")))
+               (mkdir-p demos)
+               (with-directory-excursion "demo"
+                 (for-each (lambda (file)
+                             (let* ((dir (dirname file))
+                                    (tgt-dir (string-append demos "/" dir)))
+                               (unless (equal? "." dir)
+                                 (mkdir-p tgt-dir)
+                                 (install-file file tgt-dir))))
+                           (find-files "." ".*\\.(py|gz|xdmf)$"))))
+             #t)))))
+    (home-page "https://fenicsproject.org/")
+    (synopsis "High-level environment for solving differential equations")
+    (description
+      "@code{fenics} is a computing platform for solving general classes of
+problems that involve differential equations.  @code{fenics} facilitates
+access to efficient methods for dealing with ordinary differential
+equations (ODEs) and partial differential equations (PDEs).  Systems of
+equations such as these are commonly encountered in areas of engineering,
+mathematics and the physical sciences.  It is particularly well-suited to
+problems that can be solved using the Finite Element Method (FEM).
+
+@code{fenics} is the top level of the set of packages that are developed
+within the FEniCS project.  It provides the python user interface to the
+FEniCS core components and external libraries.")
+    (license license:lgpl3+)))