Skip to content

Commit

Permalink
Merge pull request #265 from vissarion/feature/ci_examples
Browse files Browse the repository at this point in the history
Enable github actions to build examples
  • Loading branch information
vissarion authored Mar 3, 2023
2 parents 9d495d6 + 2b876b2 commit ac68063
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake-clang.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################################################
# GitHub Actions Workflow for volesti to build tests with GCC
# GitHub Actions Workflow for volesti to build tests with Clang
#
# Copyright (c) 2020-2022 Vissarion Fisikopoulos
#
Expand Down Expand Up @@ -36,4 +36,4 @@ jobs:
cd build;
cmake -D CMAKE_CXX_COMPILER=${{ matrix.config.compiler }} -D CMAKE_CXX_FLAGS=-fsanitize=memory -D CMAKE_CXX_FLAGS=-fsanitize=undefined -D CMAKE_CXX_FLAGS=-g -D DISABLE_NLP_ORACLES=ON -D USE_MKL=OFF ../test;
make;
ctest --verbose;
ctest --verbose;
40 changes: 40 additions & 0 deletions .github/workflows/cmake-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
##############################################################################
# GitHub Actions Workflow for volesti to build tests with GCC
#
# Copyright (c) 2020-2022 Vissarion Fisikopoulos
#
# Licensed under GNU LGPL.3, see LICENCE file
##############################################################################
name: cmake-examples

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.os }} - ${{ matrix.config.compiler }}
strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-22.04, compiler_pkg: clang-11, compiler: clang++-11}
- {os: ubuntu-22.04, compiler_pkg: g++-11, compiler: g++-11}
runs-on: ${{ matrix.config.os }}
steps:
- uses: actions/checkout@v1
- run: sudo apt-get update || true;
sudo apt-get install ${{ matrix.config.compiler_pkg }} lp-solve libomp-dev libopenblas-dev libarpack2-dev;
- name: Build examples
run: |
cd examples
for dir in */; do
if [ "$dir" != "EnvelopeProblemSOS/" ] && [ "$dir" != "python_utilities/" ]; then
echo
echo "Building examples in $dir ....................."
cd "$dir"
mkdir build && cd build
cmake -DCMAKE_CXX_COMPILER=${{ matrix.config.compiler }} -DUSE_MKL=OFF ..
make
cd ../..
fi
done
2 changes: 1 addition & 1 deletion examples/hpolytope-volume/hpolytopeVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef typename Kernel::Point Point;
typedef BoostRandomNumberGenerator<boost::mt19937, NT, 3> RNGType;
typedef HPolytope <Point> HPOLYTOPE;

