Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casadi: init at 3.6.6 #331343

Merged
merged 14 commits into from
Aug 8, 2024
31 changes: 31 additions & 0 deletions pkgs/by-name/bl/blasfeo/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
cmake,
fetchFromGitHub,
lib,
stdenv,
withTarget ? "GENERIC",
}:

stdenv.mkDerivation (finalAttrs: {
pname = "blasfeo";
version = "0.1.3";

src = fetchFromGitHub {
owner = "giaf";
repo = "blasfeo";
rev = finalAttrs.version;
hash = "sha256-e8InqyUMWRdL4CBHUOtrZkuabaTLiNPMNPRCnWzWkQ4=";
};

nativeBuildInputs = [ cmake ];

cmakeFlags = [ "-DTARGET=${withTarget}" ];

meta = {
description = "Basic linear algebra subroutines for embedded optimization";
homepage = "https://github.com/giaf/blasfeo";
changelog = "https://github.com/giaf/blasfeo/blob/${finalAttrs.version}/Changelog.txt";
license = lib.licenses.bsd2;
maintainers = with lib.maintainers; [ nim65s ];
};
})
205 changes: 205 additions & 0 deletions pkgs/by-name/ca/casadi/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
#alpaqa,
blas,
blasfeo,
bonmin,
bzip2,
cbc,
clp,
cmake,
cplex,
fatrop,
fetchFromGitHub,
fetchpatch,
gurobi,
highs,
hpipm,
lib,
ipopt,
lapack,
llvmPackages_17, # llvm/Support/Host.h required by casadi 3.6.5 and not available in llvm 18
mumps,
osqp,
pkg-config,
pythonSupport ? false,
python3Packages,
proxsuite,
stdenv,
sleqp,
suitesparse,
#sundials,
superscs,
spral,
swig,
tinyxml-2,
withUnfree ? false,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "casadi";
version = "3.6.6";

src = fetchFromGitHub {
owner = "casadi";
repo = "casadi";
rev = finalAttrs.version;
hash = "sha256-T4aaBS918NbUEwWkSx0URi0W9uhCB8IFmzRcOR7T8Og=";
};

patches = [
(fetchpatch {
name = "add-FindSPRAL.cmake.patch";
url = "https://github.com/casadi/casadi/pull/3792/commits/28bc1b03e67ae06dea0c8557057020f5651be7ad.patch";
hash = "sha256-t0+RnXoFakmoX93MhN08RWAbCg6Nerh42LicBBgAkRQ=";
})
];

postPatch =
''
# fix case of fatropConfig.cmake & hpipmConfig.cmake
substituteInPlace CMakeLists.txt --replace-fail \
"FATROP HPIPM" \
"fatrop hpipm"

# nix provide lib/clang headers in libclang, not in llvm.
substituteInPlace casadi/interfaces/clang/CMakeLists.txt --replace-fail \
'$'{CLANG_LLVM_LIB_DIR} \
${llvmPackages_17.libclang.lib}/lib

# fix fatrop includes
substituteInPlace casadi/interfaces/fatrop/fatrop_conic_interface.hpp --replace-fail \
"<ocp/" \
"<fatrop/ocp/"

# fix mumps lib name. No idea where this comes from.
substituteInPlace cmake/FindMUMPS.cmake --replace-fail \
"mumps_seq" \
"mumps"

