-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial CRHMC with Cooling Non-SphericalGaussians
- Loading branch information
Showing
9 changed files
with
851 additions
and
2 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
examples/crhmc_cooling_nonspherical_gaussians/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# VolEsti (volume computation and sampling library) | ||
|
||
# Copyright (c) 2012-2024 Vissarion Fisikopoulos | ||
# Copyright (c) 2018-2024 Apostolos Chalkis | ||
# Copyright (c) 2024 Vladimir Necula | ||
|
||
# Contributed and/or modified by Vladimir Necula, as part of Google Summer of | ||
# Code 2024 program. | ||
|
||
# Licensed under GNU LGPL.3, see LICENCE file | ||
|
||
project( VolEsti ) | ||
|
||
|
||
CMAKE_MINIMUM_REQUIRED(VERSION 3.11) | ||
|
||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) | ||
|
||
# Locate Intel MKL root (in case it is enabled) | ||
if (APPLE) | ||
set(MKLROOT /opt/intel/oneapi/mkl/latest) | ||
elseif(UNIX) | ||
#set(MKLROOT /opt/intel/oneapi/mkl/latest) | ||
set(MKLROOT $ENV{HOME}/intel/mkl) | ||
endif() | ||
|
||
if(COMMAND cmake_policy) | ||
cmake_policy(SET CMP0003 NEW) | ||
endif(COMMAND cmake_policy) | ||
|
||
|
||
option(DISABLE_NLP_ORACLES "Disable non-linear oracles (used in collocation)" ON) | ||
option(BUILTIN_EIGEN "Use eigen from ../../external" OFF) | ||
option(USE_MKL "Use MKL library to build eigen" OFF) | ||
|
||
|
||
if(DISABLE_NLP_ORACLES) | ||
add_definitions(-DDISABLE_NLP_ORACLES) | ||
else() | ||
find_library(IFOPT NAMES libifopt_core.so PATHS /usr/local/lib) | ||
find_library(IFOPT_IPOPT NAMES libifopt_ipopt.so PATHS /usr/local/lib) | ||
find_library(GMP NAMES libgmp.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) | ||
find_library(MPSOLVE NAMES libmps.so PATHS /usr/local/lib) | ||
find_library(PTHREAD NAMES libpthread.so PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) | ||
find_library(FFTW3 NAMES libfftw3.so.3 PATHS /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu) | ||
|
||
if (NOT IFOPT) | ||
|
||
message(FATAL_ERROR "This program requires the ifopt library, and will not be compiled.") | ||
|
||
elseif (NOT GMP) | ||
|
||
message(FATAL_ERROR "This program requires the gmp library, and will not be compiled.") | ||
|
||
elseif (NOT MPSOLVE) | ||
|
||
message(FATAL_ERROR "This program requires the mpsolve library, and will not be compiled.") | ||
|
||
elseif (NOT FFTW3) | ||
|
||
message(FATAL_ERROR "This program requires the fftw3 library, and will not be compiled.") | ||
|
||
else() | ||
message(STATUS "Library ifopt found: ${IFOPT}") | ||
message(STATUS "Library gmp found: ${GMP}") | ||
message(STATUS "Library mpsolve found: ${MPSOLVE}") | ||
message(STATUS "Library fftw3 found:" ${FFTW3}) | ||
|
||
endif(NOT IFOPT) | ||
|
||
endif(DISABLE_NLP_ORACLES) | ||
|
||
include("../../external/cmake-files/Eigen.cmake") | ||
GetEigen() | ||
|
||
include("../../external/cmake-files/Boost.cmake") | ||
GetBoost() | ||
|
||
include("../../external/cmake-files/LPSolve.cmake") | ||
GetLPSolve() | ||
|
||
include("../../external/cmake-files/QD.cmake") | ||
GetQD() | ||
|
||
# Find lpsolve library | ||
find_library(LP_SOLVE NAMES liblpsolve55.so PATHS /usr/lib/lp_solve) | ||
|
||
if (NOT LP_SOLVE) | ||
message(FATAL_ERROR "This program requires the lp_solve library, and will not be compiled.") | ||
else () | ||
message(STATUS "Library lp_solve found: ${LP_SOLVE}") | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON") | ||
|
||
if (USE_MKL) | ||
find_library(BLAS NAMES libblas.so libblas.dylib PATHS /usr/local/Cellar/lapack/3.9.1_1/lib /usr/lib/x86_64-linux-gnu /usr/lib/i386-linux-gnu /usr/local/Cellar/openblas/0.3.15_1/lib /usr/lib) | ||
find_library(GFORTRAN NAME libgfortran.dylib PATHS /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10) | ||
find_library(LAPACK NAME liblapack.dylib PATHS /usr/lib) | ||
find_library(OPENMP NAME libiomp5.dylib PATHS /opt/intel/oneapi/compiler/2021.1.1/mac/compiler/lib) | ||
|
||
include_directories (BEFORE ${MKLROOT}/include) | ||
set(PROJECT_LIBS ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES}) | ||
set(MKL_LINK "-L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl") | ||
add_definitions(-DEIGEN_USE_MKL_ALL) | ||
else() | ||
set(MKL_LINK "") | ||
endif(USE_MKL) | ||
|
||
include_directories (BEFORE ../../external) | ||
include_directories (BEFORE ../../external/minimum_ellipsoid) | ||
include_directories (BEFORE ../../include/) | ||
|
||
# for Eigen | ||
if (${CMAKE_VERSION} VERSION_LESS "3.12.0") | ||
add_compile_options(-D "EIGEN_NO_DEBUG") | ||
else () | ||
add_compile_definitions("EIGEN_NO_DEBUG") | ||
endif () | ||
|
||
|
||
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard | ||
set(ADDITIONAL_FLAGS "-march=native -DSIMD_LEN=0 -DTIME_KEEPING") | ||
add_definitions(${CMAKE_CXX_FLAGS} "-O3 -DTIME_KEEPING" ${ADDITIONAL_FLAGS}) # optimization of the compiler | ||
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgsl") | ||
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lm") | ||
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl") | ||
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR") | ||
|
||
add_executable(volume_example volume_example.cpp) | ||
target_link_libraries(volume_example QD_LIB ${MKL_LINK} ${LP_SOLVE}) | ||
|
||
endif() |
69 changes: 69 additions & 0 deletions
69
examples/crhmc_cooling_nonspherical_gaussians/volume_example.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// VolEsti (volume computation and sampling library) | ||
|
||
// Copyright (c) 2012-2024 Vissarion Fisikopoulos | ||
// Copyright (c) 2018-2024 Apostolos Chalkis | ||
// Copyright (c) 2024 Vladimir Necula | ||
|
||
// Contributed and/or modified by Vladimir Necula, as part of Google Summer of | ||
// Code 2024 program. | ||
|
||
// Licensed under GNU LGPL.3, see LICENCE file | ||
|
||
#include "generators/known_polytope_generators.h" | ||
#include "generators/h_polytopes_generator.h" | ||
#include "random_walks/random_walks.hpp" | ||
#include "volume/volume_cooling_nonspherical_gaussians_crhmc.hpp" | ||
#include "volume/volume_cooling_gaussians.hpp" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <Eigen/Dense> | ||
#include <vector> | ||
#include "misc/misc.h" | ||
|
||
const unsigned int FIXED_SEED = 42; | ||
|
||
typedef double NT; | ||
typedef Cartesian<NT> Kernel; | ||
typedef typename Kernel::Point Point; | ||
typedef BoostRandomNumberGenerator<boost::mt11213b, NT, FIXED_SEED> RandomNumberGenerator; | ||
typedef HPolytope<Point> HPOLYTOPE; | ||
|
||
NT nonspherical_crhmc_volume(HPOLYTOPE& polytope) { | ||
int walk_len = 10; | ||
NT e = 0.1; | ||
RandomNumberGenerator rng; | ||
// NT volume = volume_cooling_gaussians<GaussianBallWalk, RandomNumberGenerator>(polytope, e, walk_len); | ||
NT volume = non_spherical_crhmc_volume_cooling_gaussians<HPOLYTOPE, RandomNumberGenerator>(polytope, rng, e, walk_len); | ||
return volume; | ||
} | ||
|
||
NT spherical_gaussians_volume(HPOLYTOPE& polytope) { | ||
int walk_len = 10; | ||
NT e = 0.1; | ||
RandomNumberGenerator rng; | ||
NT volume = volume_cooling_gaussians<GaussianCDHRWalk, RandomNumberGenerator>(polytope, e, walk_len); | ||
return volume; | ||
} | ||
|
||
int main() { | ||
|
||
HPOLYTOPE cube3 = generate_cube<HPOLYTOPE>(3, false); | ||
std::cout << "Cube3 \n"; | ||
std::cout << "Calculated Volume With Gaussian CDHR: " << spherical_gaussians_volume(cube3) << "\n"; | ||
std::cout << "Calculated Volume With CRHMC: " << nonspherical_crhmc_volume(cube3) << "\n"; | ||
std::cout << "Expected Volume: " << std::pow(2, 3) << "\n\n"; | ||
|
||
HPOLYTOPE cube4 = generate_cube<HPOLYTOPE>(4, false); | ||
std::cout << "Cube4 \n"; | ||
std::cout << "Calculated Volume With Gaussian CDHR: " << spherical_gaussians_volume(cube4) << "\n"; | ||
std::cout << "Calculated Volume With CRHMC: " << nonspherical_crhmc_volume(cube4) << "\n"; | ||
std::cout << "Expected Volume: " << std::pow(2, 4) << "\n\n"; | ||
|
||
HPOLYTOPE skinnycube3 = generate_skinny_cube<HPOLYTOPE>(3, false); | ||
std::cout << "SkinnyCube3 \n"; | ||
std::cout << "Calculated Volume With Gaussian CDHR: " << spherical_gaussians_volume(skinnycube3) << "\n"; | ||
std::cout << "Calculated Volume With CRHMC: " << nonspherical_crhmc_volume(skinnycube3) << "\n"; | ||
std::cout << "Expected Volume: " << 200 * std::pow(2, 2) << "\n\n"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,8 @@ struct ImplicitMidpointODESolver { | |
stream << '\n'; | ||
} | ||
} | ||
|
||
NT get_eta() const { return eta; } | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.