void calculateVolumes(const HPOLYTOPE &HP) {
void calculateVolumes(HPOLYTOPE &HP) {
// Setup parameters for calculating volume
int walk_len = 10 + HP.dimension()/10;
NT e=0.1;
Expand Down
2 changes: 1 addition & 1 deletion examples/mmcs_method/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ else ()
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR")
#add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas")
#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" )

find_package(OpenMP REQUIRED)

add_executable (skinny_cube_10_dim skinny_cube_10_dim.cpp)
Expand Down
6 changes: 3 additions & 3 deletions examples/multithread_sampling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ else ()
endif ()


add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard
#add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # 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_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-lgslcblas")
#add_definitions( "-O3 -lgsl -lm -ldl -lgslcblas" )

find_package(OpenMP REQUIRED)

add_executable (sampling_multithread_walks sampling_multithread_walks.cpp)

TARGET_LINK_LIBRARIES(sampling_multithread_walks ${LP_SOLVE} OpenMP::OpenMP_CXX)


Expand Down
11 changes: 5 additions & 6 deletions examples/multithread_sampling/sampling_multithread_walks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ MT get_uniform_samples(Polytope &P,
std::list<Point> randPoints;

typedef RandomPointGeneratorMultiThread <walk> _RandomPointGeneratorMultiThread;

_RandomPointGeneratorMultiThread::apply(P, p, N, walk_len, num_threads, randPoints,
push_back_policy, rng);

unsigned int d = P.dimension();

MT samples(d, N);
unsigned int jj = 0;

Expand Down Expand Up @@ -92,7 +92,7 @@ MT get_gaussian_samples(Polytope &P,
std::list<Point> randPoints;

typedef GaussianPointGeneratorMultiThread <walk> _GaussianPointGeneratorMultiThread;

_GaussianPointGeneratorMultiThread::apply(P, p, a_i, N, walk_len, num_threads, randPoints,
push_back_policy, rng);

Expand All @@ -118,11 +118,10 @@ void test_uniform_random_walk(std::string random_walk, unsigned int const& num_t
typedef Eigen::Matrix<NT,Eigen::Dynamic,Eigen::Dynamic> MT;
typedef Eigen::Matrix<NT,Eigen::Dynamic,1> VT;
typedef BoostRandomNumberGenerator<boost::mt19937, NT, 3> RNGType;
Hpolytope P;
unsigned int d = 10, walk_len = 5, N = 5000;

std::cout << "--- Sampling with " + random_walk + " walk from H-cube10" << std::endl;
P = generate_cube<Hpolytope>(d, false);
Hpolytope P = generate_cube<Hpolytope>(d, false);
RNGType rng(P.dimension());

MT samples = get_uniform_samples<MT, WalkType, Point>(P, rng, walk_len, N, num_threads);
Expand Down Expand Up @@ -155,7 +154,7 @@ void test_gaussian_random_walk(std::string random_walk, unsigned int const& num_


int main() {

unsigned int num_threads = 2;

test_uniform_random_walk<double, BRDHRWalk_multithread>("BRDHR", num_threads);
Expand Down
9 changes: 5 additions & 4 deletions examples/optimization_spectrahedra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ IF (OPENBLAS_LIB)
IF (GFORTRAN_LIB)
message( STATUS "GFORTRAN_LIB found: ${GFORTRAN_LIB}" )

add_executable (boltzmann_hmc_walk boltzmann_hmc_walk.cpp)
TARGET_LINK_LIBRARIES(boltzmann_hmc_walk ${ARPACK_LIB} ${LAPACK_LIBRARIES} ${GFORTRAN_LIB})
# These are not compiling, see issue https://github.com/GeomScale/volesti/issues/264
#add_executable (boltzmann_hmc_walk boltzmann_hmc_walk.cpp)
#TARGET_LINK_LIBRARIES(boltzmann_hmc_walk ${ARPACK_LIB} ${LAPACK_LIBRARIES} ${GFORTRAN_LIB})

add_executable (solve_sdp solve_sdp.cpp)
TARGET_LINK_LIBRARIES(solve_sdp ${GFORTRAN_LIB} ${LAPACK_LIBRARIES} ${ARPACK_LIB})
#add_executable (solve_sdp solve_sdp.cpp)
#TARGET_LINK_LIBRARIES(solve_sdp ${GFORTRAN_LIB} ${LAPACK_LIBRARIES} ${ARPACK_LIB})

ELSE()
MESSAGE(STATUS "gfortran is required but it could not be found")
Expand Down
6 changes: 3 additions & 3 deletions examples/sampling-hpolytope-with-billiard-walks/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void write_to_file(std::string filename, std::vector<Point> const& randPoints) {
}


void sample_using_uniform_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
void sample_using_uniform_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
std::string filename = "uniform_billiard_walk.txt";
typedef RandomPointGenerator<BilliardWalkType> Generator;

Expand All @@ -49,7 +49,7 @@ void sample_using_uniform_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsig
}


void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
std::string filename = "uniform_accelerated_billiard_walk.txt";
typedef RandomPointGenerator<AcceleratedBilliardWalkType> Generator;

Expand All @@ -61,7 +61,7 @@ void sample_using_uniform_accelerated_billiard_walk(HPOLYTOPE const& HP, RNGType
}


void sample_using_gaussian_billiard_walk(HPOLYTOPE const& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
void sample_using_gaussian_billiard_walk(HPOLYTOPE& HP, RNGType& rng, unsigned int walk_len, unsigned int num_points) {
std::string filename = "gaussian_billiard_walk.txt";
typedef MultivariateGaussianRandomPointGenerator<GaussianAcceleratedWalkType> Generator;

Expand Down
4 changes: 2 additions & 2 deletions examples/vpolytope-volume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ else ()
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-ldl")
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR")

add_executable (vpolytopeVolume vpolytopeVolume.cpp)
TARGET_LINK_LIBRARIES(vpolytopeVolume ${LP_SOLVE})
add_executable (vpolytopevolume vpolytopevolume.cpp)
TARGET_LINK_LIBRARIES(vpolytopevolume ${LP_SOLVE})

endif()
2 changes: 1 addition & 1 deletion examples/vpolytope-volume/vpolytopevolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef typename Kernel::Point Point;
typedef BoostRandomNumberGenerator<boost::mt19937, NT, 3> RNGType;
typedef VPolytope <Point> VPOLYTOPE;

void calculateVolumes(const VPOLYTOPE &VP) {
void calculateVolumes(VPOLYTOPE &VP) {
// Setup parameters for calculating volume
int walk_len = 10 + VP.dimension()/10;
NT e=0.1;
Expand Down
2 changes: 1 addition & 1 deletion include/convex_bodies/ballintersectconvex.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BallIntersectPolytope {

BallIntersectPolytope() {}

BallIntersectPolytope(Polytope const& PP, CBall &BB) : P(PP), B(BB) {};
BallIntersectPolytope(Polytope& PP, CBall &BB) : P(PP), B(BB) {};

Polytope first() const { return P; }
CBall second() const { return B; }
Expand Down
2 changes: 1 addition & 1 deletion include/random_walks/boundary_cdhr_walk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct BCDHRWalk
typedef typename Point::FT NT;

template <typename GenericPolytope>
Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng)
Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng)
{
initialize(P, p, rng);
}
Expand Down
2 changes: 1 addition & 1 deletion include/random_walks/boundary_rdhr_walk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct BRDHRWalk
typedef typename Point::FT NT;

template <typename GenericPolytope>
Walk(GenericPolytope const& P, Point const& p, RandomNumberGenerator& rng)
Walk(GenericPolytope& P, Point const& p, RandomNumberGenerator& rng)
{
initialize(P, p, rng);
}
Expand Down
4 changes: 2 additions & 2 deletions include/random_walks/compute_diameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ template <typename Point>
struct compute_diameter<OrderPolytope<Point>>
{
template <typename NT>
static NT compute(OrderPolytope<Point> const& P)
static NT compute(OrderPolytope<Point>& P)
{
return std::sqrt(NT(P.dimension()));
}
Expand All @@ -215,7 +215,7 @@ template <typename Point>
struct compute_diameter<BallIntersectPolytope<OrderPolytope<Point>, Ellipsoid<Point> > >
{
template <typename NT>
static NT compute(BallIntersectPolytope<OrderPolytope<Point>, Ellipsoid<Point>> const& P)
static NT compute(BallIntersectPolytope<OrderPolytope<Point>, Ellipsoid<Point>>& P)
{
NT polytope_diameter = std::sqrt(NT(P.dimension()));
return std::min(polytope_diameter, (NT(2) * P.radius()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct Walk
<
typename GenericPolytope
>
inline bool apply(GenericPolytope const& P,
inline bool apply(GenericPolytope& P,
Point& p, // a point to start
unsigned int const& walk_length,
RandomNumberGenerator &rng)
Expand All @@ -104,7 +104,7 @@ struct Walk
}
T = rng.sample_urdist() * _Len;
_v = GetDirection<Point>::apply(n, rng, false);

it = 0;
while (it < _rho)
{
Expand All @@ -122,7 +122,7 @@ struct Walk
P.compute_reflection(_v, _p, pbpair.second);
it++;
}

} while (P.is_in(_p, INSIDE_BODY_TOLLERANCE) == 0);
if (it == _rho) {
_p = p0;
Expand All @@ -137,7 +137,7 @@ struct Walk
<
typename GenericPolytope
>
inline void get_starting_point(GenericPolytope const& P,
inline void get_starting_point(GenericPolytope& P,
Point const& center,
Point &q,
unsigned int const& walk_length,
Expand All @@ -158,7 +158,7 @@ struct Walk
<
typename GenericPolytope
>
inline void parameters_burnin(GenericPolytope const& P,
inline void parameters_burnin(GenericPolytope& P,
Point const& center,
unsigned int const& num_points,
unsigned int const& walk_length,
Expand All @@ -171,26 +171,26 @@ struct Walk
pointset.push_back(_p);
NT rad = NT(0), max_dist, Lmax = NT(0), radius = P.InnerBall().second;

for (int i = 0; i < num_points; i++)
for (int i = 0; i < num_points; i++)
{
p = GetPointInDsphere<Point>::apply(n, radius, rng);
p += center;
initialize(P, p, rng);

apply(P, p, walk_length, rng);
max_dist = get_max_distance(pointset, p, rad);
if (max_dist > Lmax)
if (max_dist > Lmax)
{
Lmax = max_dist;
}
if (2.0 * rad > Lmax)
if (2.0 * rad > Lmax)
{
Lmax = 2.0 * rad;
}
pointset.push_back(p);
}

if (Lmax > _Len)
if (Lmax > _Len)
{
update_delta(Lmax);
}
Expand All @@ -210,7 +210,7 @@ private :
<
typename GenericPolytope
>
inline void initialize(GenericPolytope const& P,
inline void initialize(GenericPolytope& P,
Point const& p,
RandomNumberGenerator &rng)
{
Expand All @@ -219,7 +219,7 @@ private :
_lambdas.setZero(P.num_of_hyperplanes());
_Av.setZero(P.num_of_hyperplanes());
_v = GetDirection<Point>::apply(n, rng, false);

do {
_p = p;
T = rng.sample_urdist() * _Len;
Expand Down Expand Up @@ -262,11 +262,11 @@ private :
}


inline double get_max_distance(std::vector<Point> &pointset, Point const& q, double &rad)
inline double get_max_distance(std::vector<Point> &pointset, Point const& q, double &rad)
{
double dis = -1.0, temp_dis;
int jj = 0;
for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++)
for (auto vecit = pointset.begin(); vecit!=pointset.end(); vecit++, jj++)
{
temp_dis = (q.getCoefficients() - (*vecit).getCoefficients()).norm();
if (temp_dis > dis) {
Expand Down
8 changes: 4 additions & 4 deletions include/random_walks/gaussian_accelerated_billiard_walk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct GaussianAcceleratedBilliardWalk
typedef typename Point::FT NT;

template <typename GenericPolytope, typename Ellipsoid>
Walk(GenericPolytope const& P,
Walk(GenericPolytope& P,
Point const& p,
Ellipsoid const& E, // ellipsoid representing the Gaussian distribution
RandomNumberGenerator &rng)
Expand All @@ -83,7 +83,7 @@ struct GaussianAcceleratedBilliardWalk
}

template <typename GenericPolytope, typename Ellipsoid>
Walk(GenericPolytope const& P,
Walk(GenericPolytope& P,
Point const& p,
Ellipsoid const& E, // ellipsoid representing the Gaussian distribution
RandomNumberGenerator &rng,
Expand All @@ -104,7 +104,7 @@ struct GaussianAcceleratedBilliardWalk
typename GenericPolytope,
typename Ellipsoid
>
inline void apply(GenericPolytope const& P,
inline void apply(GenericPolytope& P,
Point &p, // a point to return the result
Ellipsoid const& E, // ellipsoid representing the Gaussian distribution
unsigned int const& walk_length,
Expand Down Expand Up @@ -181,7 +181,7 @@ struct GaussianAcceleratedBilliardWalk
typename GenericPolytope,
typename Ellipsoid
>
inline void initialize(GenericPolytope const& P,
inline void initialize(GenericPolytope& P,
Point const& p, // a point to start
Ellipsoid const& E, // ellipsoid representing the Gaussian distribution
RandomNumberGenerator &rng)
Expand Down
Loading

0 comments on commit ac68063

Please sign in to comment.