Skip to content

Commit

Permalink
Merge remote-tracking branch 'polysolve/main' into slim
Browse files Browse the repository at this point in the history
  • Loading branch information
Huangzizhou committed Aug 20, 2024
2 parents e7e41ad + 0cd21ba commit c2921f1
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 115 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
name: Linux
steps:
- name: Checkout repository
uses: actions/checkout@v1
uses: actions/checkout@v4.1.6
with:
fetch-depth: 10

Expand All @@ -53,7 +53,7 @@ jobs:
- name: Cache Build
id: cache-build
uses: actions/cache@v2
uses: actions/cache@v4.0.2
with:
path: ${{ env.CACHE_PATH }}
key: ${{ runner.os }}-${{ matrix.config }}-cache-${{ github.sha }}
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
config: [Debug, Release]
steps:
- name: Checkout repository
uses: actions/checkout@v1
uses: actions/checkout@v4.1.6
with:
fetch-depth: 10

Expand All @@ -105,7 +105,7 @@ jobs:
- name: Cache build
id: cache-build
uses: actions/cache@v2
uses: actions/cache@v4.0.2
with:
path: ${{ env.appdata }}\Mozilla\sccache
key: ${{ runner.os }}-${{ matrix.config }}-cache-${{ github.sha }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
name: Linux
steps:
- name: Checkout repository
uses: actions/checkout@v1
uses: actions/checkout@v4.1.6
with:
fetch-depth: 10

Expand All @@ -41,7 +41,7 @@ jobs:
- name: Cache Build
id: cache-build
uses: actions/cache@v3
uses: actions/cache@v4.0.2
with:
path: ${{ env.CACHE_PATH }}
key: ${{ runner.os }}-Release-${{ matrix.threading }}-cache-${{ github.sha }}
Expand Down Expand Up @@ -72,7 +72,9 @@ jobs:
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*tests/*.cpp' '*tests/*.h' --output-file coverage.info
- name: Upload Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: polysolve # optional
files: coverage.info
Expand Down
2 changes: 1 addition & 1 deletion cmake/recipes/jse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ endif()
message(STATUS "Third-party: creating target 'jse::jse'")

include(CPM)
CPMAddPackage("gh:geometryprocessing/json-spec-engine#49f1a30f8c2912814916ec3d6108a649b23cb243")
CPMAddPackage("gh:geometryprocessing/json-spec-engine#11d028ebf54c3665e1a7c25d8ac622a8cb851223")
86 changes: 27 additions & 59 deletions cmake/recipes/mkl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ set_property(CACHE MKL_LINKING PROPERTY STRINGS ${MKL_LINKINK_CHOICES})
message(STATUS "MKL linking strategy: ${MKL_LINKING}")

# MKL version
set(MKL_VERSION "2021.3.0" CACHE STRING "MKL version to use (2020.4 or 2021.3.0)")
set(MKL_VERSION_CHOICES 2020.4 2021.3.0)
set(MKL_VERSION "2022.2.1" CACHE STRING "MKL version to use (2022.2.1)")
set(MKL_VERSION_CHOICES 2022.2.1)
set_property(CACHE MKL_VERSION PROPERTY STRINGS ${MKL_VERSION_CHOICES})
message(STATUS "MKL version: ${MKL_VERSION}")

Expand Down Expand Up @@ -78,66 +78,34 @@ elseif(UNIX)
set(MKL_PLATFORM linux-64)
endif()

if(MKL_VERSION VERSION_EQUAL 2020.4)
# To compute the md5 checksums for each lib, use the following bash script (replace the target version number):
# for f in mkl mkl-include mkl-static mkl-devel; do for os in linux osx win; do cat <(printf "$f-$os-64-md5") <(conda search --override-channel --channel intel $f=2020.4 --platform $os-64 -i | grep md5 | cut -d : -f 2); done; done
set(mkl-linux-64-md5 f85891f97a04c7b2fbf619d1b903d7f5)
set(mkl-osx-64-md5 735d7f93c7fbcffe658f1ccf67418cb3)
set(mkl-win-64-md5 37ade09cace5cd73053b16574a3ee3c3)
set(mkl-include-linux-64-md5 8b2bf0e42bd95dd700d9877add1ca6de)
set(mkl-include-osx-64-md5 26043328553952cdb064c5aab8b50c78)
set(mkl-include-win-64-md5 87e9a73a6e6757a8ed0dbc87d50d7f60)
set(mkl-static-linux-64-md5 9f589a1508fb083c3e73427db459ca4c)
set(mkl-static-osx-64-md5 2f9e1b8b6d6b0903e81a573084e4494f)
set(mkl-static-win-64-md5 5ae780c06edd0be62966c6d8ab47d5fb)
set(mkl-devel-linux-64-md5 b571698ef237c0e61abe15b7d300f157)
set(mkl-devel-osx-64-md5 ee58da0463676d910eeab9aec0470f0e)
set(mkl-devel-win-64-md5 8a7736b81b9bc2d5c044b88d6ac8af6e)

# To compute file names, we use the following bash script:
# for f in mkl mkl-include mkl-static mkl-devel; do for os in linux osx win; do cat <(printf "$f-$os-64-file") <(conda search --override-channel --channel intel $f=2020.4 --platform $os-64 -i | grep file | cut -d : -f 2); done; done
set(mkl-linux-64-file mkl-2020.4-intel_304.tar.bz2)
set(mkl-osx-64-file mkl-2020.4-intel_301.tar.bz2)
set(mkl-win-64-file mkl-2020.4-intel_311.tar.bz2)
set(mkl-include-linux-64-file mkl-include-2020.4-intel_304.tar.bz2)
set(mkl-include-osx-64-file mkl-include-2020.4-intel_301.tar.bz2)
set(mkl-include-win-64-file mkl-include-2020.4-intel_311.tar.bz2)
set(mkl-static-linux-64-file mkl-static-2020.4-intel_304.tar.bz2)
set(mkl-static-osx-64-file mkl-static-2020.4-intel_301.tar.bz2)
set(mkl-static-win-64-file mkl-static-2020.4-intel_311.tar.bz2)
set(mkl-devel-linux-64-file mkl-devel-2020.4-intel_304.tar.bz2)
set(mkl-devel-osx-64-file mkl-devel-2020.4-intel_301.tar.bz2)
set(mkl-devel-win-64-file mkl-devel-2020.4-intel_311.tar.bz2)
elseif(MKL_VERSION VERSION_EQUAL 2021.3.0)
if(MKL_VERSION VERSION_EQUAL 2022.2.1)
# To compute the md5 checksums for each lib, use the following bash script (replace the target version number):
# for f in mkl mkl-include mkl-static mkl-devel; do for os in linux osx win; do cat <(printf "$f-$os-64-md5") <(conda search --override-channel --channel intel $f=2021.3.0 --platform $os-64 -i | grep md5 | cut -d : -f 2); done; done
set(mkl-linux-64-md5 2501643729c00b24fddb9530b339aea7)
set(mkl-osx-64-md5 d6129ae9dfba58671667a65c160d0776)
set(mkl-win-64-md5 264213ea4c5cb6b6d81ea97f59e757ab)
set(mkl-include-linux-64-md5 70b4f9a53401a3d11ce27d7ddb0e2511)
set(mkl-include-osx-64-md5 6da50c06992b78c4127a1881d39c1804)
set(mkl-include-win-64-md5 28d785eb22d28512d4e40e5890a817dc)
set(mkl-static-linux-64-md5 1469ad60a34269d4d0c5666bc131b82a)
set(mkl-static-osx-64-md5 4a099581ba95cc50bb538598b26389e4)
set(mkl-static-win-64-md5 69aef10428893314bc486e81397e1b25)
set(mkl-devel-linux-64-md5 2432ad963e3f7e4619ffc7f896178fbe)
set(mkl-devel-osx-64-md5 61b84a60715a3855a2097a3b619a00c8)
set(mkl-devel-win-64-md5 6128dee67d2b20ff534cf54757f623e0)
# set(mkl-linux-64-md5 2501643729c00b24fddb9530b339aea7)
# set(mkl-win-64-md5 264213ea4c5cb6b6d81ea97f59e757ab)

# set(mkl-include-linux-64-md5 70b4f9a53401a3d11ce27d7ddb0e2511)
# set(mkl-include-win-64-md5 28d785eb22d28512d4e40e5890a817dc)

# set(mkl-static-linux-64-md5 1469ad60a34269d4d0c5666bc131b82a)
# set(mkl-static-win-64-md5 69aef10428893314bc486e81397e1b25)

# set(mkl-devel-linux-64-md5 2432ad963e3f7e4619ffc7f896178fbe)
# set(mkl-devel-win-64-md5 6128dee67d2b20ff534cf54757f623e0)

# To compute file names, we use the following bash script:
# for f in mkl mkl-include mkl-static mkl-devel; do for os in linux osx win; do cat <(printf "$f-$os-64-file") <(conda search --override-channel --channel intel $f=2021.3.0 --platform $os-64 -i | grep file | cut -d : -f 2); done; done
set(mkl-linux-64-file mkl-2021.3.0-intel_520.tar.bz2)
set(mkl-osx-64-file mkl-2021.3.0-intel_517.tar.bz2)
set(mkl-win-64-file mkl-2021.3.0-intel_524.tar.bz2)
set(mkl-include-linux-64-file mkl-include-2021.3.0-intel_520.tar.bz2)
set(mkl-include-osx-64-file mkl-include-2021.3.0-intel_517.tar.bz2)
set(mkl-include-win-64-file mkl-include-2021.3.0-intel_524.tar.bz2)
set(mkl-static-linux-64-file mkl-static-2021.3.0-intel_520.tar.bz2)
set(mkl-static-osx-64-file mkl-static-2021.3.0-intel_517.tar.bz2)
set(mkl-static-win-64-file mkl-static-2021.3.0-intel_524.tar.bz2)
set(mkl-devel-linux-64-file mkl-devel-2021.3.0-intel_520.tar.bz2)
set(mkl-devel-osx-64-file mkl-devel-2021.3.0-intel_517.tar.bz2)
set(mkl-devel-win-64-file mkl-devel-2021.3.0-intel_524.tar.bz2)
set(mkl-linux-64-file mkl-2022.2.1-h6508926_16999.tar.bz2)
set(mkl-win-64-file mkl-2022.2.1-h4060db9_19760.tar.bz2)

set(mkl-include-linux-64-file mkl-include-2022.2.1-ha957f24_16999.tar.bz2)
set(mkl-include-win-64-file mkl-include-2022.2.1-h66d3029_19760.tar.bz2)

set(mkl-static-linux-64-file mkl-static-2022.2.1-h6508926_16999.tar.bz2)
set(mkl-static-win-64-file mkl-static-2022.2.1-h4060db9_19760.tar.bz2)

set(mkl-devel-linux-64-file mkl-devel-2022.2.1-ha957f24_16999.tar.bz2)
set(mkl-devel-win-64-file mkl-devel-2022.2.1-h66d3029_19760.tar.bz2)
endif()

# On Windows, `mkl-devel` contains the .lib files (needed at link time),
Expand All @@ -153,8 +121,8 @@ include(CPM)
foreach(name IN ITEMS ${MKL_REMOTES})
CPMAddPackage(
NAME ${name}
URL https://anaconda.org/intel/${name}/${MKL_VERSION}/download/${MKL_PLATFORM}/${${name}-${MKL_PLATFORM}-file}
URL_MD5 ${${name}-${MKL_PLATFORM}-md5}
URL https://anaconda.org/conda-forge/${name}/${MKL_VERSION}/download/${MKL_PLATFORM}/${${name}-${MKL_PLATFORM}-file}
# URL_MD5 ${${name}-${MKL_PLATFORM}-md5}
)
endforeach()

Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage:
target: 75%
threshold: 5%
only_pulls: true
ignore:
- "tests" # ignore folders and all its contents
4 changes: 4 additions & 0 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,15 @@ namespace polysolve::linear
#ifdef POLYSOLVE_WITH_PARDISO
return "Pardiso";
#else
#ifdef POLYSOLVE_WITH_ACCELERATE
return "Eigen::AccelerateLDLT";
#else
#ifdef POLYSOLVE_WITH_HYPRE
return "Hypre";
#else
return "Eigen::BiCGSTAB";
#endif
#endif
#endif
}

Expand Down
65 changes: 30 additions & 35 deletions src/polysolve/linear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ namespace polysolve::linear
/// Selects the correct solver based on params using the fallback or the list of solvers if necessary
static void select_valid_solver(json &params, spdlog::logger &logger);

// Static constructor
//
// @param[in] params Parameter of the solver, including name and preconditioner
// @param[in] logger Logger used for error
// @param[in] strict_validation strict validation of the input paraams
// @param[out] a pointer to a linear solver
/// @brief Static constructor
///
/// @param[in] params Parameter of the solver, including name and preconditioner
/// @param[in] logger Logger used for error
/// @param[in] strict_validation strict validation of the input paraams
/// @return a pointer to a linear solver
//
static std::unique_ptr<Solver> create(const json &params,
spdlog::logger &logger,
const bool strict_validation = true);

// Static constructor
//
// @param[in] solver Solver type
// @param[in] precond Preconditioner for iterative solvers
//
/// @brief Static constructor
///
/// @param[in] solver Solver type
/// @param[in] precond Preconditioner for iterative solvers
///
static std::unique_ptr<Solver> create(const std::string &solver, const std::string &precond);

// List available solvers
Expand All @@ -86,50 +86,45 @@ namespace polysolve::linear
// Public interface //
//////////////////////

// Set solver parameters
/// Set solver parameters
virtual void set_parameters(const json &params) {}

// Get info on the last solve step
/// Get info on the last solve step
virtual void get_info(json &params) const {};

// Analyze sparsity pattern
/// Analyze sparsity pattern
virtual void analyze_pattern(const StiffnessMatrix &A, const int precond_num) {}

// Factorize system matrix
/// Factorize system matrix
virtual void factorize(const StiffnessMatrix &A) {}

// Analyze sparsity pattern of a dense matrix
/// Analyze sparsity pattern of a dense matrix
virtual void analyze_pattern_dense(const Eigen::MatrixXd &A, const int precond_num) {}

// Factorize system matrix of a dense matrix
/// Factorize system matrix of a dense matrix
virtual void factorize_dense(const Eigen::MatrixXd &A) {}

// If solver uses dense matrices
/// If solver uses dense matrices
virtual bool is_dense() const { return false; }

// Set block size for multigrid solvers
/// Set block size for multigrid solvers
virtual void set_block_size(int block_size) {}

// If the problem is nullspace for multigrid solvers
/// If the problem is nullspace for multigrid solvers
virtual void set_is_nullspace(const VectorXd &x) {}

//
// @brief { Solve the linear system Ax = b }
//
// @param[in] b { Right-hand side. }
// @param[in,out] x { Unknown to compute. When using an iterative
// solver, the input unknown vector is used as an
// initial guess, and must thus be properly allocated
// and initialized. }
//
///
/// @brief { Solve the linear system Ax = b }
///
/// @param[in] b { Right-hand side. }
/// @param[in,out] x { Unknown to compute. When using an iterative
/// solver, the input unknown vector is used as an
/// initial guess, and must thus be properly allocated
/// and initialized. }
///
virtual void solve(const Ref<const VectorXd> b, Ref<VectorXd> x) = 0;

public:
///////////
// Debug //
///////////

// Name of the solver type (for debugging purposes)
/// @brief Name of the solver type (for debugging purposes)
virtual std::string name() const { return ""; }
};

Expand Down
1 change: 1 addition & 0 deletions src/polysolve/nonlinear/Problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace polysolve::nonlinear
{
/// @brief Class defining optimization problem to be solved. To be defined by user code
class Problem
{
public:
Expand Down
24 changes: 21 additions & 3 deletions src/polysolve/nonlinear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace polysolve::nonlinear
spdlog::logger &logger,
const bool strict_validation = true);

// List available solvers
/// @brief List available solvers
static std::vector<std::string> available_solvers();

public:
Expand Down Expand Up @@ -82,10 +82,17 @@ namespace polysolve::nonlinear
/// @brief If true the solver will not throw an error if the maximum number of iterations is reached
bool allow_out_of_iterations = false;


/// @brief Get the line search object
const std::shared_ptr<line_search::LineSearch> &line_search() const { return m_line_search; };

protected:
/// @brief Compute direction in which the argument should be updated
/// @param objFunc Problem to be minimized
/// @param x Current input (n x 1)
/// @param grad Gradient at current step (n x 1)
/// @param[out] direction Current update direction (n x 1)
/// @return True if update direction was found, False otherwises
virtual bool compute_update_direction(
Problem &objFunc,
const TVector &x,
Expand Down Expand Up @@ -116,6 +123,10 @@ namespace polysolve::nonlinear

FiniteDiffStrategy gradient_fd_strategy = FiniteDiffStrategy::NONE;
double gradient_fd_eps = 1e-7;
/// @brief Check gradient versus finite difference results
/// @param objFunc Problem defining relevant objective function
/// @param x Current input (n x 1)
/// @param grad Current gradient (n x 1)
virtual void verify_gradient(Problem &objFunc, const TVector &x, const TVector &grad) final;

private:
Expand All @@ -128,8 +139,9 @@ namespace polysolve::nonlinear
// ====================================================================
// Solver state
// ====================================================================

// Reset the solver at the start of a minimization

/// @brief Reset the solver at the start of a minimization
/// @param ndof number of degrees of freedom
void reset(const int ndof);

std::string descent_strategy_name() const { return m_strategies[m_descent_strategy]->name(); };
Expand All @@ -143,8 +155,14 @@ namespace polysolve::nonlinear
// Solver info
// ====================================================================

/// @brief Update solver info JSON object
/// @param energy
void update_solver_info(const double energy);

/// @brief Reset timing members to 0
void reset_times();

/// @brief Log time taken in different phases of the solve
void log_times() const;

json solver_info;
Expand Down
Loading

0 comments on commit c2921f1

Please sign in to comment.