# help casadi find its own libs
substituteInPlace casadi/core/casadi_os.cpp --replace-fail \
"std::vector<std::string> search_paths;" \
"std::vector<std::string> search_paths;
search_paths.push_back(\"$out/lib\");"
''
+ lib.optionalString pythonSupport ''
# fix including Python.h issue
substituteInPlace swig/python/CMakeLists.txt --replace-fail \
"add_library(_casadi MODULE \''${PYTHON_FILE})" \
"add_library(_casadi MODULE \''${PYTHON_FILE})
target_include_directories(_casadi SYSTEM PRIVATE
${python3Packages.python}/include/python3.${python3Packages.python.sourceVersion.minor})"

# I have no clue. without this, it tries to install a non existent file.
# maybe a run without SWIG_IMPORT is required before a run with SWIG_IMPORT.
# but we need SWIG_IMPORT at some point for something else TODO
substituteInPlace swig/python/CMakeLists.txt --replace-fail \
"if (SWIG_IMPORT)" \
"if (NOT SWIG_IMPORT)"
'';

nativeBuildInputs = [
cmake
pkg-config
];

buildInputs =
[
#alpaqa
blas
blasfeo
bzip2
bonmin
cbc
clp
fatrop
highs
hpipm
ipopt
lapack
llvmPackages_17.clang
llvmPackages_17.libclang
llvmPackages_17.llvm
mumps
osqp
proxsuite
sleqp
suitesparse
#sundials
superscs
spral
swig
tinyxml-2
]
++ lib.optionals withUnfree [
cplex
gurobi
]
++ lib.optionals pythonSupport [
python3Packages.numpy
python3Packages.python
];

cmakeFlags = [
(lib.cmakeBool "WITH_PYTHON" pythonSupport)
(lib.cmakeBool "WITH_PYTHON3" pythonSupport)
(lib.cmakeBool "WITH_JSON" false)
(lib.cmakeBool "WITH_INSTALL_INTERNAL_HEADERS" true)
(lib.cmakeBool "INSTALL_INTERNAL_HEADERS" true)
(lib.cmakeBool "ENABLE_EXPORT_ALL" true)
(lib.cmakeBool "SWIG_EXPORT" true)
(lib.cmakeBool "SWIG_IMPORT" false)
(lib.cmakeBool "WITH_OPENMP" true)
(lib.cmakeBool "WITH_THREAD" true)
(lib.cmakeBool "WITH_OPENCL" false)
(lib.cmakeBool "WITH_BUILD_SUNDIALS" true) # ref. https://github.com/casadi/casadi/issues/2125
(lib.cmakeBool "WITH_SUNDIALS" true)
(lib.cmakeBool "WITH_BUILD_CSPARSE" false)
(lib.cmakeBool "WITH_CSPARSE" true)
(lib.cmakeBool "WITH_BLASFEO" true)
(lib.cmakeBool "WITH_HPIPM" true)
(lib.cmakeBool "WITH_FATROP" false) # invalid new-expression of abstract class type 'casadi::CasadiStructuredQP'
(lib.cmakeBool "WITH_BUILD_FATROP" false)
(lib.cmakeBool "WITH_SUPERSCS" false) # packaging too chaotic
(lib.cmakeBool "WITH_BUILD_OSQP" false)
(lib.cmakeBool "WITH_OSQP" true)
(lib.cmakeBool "WITH_PROXQP" true)
(lib.cmakeBool "WITH_BUILD_TINYXML" false)
(lib.cmakeBool "WITH_TINYXML" true)
(lib.cmakeBool "WITH_BUILD_DSDP" true) # not sure where this come from
(lib.cmakeBool "WITH_DSDP" true)
(lib.cmakeBool "WITH_CLANG" true)
(lib.cmakeBool "WITH_LAPACK" true)
(lib.cmakeBool "WITH_QPOASES" true)
(lib.cmakeBool "WITH_BLOCKSQP" true)
(lib.cmakeBool "WITH_SLEQP" true)
(lib.cmakeBool "WITH_IPOPT" true)
(lib.cmakeBool "WITH_KNITRO" withUnfree)
(lib.cmakeBool "WITH_SNOPT" withUnfree)
(lib.cmakeBool "WITH_WORHP" withUnfree)
(lib.cmakeBool "WITH_CPLEX" withUnfree)
(lib.cmakeBool "WITH_GUROBI" withUnfree)
(lib.cmakeBool "WITH_BONMIN" true)
(lib.cmakeBool "WITH_CBC" true)
(lib.cmakeBool "WITH_CLP" true)
(lib.cmakeBool "WITH_MUMPS" true)
(lib.cmakeBool "WITH_SPRAL" true)
(lib.cmakeBool "WITH_HSL" withUnfree)
(lib.cmakeBool "WITH_HIGHS" true)
#(lib.cmakeBool "WITH_ALPAQA" true) # this requires casadi...
];

# I don't know how to pass absolute $out path from cmakeFlags
postConfigure = lib.optionalString pythonSupport ''
cmake -DPYTHON_PREFIX=$out/${python3Packages.python.sitePackages} ..
'';

doCheck = true;

meta = {
description = "CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave";
homepage = "https://github.com/casadi/casadi";
license = lib.licenses.lgpl3Only;
maintainers = with lib.maintainers; [ nim65s ];
};
})
56 changes: 56 additions & 0 deletions pkgs/by-name/fa/fatrop/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
blasfeo,
cmake,
fetchFromGitHub,
lib,
llvmPackages,
python3Packages,
pythonSupport ? false,
stdenv,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "fatrop";
version = "0.0.1";

