Subject: [bug#48638] PSOPT (ADOL-C and ColPack)

From: "Eric Brown" <[email-masked]>
Date: Tue, 25 May 2021 00:04:06 -0500

Patches attached.
From 78854d28465341b68dfd94dba1aa78b48734785a Mon Sep 17 00:00:00 2001
From: Eric Brown <[email-masked]>
Date: Mon, 24 May 2021 21:58:49 -0500
Subject: [PATCH 1/3] gnu: colpack: Add colpack.

* gnu/packages/maths.scm (colpack): New variable.
---
 gnu/packages/maths.scm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index ee0a69bbd7..74890fd933 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -1827,6 +1827,35 @@ linear and quadratic objectives.  There are limited facilities for nonlinear
 and quadratic objectives using the Simplex algorithm.")
     (license license:epl1.0)))
 
+(define-public colpack
+  ;; The latest tagged release is 3 years old and there have been
+  ;; unreleased fixes, so we take the last commit.
+  (let ((commit "f328cad4141c4c6e3e30a58efcbcdacf8849124e")
+        (revision "1"))
+  (package
+    (name "colpack")
+    (version (git-version "1.0.10" revision commit))
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://salsa.debian.org/science-team/colpack.git")
+                    (commit "f328cad4141c4c6e3e30a58efcbcdacf8849124e")))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "1c7i2gm28hjpgv3qjavmbd488q3zdxfnx10w193v3xxhincfcxl6"))))
+    (build-system cmake-build-system)
+    (arguments
+     '(#:configure-flags '("-DENABLE_OPENMP=ON")))
+    (home-page "http://cscapes.cs.purdue.edu/coloringpage/")
+    (synopsis "Graph Coloring Algorithm package")
+    (description
+     "The overall aim of this project is to exploit the sparsity available in
+large-scale Jacobian and Hessian matrices the best possible way in order to
+make their computation using automatic differentiation (AD) (or finite
+differences) efficient.")
+    (license license:bsd-3))))
+
 (define-public libflame
   (package
     (name "libflame")
-- 
2.31.1

From d0263c2d40b4633a40a5675df3432424d0ba7fe2 Mon Sep 17 00:00:00 2001
From: Eric Brown <[email-masked]>
Date: Mon, 24 May 2021 22:29:23 -0500
Subject: [PATCH 2/3] gnu: adol-c: Add adol-c.

* gnu/packages/maths.scm (adol-c): New variable.
---
 gnu/packages/maths.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index 74890fd933..6d1d3dc0ca 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -1856,6 +1856,34 @@ make their computation using automatic differentiation (AD) (or finite
 differences) efficient.")
     (license license:bsd-3))))
 
+(define-public adol-c
+  (package
+    (name "adol-c")
+    (version "2.7.2")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "https://www.coin-or.org/download/source/ADOL-C/ADOL-C-"
+                    version".tgz"))
+              (sha256
+               (base32
+                "1hw2ayv91rk8s24dnx70i70vg66rwnvyb8pa7pmv4i6wkzirhawh"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:configure-flags `("--enable-sparse")))
+    (native-inputs
+     `(("gfortran" ,gfortran)))
+    (inputs
+     `(("colpack" ,colpack)
+       ("lapack" ,openblas)))
+    (home-page "https://www.coin-or.org")
+    (synopsis "Automatic Differentiation of Algorithms")
+    (description
+     "The ADOLC system automatically calculates exact derivatives of a C/C++
+function.  It uses C++ overloading to record arithmetic operations, which it
+plays back later in various ways to calculate the requested values.")
+    (license license:epl1.0)))
+
 (define-public libflame
   (package
     (name "libflame")
-- 
2.31.1

From 8c5ad02f0bedb41f86ef05d533f2ff0917d8361f Mon Sep 17 00:00:00 2001
From: Eric Brown <[email-masked]>
Date: Mon, 24 May 2021 23:40:05 -0500
Subject: [PATCH 3/3] gnu: psopt: Add psopt.

* gnu/packages/maths.scm (psopt): New variable.
---
 gnu/packages/maths.scm | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index 6d1d3dc0ca..d772d6b046 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -1884,6 +1884,45 @@ function.  It uses C++ overloading to record arithmetic operations, which it
 plays back later in various ways to calculate the requested values.")
     (license license:epl1.0)))
 
+(define-public psopt
+  (package
+    (name "psopt")
+    (version "5.0.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/PSOPT/psopt")
+                    (commit version)))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0y56lag51xdmpcak0wydzrkghypfn884nw8rd62gwgzgxgz0ls9f"))))
+    (build-system cmake-build-system)
+    (arguments
+     `(#:tests? #f ; no test suite
+       #:configure-flags
+       `(,(string-append "-Dadolc_INCLUDE_DIR="
+                         (assoc-ref %build-inputs "adol-c") "/include")
+         ,(string-append "-Dadolc_LIBRARY="
+                         (assoc-ref %build-inputs "adol-c") "/lib"))))
+    (native-inputs
+     `(("python-2" ,python-2)
+       ("pkg-config" ,pkg-config)))
+    (inputs
+     `(("adol-c" ,adol-c)
+       ("colpack" ,colpack)
+       ("eigen" ,eigen)
+       ("ipopt" ,ipopt)
+       ("lapack" ,openblas)))
+    (home-page "https://psopt.org")
+    (synopsis "Optimal Control Software")
+    (description
+     "PSOPT is an open source optimal control package written in C++ that uses
+direct collocation methods. These methods solve optimal control problems by
+approximating the time-dependent variables using global or local
+polynomials.")
+    (license license:lgpl2.1)))
+
 (define-public libflame
   (package
     (name "libflame")
-- 
2.31.1