diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml index 07e49c2084c8a..d0e404566223b 100644 --- a/.github/workflows/ci_macos.yml +++ b/.github/workflows/ci_macos.yml @@ -28,11 +28,14 @@ jobs: matrix: os: [macos-latest] build_type: [Release] + enable_simd: [ON] env: COMPILER: clang BUILD_TYPE: ${{ matrix.build_type }} BUILD_DARTPY: ON DART_USE_SYSTEM_ENTT: ON + IN_CI: ON + ENABLE_SIMD: ${{ matrix.enable_simd }} steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/ci_ubuntu.yml b/.github/workflows/ci_ubuntu.yml index 130bb8180f8f9..581d0b936a49c 100644 --- a/.github/workflows/ci_ubuntu.yml +++ b/.github/workflows/ci_ubuntu.yml @@ -33,6 +33,7 @@ jobs: codecov: [OFF] check_format: [OFF] build_dartpy: [ON] + enable_simd: [ON] include: # For code coverage report to Codecov - os: ubuntu-jammy @@ -40,6 +41,7 @@ jobs: codecov: ON check_format: ON build_dartpy: ON + enable_simd: ON env: # Hosted on: https://hub.docker.com/repository/docker/jslee02/dart-dev DART_DEV_IMAGE: jslee02/dart-dev @@ -49,7 +51,11 @@ jobs: BUILD_TYPE: ${{ matrix.build_type }} BUILD_DARTPY: "${{ matrix.build_dartpy }}" CODECOV: ${{ matrix.codecov }} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} CHECK_FORMAT: ${{ matrix.check_format }} + ENABLE_SIMD: ${{ matrix.enable_simd }} + IN_CI: ON + IN_DOCKER: ON steps: # https://github.com/marketplace/actions/docker-setup-qemu - name: Set up QEMU diff --git a/CMakeLists.txt b/CMakeLists.txt index 63d2b5beef80a..8cb3468f5d70e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF) dart_option(DART_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF) dart_option(DART_USE_SYSTEM_ENTT "Use system EnTT" OFF) +dart_option(DART_IN_CI "Indicate building DART as part of CI" OFF) #=============================================================================== # Print intro @@ -128,11 +129,38 @@ message(STATUS "") # CodeCov settings #=============================================================================== if(DART_CODECOV) - include(CodeCoverage) - setup_target_for_coverage(codecov ctest coverage) - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage" + # Set up custom targets for code coverage + dart_coverage( + INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dart + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dart ) + + # Code Coverage Configuration + add_library(coverage_config INTERFACE) + + # CodeCov can only be enabled in Debug mode + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + message(FATAL_ERROR "CodeCov can only be enabled in Debug mode") + endif() + + # CodeCov can only be enabled with GCC or Clang + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + message(FATAL_ERROR "CodeCov can only be enabled with GCC or Clang") + endif() + + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags + ) + + # Add required flags (GCC & LLVM/Clang) + target_link_options(coverage_config INTERFACE --coverage) + + # Export CodeCov configuration + install(TARGETS coverage_config DESTINATION lib EXPORT coverage_config) + install(EXPORT coverage_config DESTINATION ${CONFIG_INSTALL_DIR}) endif() #=============================================================================== @@ -670,6 +698,11 @@ if(TARGET dartpy) message(STATUS "Run 'make dartpy' to build dartpy") message(STATUS "Run 'make install' to install dartpy") endif() +if(TARGET coverage) + message(STATUS "- 'coverage' : generage coverage report") + message(STATUS "- 'coverage_html': generage coverage report in html") + message(STATUS "- 'coverage_view': view generaged coverage report in a browser") +endif() #=============================================================================== # END diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake deleted file mode 100644 index 62fd6be1fe3a8..0000000000000 --- a/cmake/CodeCoverage.cmake +++ /dev/null @@ -1,208 +0,0 @@ -# Copyright (c) 2012 - 2015, Lars Bilke -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors -# may be used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# -# -# 2012-01-31, Lars Bilke -# - Enable Code Coverage -# -# 2013-09-17, Joakim Söderberg -# - Added support for Clang. -# - Some additional usage instructions. -# -# 2019-01-24, Brian Hou -# - Added support for Codecov uploads. -# -# USAGE: - -# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here: -# http://stackoverflow.com/a/22404544/80480 -# -# 1. Copy this file into your cmake modules path. -# -# 2. Add the following line to your CMakeLists.txt: -# INCLUDE(CodeCoverage) -# -# 3. Set compiler flags to turn off optimization and enable coverage: -# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") -# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") -# -# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target -# which runs your test executable and produces a lcov code coverage report: -# Example: -# SETUP_TARGET_FOR_COVERAGE( -# my_coverage_target # Name for custom target. -# test_driver # Name of the test driver executable that runs the tests. -# # NOTE! This should always have a ZERO as exit code -# # otherwise the coverage generation will not complete. -# coverage # Name of output directory. -# ) -# -# 4. Build a Debug build: -# cmake -DCMAKE_BUILD_TYPE=Debug .. -# make -# make my_coverage_target -# -# - -# Check prereqs -FIND_PROGRAM( GCOV_PATH gcov ) -FIND_PROGRAM( LCOV_PATH lcov ) -FIND_PROGRAM( GENHTML_PATH genhtml ) -FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) - -IF(NOT GCOV_PATH) - MESSAGE(FATAL_ERROR "gcov not found! Aborting...") -ENDIF() # NOT GCOV_PATH - -IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") - IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) - MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") - ENDIF() -ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX) - MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") -ENDIF() # CHECK VALID COMPILER - -SET(CMAKE_CXX_FLAGS_COVERAGE - "-g -O0 --coverage -fprofile-arcs -ftest-coverage" - CACHE STRING "Flags used by the C++ compiler during coverage builds." - FORCE ) -SET(CMAKE_C_FLAGS_COVERAGE - "-g -O0 --coverage -fprofile-arcs -ftest-coverage" - CACHE STRING "Flags used by the C compiler during coverage builds." - FORCE ) -SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used for linking binaries during coverage builds." - FORCE ) -SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE - "" - CACHE STRING "Flags used by the shared libraries linker during coverage builds." - FORCE ) -MARK_AS_ADVANCED( - CMAKE_CXX_FLAGS_COVERAGE - CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE - CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) - -IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) - MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" ) -ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" - - -# Param _targetname The name of new the custom make target -# Param _testrunner The name of the target which runs the tests. -# MUST return ZERO always, even on errors. -# If not, no coverage report will be created! -# Param _outputname lcov output is generated as _outputname.info -# HTML report is generated in _outputname/index.html -# Optional fourth parameter is passed as arguments to _testrunner -# Pass them in list form, e.g.: "-j;2" for -j 2 -FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) - - IF(NOT LCOV_PATH) - MESSAGE(FATAL_ERROR "lcov not found! Aborting...") - ENDIF() # NOT LCOV_PATH - - IF(NOT GENHTML_PATH) - MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") - ENDIF() # NOT GENHTML_PATH - - SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info") - SET(coverage_cleaned "${coverage_info}.cleaned") - SET(codecov_script "${CMAKE_BINARY_DIR}/codecov.sh") - - SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}") - - # Setup target - ADD_CUSTOM_TARGET(${_targetname} - - # Cleanup lcov - ${LCOV_PATH} --directory . --zerocounters - - # Run tests - COMMAND ${test_command} ${ARGV3} - - # Capturing lcov counters and generating report - COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info} - COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned} - COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned} - - # Upload to Codecov (added by @brianhou) - COMMAND curl -s "https://codecov.io/bash" > ${codecov_script} - COMMAND chmod +x ${codecov_script} - COMMAND ${codecov_script} -R ${CMAKE_SOURCE_DIR} -X gcov -f ${coverage_cleaned} - - # Clean up reports - COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned} - - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." - ) - - # Show info where to find the report - ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD - COMMAND ; - COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." - ) - -ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE - -# Param _targetname The name of new the custom make target -# Param _testrunner The name of the target which runs the tests -# Param _outputname cobertura output is generated as _outputname.xml -# Optional fourth parameter is passed as arguments to _testrunner -# Pass them in list form, e.g.: "-j;2" for -j 2 -FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) - - IF(NOT Python3_EXECUTABLE) - MESSAGE(FATAL_ERROR "Python not found! Aborting...") - ENDIF() # NOT Python3_EXECUTABLE - - IF(NOT GCOVR_PATH) - MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") - ENDIF() # NOT GCOVR_PATH - - ADD_CUSTOM_TARGET(${_targetname} - - # Run tests - ${_testrunner} ${ARGV3} - - # Running gcovr - COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Running gcovr to produce Cobertura code coverage report." - ) - - # Show info where to find the report - ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD - COMMAND ; - COMMENT "Cobertura code coverage report saved in ${_outputname}.xml." - ) - -ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA diff --git a/cmake/DARTFindpagmo.cmake b/cmake/DARTFindpagmo.cmake index a746c088358a6..cb67c308bf207 100644 --- a/cmake/DARTFindpagmo.cmake +++ b/cmake/DARTFindpagmo.cmake @@ -6,4 +6,4 @@ # # This file is provided under the "BSD-style" License -find_package(pagmo 2.17.0 QUIET CONFIG) +find_package(pagmo QUIET CONFIG) diff --git a/cmake/dart_defs.cmake b/cmake/dart_defs.cmake index f2ab0eb7e903b..8a52a275c8219 100644 --- a/cmake/dart_defs.cmake +++ b/cmake/dart_defs.cmake @@ -221,4 +221,143 @@ function(dart_library) dart_format_add(${_ARG_HEADERS} ${_ARG_SOURCES}) -endfunction() \ No newline at end of file +endfunction() + +#=============================================================================== +function(dart_coverage) + set(prefix _ARG) + set(options + REQUIRED + ) + set(oneValueArgs + INCLUDE_DIR + SOURCE_DIR + INSTALL_DIR + ) + set(multiValueArgs + INPUT # optional + EXCLUDE + ) + cmake_parse_arguments( + "${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} + ) + + include(GNUInstallDirs) + + if(NOT _ARG_INCLUDE_DIR) + message(FATAL_ERROR "INCLUDE_DIR is not set") + endif() + + if(NOT _ARG_SOURCE_DIR) + message(FATAL_ERROR "SOURCE_DIR is not set") + endif() + + if(NOT _ARG_INSTALL_DIR) + set(_ARG_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOXDIR}/${PROJECT_NAME}${DART_VERSION_MAJOR}/coverage) + endif() + + # Find gcovr + if(NOT GCOVR_EXECUTABLE) + find_program(GCOVR_EXECUTABLE gcovr QUIET) + if(NOT GCOVR_EXECUTABLE) + if(_ARG_REQUIRED) + message(FATAL_ERROR "Failed to find gcovr. Install gcovr or remove REQUIRED option.") + else() + return() + endif() + endif() + endif() + + # Set variables + get_filename_component(_ARG_INCLUDE_DIR ${_ARG_INCLUDE_DIR} ABSOLUTE) + set(gcovr_include_dir ${_ARG_INCLUDE_DIR}) + get_filename_component(_ARG_SOURCE_DIR ${_ARG_SOURCE_DIR} ABSOLUTE) + set(gcovr_source_dir ${_ARG_SOURCE_DIR}) + set(gcovr_html_dir ${CMAKE_CURRENT_BINARY_DIR}/__coverage__) + set(gcovr_index_path ${gcovr_html_dir}/index.html) + + # Extract Gcovr version + execute_process(COMMAND ${GCOVR_EXECUTABLE} --version OUTPUT_VARIABLE GCOVR_VERSION_RAW_OUTPUT) + string(STRIP ${GCOVR_VERSION_RAW_OUTPUT} GCOVR_VERSION_RAW_OUTPUT) + string(REPLACE "gcovr " "" GCOVR_VERSION_RAW_OUTPUT ${GCOVR_VERSION_RAW_OUTPUT}) + + # Set options based on the Gcovr version + if(${GCOVR_VERSION_RAW_OUTPUT} VERSION_GREATER_EQUAL 4.2) + set(gcovr_options --exclude-throw-branches) + endif() + + add_custom_target(coverage + COMMAND + ${GCOVR_EXECUTABLE} + -r ${CMAKE_CURRENT_SOURCE_DIR} + -f ${gcovr_include_dir} + -f ${gcovr_source_dir} + DEPENDS tests_and_run + COMMENT "Generating line coverage report..." + ) + + add_custom_target(coverage_branch + COMMAND ${GCOVR_EXECUTABLE} + -b + ${gcovr_options} + --exclude-unreachable-branches + -r ${CMAKE_CURRENT_SOURCE_DIR} + -f ${gcovr_include_dir} + -f ${gcovr_source_dir} + DEPENDS tests_and_run + COMMENT "Generating branch coverage report..." + ) + + add_custom_target(coverage_html + COMMAND ${CMAKE_COMMAND} -E make_directory ${gcovr_html_dir} + COMMAND ${GCOVR_EXECUTABLE} + --html + --html-details + ${gcovr_options} + --exclude-unreachable-branches + -o "${gcovr_index_path}" + -r ${CMAKE_CURRENT_SOURCE_DIR} + -f ${gcovr_include_dir} + -f ${gcovr_source_dir} + DEPENDS coverage coverage_branch + COMMENT "Generating a detailed HTML coverage report in ${gcovr_index_path}" + ) + + if(APPLE) + set(open_command_name "open") + else() + set(open_command_name "xdg-open") + endif() + find_program(open_command + NAMES ${open_command_name} + DOC "Path to ${open_command_name}" + ) + + if(open_command) + add_custom_target(coverage_view "${open_command}" "${gcovr_index_path}" + DEPENDS coverage_html + COMMENT "Opening documentation in a web browser." + ) + else() + message(WARNING "Failed to find ${open_command_name}, to enable " + "'coverage_view', please install xdg-utils" + ) + endif() + + # Remove all gcovr data and delete the html directory + add_custom_target(coverage_cleanup + COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/**/*.gcno + COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/**/*.gcda + COMMAND rm -rf ${gcovr_html_dir} + COMMENT "Removing stored coverage files..." + ) + + # Create the working directory ahead so that make install doesn't complain even when + # make coverage is run before. + file(MAKE_DIRECTORY ${gcovr_html_dir}) + + # Install + if(EXISTS ${gcovr_html_dir}) + install(DIRECTORY ${gcovr_html_dir}/ DESTINATION ${_ARG_INSTALL_DIR}) + endif() +endfunction() diff --git a/dart/CMakeLists.txt b/dart/CMakeLists.txt index b3dc102ed4880..279946a2a5675 100644 --- a/dart/CMakeLists.txt +++ b/dart/CMakeLists.txt @@ -233,11 +233,15 @@ endif() if(MSVC) set_target_properties( - ${target} PROPERTIES + dart PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG" ) endif() +if(DART_CODECOV) + target_link_libraries(dart PUBLIC coverage_config) +endif() + install(FILES dart.hpp DESTINATION include/dart/ COMPONENT headers) dart_format_add(${dart_core_headers} ${dart_core_sources}) diff --git a/dart/optimizer/pagmo/PagmoMultiObjectiveProblemAdaptor.hpp b/dart/optimizer/pagmo/PagmoMultiObjectiveProblemAdaptor.hpp index f8397b025b2a2..8fe9cbf4d4961 100644 --- a/dart/optimizer/pagmo/PagmoMultiObjectiveProblemAdaptor.hpp +++ b/dart/optimizer/pagmo/PagmoMultiObjectiveProblemAdaptor.hpp @@ -33,10 +33,12 @@ #ifndef DART_OPTIMIZER_PAGMO_PAGMOMULTIOBJECTIVEPROBLEMADAPTOR_HPP_ #define DART_OPTIMIZER_PAGMO_PAGMOMULTIOBJECTIVEPROBLEMADAPTOR_HPP_ -#include -#include #include +#include + +#include + namespace dart { namespace optimizer { diff --git a/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.cpp b/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.cpp index 04f64ba7d521c..688c63b42278b 100644 --- a/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.cpp +++ b/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.cpp @@ -32,8 +32,6 @@ #include "dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp" -#include -#include #include "dart/common/Console.hpp" #include "dart/common/StlHelpers.hpp" #include "dart/math/Constants.hpp" @@ -42,6 +40,10 @@ #include "dart/optimizer/pagmo/PagmoMultiObjectiveProblemAdaptor.hpp" #include "dart/optimizer/pagmo/PagmoUtils.hpp" +#include + +#include + namespace dart { namespace optimizer { @@ -120,20 +122,16 @@ static pagmo::algorithm createNsga2( static pagmo::algorithm createPagmoAlgorithm( const PagmoMultiObjectiveSolver::Properties& properties) { - switch (properties.mAlgorithm) - { + switch (properties.mAlgorithm) { #ifdef PAGMO_WITH_NLOPT - case PagmoMultiObjectiveSolver::Algorithm::Local_nlopt_COBYLA: - { + case PagmoMultiObjectiveSolver::Algorithm::Local_nlopt_COBYLA: { return createNloptCobyla(properties); } #endif - case PagmoMultiObjectiveSolver::Algorithm::Global_MOEAD: - { + case PagmoMultiObjectiveSolver::Algorithm::Global_MOEAD: { return createMoead(properties); } - case PagmoMultiObjectiveSolver::Algorithm::Global_NSGA2: - { + case PagmoMultiObjectiveSolver::Algorithm::Global_NSGA2: { return createNsga2(properties); } } @@ -161,8 +159,7 @@ bool PagmoMultiObjectiveSolver::solve(std::size_t numEvolutions) mPopulations.clear(); mPopulations.reserve(archi.size()); - for (std::size_t i = 0u; i < archi.size(); ++i) - { + for (std::size_t i = 0u; i < archi.size(); ++i) { mPopulations.emplace_back( PagmoTypes::convertPopulation(archi[i].get_population(), prob)); } diff --git a/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp b/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp index 59049bd43ca68..3f79470076df0 100644 --- a/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp +++ b/dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp @@ -33,10 +33,12 @@ #ifndef DART_OPTIMIZER_PAGMO_PAGMOMULTIOBJECTIVESOLVER_HPP_ #define DART_OPTIMIZER_PAGMO_PAGMOMULTIOBJECTIVESOLVER_HPP_ -#include -#include #include +#include + +#include + #define DART_PAGMO_DEFAULT_SOLVER Algorithm::Global_MOEAD namespace dart { diff --git a/dart/optimizer/pagmo/PagmoUtils.cpp b/dart/optimizer/pagmo/PagmoUtils.cpp index 3f726181b22fd..49f23405f2a32 100644 --- a/dart/optimizer/pagmo/PagmoUtils.cpp +++ b/dart/optimizer/pagmo/PagmoUtils.cpp @@ -59,8 +59,7 @@ Population PagmoTypes::convertPopulation( const auto& pagmoX = pagmoPop.get_x(); const auto& pagmoF = pagmoPop.get_f(); - for (std::size_t i = 0u; i < pagmoPop.size(); ++i) - { + for (std::size_t i = 0u; i < pagmoPop.size(); ++i) { const Eigen::VectorXd x = convertVector(pagmoX[i]); const Eigen::VectorXd f = convertVector(pagmoF[i]); pop.set(i, x, f); @@ -75,8 +74,7 @@ pagmo::population PagmoTypes::convertPopulation( { pagmo::population pagmoPop(pagmoProb, pop.getSize()); - for (std::size_t i = 0u; i < pagmoPop.size(); ++i) - { + for (std::size_t i = 0u; i < pagmoPop.size(); ++i) { const std::vector pagmoX = convertVector(pop.getDecisionVector(i)); const std::vector pagmoF = convertVector(pop.getFitnessVector(i)); pagmoPop.set_xf(i, pagmoX, pagmoF); diff --git a/dart/optimizer/pagmo/PagmoUtils.hpp b/dart/optimizer/pagmo/PagmoUtils.hpp index 97bd263e84a03..3bd8dbe64eb92 100644 --- a/dart/optimizer/pagmo/PagmoUtils.hpp +++ b/dart/optimizer/pagmo/PagmoUtils.hpp @@ -33,9 +33,10 @@ #ifndef DART_OPTIMIZER_PAGMO_PAGMOUTILS_HPP_ #define DART_OPTIMIZER_PAGMO_PAGMOUTILS_HPP_ -#include #include +#include + namespace dart { namespace optimizer { diff --git a/dart/v7/ecs/entity_manager.hpp b/dart/v7/ecs/entity_manager.hpp index 1041a4cb7a775..d029aed217e8d 100644 --- a/dart/v7/ecs/entity_manager.hpp +++ b/dart/v7/ecs/entity_manager.hpp @@ -51,4 +51,4 @@ class EntityManager entt::registry mRegistry; }; -} // namespace dart::v7 \ No newline at end of file +} // namespace dart::v7 diff --git a/docker/dev/v6.14/Dockerfile.ubuntu.noble b/docker/dev/v6.14/Dockerfile.ubuntu.noble index c9994d3097e87..cf49a8d9495ab 100644 --- a/docker/dev/v6.14/Dockerfile.ubuntu.noble +++ b/docker/dev/v6.14/Dockerfile.ubuntu.noble @@ -54,30 +54,8 @@ RUN apt-get install -y --no-install-recommends \ liboctomap-dev \ libode-dev \ libimgui-dev \ - libspdlog-dev - -# pagmo2 -RUN apt-get install -y --no-install-recommends \ - coinor-libipopt-dev \ - libboost-serialization-dev \ - libeigen3-dev \ - libnlopt-cxx-dev \ - libtbb-dev -RUN git clone https://github.com/esa/pagmo2.git -b 'v2.17.0' --single-branch --depth 1 \ - && mkdir pagmo2/build \ - && pushd pagmo2/build \ - && cmake .. \ - -DCMAKE_BUILD_TYPE=Release \ - -DPAGMO_WITH_EIGEN3=ON \ - -DPAGMO_WITH_NLOPT=OFF \ - -DPAGMO_WITH_IPOPT=ON \ - -DPAGMO_BUILD_TESTS=OFF \ - -DPAGMO_BUILD_BENCHMARKS=OFF \ - -DPAGMO_BUILD_TUTORIALS=OFF \ - && make -j$(nproc) \ - && make install \ - && popd \ - && rm -rf pagmo2 + libspdlog-dev \ + libpagmo-dev # ============================================================================== # Python binding dependencies diff --git a/scripts/build.sh b/scripts/build.sh index 725c13b7e2d56..9c123dbddaff4 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -27,9 +27,14 @@ if [ -z "$CODECOV" ]; then CODECOV=OFF fi -if [ -z "$BUILD_DIR" ]; then - echo "Error: Environment variable BUILD_DIR is unset. Using $PWD by default." - BUILD_DIR=$PWD +if [ -z "$CODE_DIR" ]; then + echo "Error: Environment variable CODE_DIR is unset. Using $PWD by default." + CODE_DIR=$PWD +fi + +if [ -z "$IN_DOCKER" ]; then + echo "Error: Environment variable IN_DOCKER is unset. Using OFF by default." + IN_DOCKER=OFF fi if [ -z "$CHECK_FORMAT" ]; then @@ -57,6 +62,16 @@ if [ -z "$TEST_INSTALLATION" ]; then TEST_INSTALLATION=ON fi +if [ -z "$IN_CI" ]; then + echo "Info: Environment variable IN_CI is unset. Using OFF by default." + IN_CI=OFF +fi + +if [ -z "$ENABLE_SIMD" ]; then + echo "Info: Environment variable ENABLE_SIMD is unset. Using OFF by default." + ENABLE_SIMD=ON +fi + if [ -f /etc/os-release ]; then # freedesktop.org and systemd . /etc/os-release @@ -119,7 +134,7 @@ fi # Build API documentation and exit if [ $BUILD_DOCS = "ON" ]; then - . "${BUILD_DIR}/scripts/build_docs.sh" + . "${CODE_DIR}/scripts/build_docs.sh" exit 0 fi @@ -127,6 +142,7 @@ echo "=====================================" echo "" echo " [ SYSTEM INFO ]" echo "" +echo " IN_DOCKER: $IN_DOCKER" echo " OS : $OS $VER ($(uname -m))" echo " OSTYPE : $OSTYPE" echo " Cores : $num_threads / $num_available_threads" @@ -135,70 +151,119 @@ echo " CMake : $(cmake --version | perl -pe '($_)=/([0-9]+([.][0-9]+)+)/')" echo "" echo "=====================================" +if [ "$IN_DOCKER" = "ON" ]; then + # Create workspace folder + ws_dir=/ws + mkdir -p $ws_dir + + # Copy DART code + source_dir=$ws_dir/code + cp -r $CODE_DIR $source_dir +else + source_dir=$CODE_DIR +fi +cd $source_dir + +# Create build folder +build_dir=$source_dir/build +mkdir -p $build_dir + # Run CMake -mkdir build && cd build +cmake_args="" if [ "$OSTYPE" = "linux-gnu" ]; then install_prefix_option="-DCMAKE_INSTALL_PREFIX=/usr/" elif [[ $OSTYPE = darwin* ]]; then install_prefix_option="-DCMAKE_INSTALL_PREFIX=/usr/local/ -DCMAKE_INSTALL_RPATH=/usr/local/lib/" + cmake_args="-DOpenCLHeaders_DIR=$(brew --prefix opencl-headers)/share/cmake/OpenCLHeaders -DOpenCLHeadersCpp_DIR=$(brew --prefix opencl-clhpp-headers)/share/cmake/OpenCLHeadersCpp" fi cmake .. \ + -S $source_dir \ + -B $build_dir \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DDART_VERBOSE=ON \ -DDART_TREAT_WARNINGS_AS_ERRORS=ON \ -DDART_CODECOV=$CODECOV \ - ${install_prefix_option} + -DDART_IN_CI=$IN_CI \ + -DDART_ENABLE_SIMD=$ENABLE_SIMD \ + ${install_prefix_option} \ + ${cmake_args} # Check format if [ "$CHECK_FORMAT" = "ON" ]; then - make check-format + cmake --build $build_dir --target check-format fi # DART: build, test, and install -make -j$num_threads all tests -ctest --output-on-failure -j$num_threads +cmake --build $build_dir --target all tests -j$num_threads +ctest --output-on-failure -j$num_threads --test-dir $build_dir if [ "$BUILD_EXAMPLES" = "ON" ]; then - make -j$num_threads all examples + cmake --build $build_dir --target all examples -j$num_threads fi if [ "$BUILD_TUTORIALS" = "ON" ]; then - make -j$num_threads all tutorials + cmake --build $build_dir --target all tutorials -j$num_threads fi # dartpy: build, test, and install if [ "$BUILD_DARTPY" = "ON" ]; then - make -j$num_threads dartpy - make pytest + export DART_DATA_LOCAL_PATH=$source_dir/data + cmake --build $build_dir --target dartpy -j$num_threads + cmake --build $build_dir --target pytest + find $CODE_DIR -type d -name directory_name -exec rm -rf {} + fi -make -j$num_threads install +cmake --build $build_dir --target install -# Codecov +# Code coverage report generation and upload to codecov.io (only for Linux) if [ "$CODECOV" = "ON" ]; then - lcov --directory . --capture --output-file coverage.info - # filter out system and extra files. + + echo "Info: Code coverage is enabled." + + echo "Downloading codecov script..." + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov --version + ./codecov -t $CODECOV_TOKEN + + echo "Generating code coverage report..." + + # Capture coverage info + lcov --capture --directory . --output-file coverage.info + # Filter out system and extra files. # To also not include test code in coverage add them with full path to the patterns: '*/tests/*' - lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' --output-file coverage.info - # output coverage data for debugging (optional) + lcov \ + --remove coverage.info \ + '/usr/*' \ + '*/.deps/*' \ + '*/tests/*' \ + '*/examples/*' \ + '*/tutorials/*' \ + --output-file coverage.info + # Output coverage data for debugging (optional) lcov --list coverage.info + # Uploading to CodeCov + echo "Uploading code coverage report to codecov.io..." # '-f' specifies file(s) to use and disables manual coverage gathering and file search which has already been done above - bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" -fi + ./codecov -f coverage.info -# DART: build an C++ example using installed DART -if [ "$TEST_INSTALLATION" = "ON" ]; then - cd $BUILD_DIR/examples/hello_world +elif [ "$TEST_INSTALLATION" = "ON" ]; then + + # DART: build an C++ example using installed DART + echo "Info: Testing the installation..." + cd $source_dir/examples/hello_world mkdir build && cd build cmake .. make -j$num_threads + fi # dartpy: run a Python example using installed dartpy if [ "$BUILD_DARTPY" = "ON" ]; then + echo "Info: Running a Python example..." echo $PYTHONPATH - cd $BUILD_DIR/python/examples/hello_world + cd $source_dir/python/examples/hello_world # python3 main.py fi diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 5857559fbdbca..2d14a2a425fb7 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -1,15 +1,38 @@ #!/bin/bash + if [ "$#" -lt 2 ]; then - echo "Usage: ./check_format.sh [ ...]" >&2 - exit 0 + echo "Usage: ./check_format.sh [ ...]" >&2 + exit 1 fi -num_changes=$($1 -style=file -output-replacements-xml "${@:2}" | grep -c " -#include -#include #include + #include #include #include + +#include +#include + #include + +#include #if HAVE_PAGMO -# include + #include #endif using namespace dart;