src = fetchFromGitHub {
owner = "meco-group";
repo = "fatrop";
rev = "v${finalAttrs.version}";
hash = "sha256-c4qYh8RutRsMIx3m0oxXy73fnLTBGVZ1QjFcLEJ413Y=";
};

postPatch = lib.optionalString pythonSupport ''
# avoid submodule
rmdir external/pybind11
ln -s ${python3Packages.pybind11.src} external/pybind11

# install python module
echo "" >> fatropy/CMakeLists.txt
echo "install(DIRECTORY fatropy DESTINATION ${python3Packages.python.sitePackages})" >> fatropy/CMakeLists.txt
echo "install(TARGETS _fatropy DESTINATION ${python3Packages.python.sitePackages}/fatropy)" >> fatropy/CMakeLists.txt
'';

nativeBuildInputs = [ cmake ];
buildInputs =
[ blasfeo ]
++ lib.optionals pythonSupport [ python3Packages.pybind11 ]
++ lib.optionals stdenv.isDarwin [ llvmPackages.openmp ];

cmakeFlags = [
(lib.cmakeBool "BUILD_DOCS" true)
(lib.cmakeBool "ENABLE_MULTITHREADING" true)
(lib.cmakeBool "BUILD_WITH_BLASFEO" false)
(lib.cmakeBool "WITH_PYTHON" pythonSupport)
(lib.cmakeBool "WITH_SPECTOOL" false) # this depends on casadi
];

doCheck = true;

meta = {
description = "nonlinear optimal control problem solver that aims to be fast, support a broad class of optimal control problems and achieve a high numerical robustness";
homepage = "https://github.com/meco-group/fatrop";
license = lib.licenses.lgpl3Only;
maintainers = with lib.maintainers; [ nim65s ];
};
})
39 changes: 39 additions & 0 deletions pkgs/by-name/hp/hpipm/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
blas,
blasfeo,
cmake,
fetchFromGitHub,
lib,
stdenv,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "hpipm";
#version = "0.1.3"; not building, use master instead
version = "0-unstable-2024-07-30";

src = fetchFromGitHub {
owner = "giaf";
repo = "hpipm";
rev = "3ab7d6059d9d7da31ec9ff6a8ca84fd8ec5ab5e2";
hash = "sha256-TRNHjW2/YDfGJHTG9sy2nmHyk6+HlBGIabPm87TETE8=";
};

nativeBuildInputs = [ cmake ];
buildInputs = [
blas
blasfeo
];

cmakeFlags = [
"-DBLASFEO_PATH=${blasfeo}"
] ++ lib.optionals (!stdenv.isx86_64) [ "-DTARGET=GENERIC" ];

meta = {
description = "High-performance interior-point-method QP and QCQP solvers";
homepage = "https://github.com/giaf/hpipm";
changelog = "https://github.com/giaf/hpipm/blob/${finalAttrs.src.rev}/Changelog.txt";
license = lib.licenses.bsd2;
maintainers = with lib.maintainers; [ nim65s ];
};
})
Loading