Lichthagel / scipopt-nix

Nix flake and expressions for tools from the SCIP Optimization Suite.
MIT License
1 stars 0 forks source link

Include `hMetis` for GCG #1

Open magneticflux- opened 1 month ago

magneticflux- commented 1 month ago

hMetis is optionally used by GCG for detecting arrowhead structures, but it is unfortunately difficult to track down because the links from SCIP and GCG's sites are currently (and were in the past) dead. However, GCG's GitLab CI runs tests with hMetis and it downloads a binary from https://or.rwth-aachen.de/hmetis/hmetis-2.0pre1.tar.gz.

The included license is as follows:

Copyright and License Notice

The hMETIS package is copyrighted by the Regents of the University of Minnesota. hMETIS may not be sold or redistributed without prior approval.

It can be freely used for educational and research purposes by non-profit institutions and US government agencies only. All other organizations are allowed to use hMETIS for evaluation purposes only for a period of up to 30 days from the time of download. Any further uses will require obtaining a license from the University of Minnesota's Patent and Technology Marketing Office.

As unestablished research software, this code is provided on an ``as is'' basis without warranty of any kind, either expressed or implied. The downloading, or executing any part of this software constitutes an implicit agreement to these terms. These terms and conditions are subject to change at any time without prior notice.

GCG also says it requires zsh to enforce memory and runtime limitations (which is hilariously jank, but what can we do?)

magneticflux- commented 1 month ago

Played around a bit locally and came up with this:

diff --git a/packages/gcg.nix b/packages/gcg.nix
index 38911e2..1ba3b8c 100644
--- a/packages/gcg.nix
+++ b/packages/gcg.nix
@@ -25,6 +25,8 @@ in
     in
       builtins.concatStringsSep "." matches;

+    cmakeFlags = [ "-DHMETIS=ON" ];
+
     nativeBuildInputs = with pkgs; [
       cmake
       git # to obtain git commit hash
@@ -54,6 +56,21 @@ in
       for file in ${builtins.concatStringsSep " " debugFiles}; do
         sed -i '1s/^/#define SCIP_DEBUG\n/' $file
       done
+
+      # Fix `zsh` path
+      substituteInPlace \
+        src/gcg/dec_hcgpartition.cpp src/gcg/dec_hrgpartition.cpp src/gcg/dec_hrcgpartition.cpp \
+        --replace-fail "zsh -c" "${pkgs.zsh}/bin/zsh -c"
+
+      # Fix `hmetis` path (it will be installed there later)
+      substituteInPlace \
+        src/hmetis.h.in \
+        --replace-fail "@HMETIS_EXECUTABLE@" "$out/bin/hmetis"
+    '';
+
+    postInstall = ''
+      # Install `hmetis` binary where it was expected
+      install -Dm755 $src/hmetis -t $out/bin
     '';

     enableParallelBuilding = true;

It would be better to have hMetis's code on GitHub and build it from source, but this works for now. I found some old email communication with Dr. George Karypis on Ubuntu's packaging/licensing of parMetis in 2003, but hMetis is MIA for now: https://launchpad.net/ubuntu/focal/+source/parmetis/+copyright

Lichthagel commented 1 month ago

However, GCG's GitLab CI runs tests with hMetis and it downloads a binary from or.rwth-aachen.de/hmetis/hmetis-2.0pre1.tar.gz.

Given the strict licensing I do not know if this should be public. On the other hand, the x86_64 binary is also in the GitHub and the official site is down...

Due to hMetis being unfree I am somewhat unsure if hMetis should be used by default. I've created #2 for now.