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

1167 Update some dependencies #1168

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.13)

project(memilio VERSION 1.0.0)

Expand Down
6 changes: 3 additions & 3 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ The following table lists the dependencies that are used. Most of them are requi

| Library | Version | Required | Bundled | Notes |
|---------|----------|----------|-----------------------|-------|
| spdlog | 1.11.0 | Yes | Yes (git repo) | https://github.com/gabime/spdlog |
| Eigen | 3.3.9 | Yes | Yes (git repo) | http://gitlab.com/libeigen/eigen |
| spdlog | 1.15.0 | Yes | Yes (git repo) | https://github.com/gabime/spdlog |
| Eigen | 3.4.0 | Yes | Yes (git repo) | http://gitlab.com/libeigen/eigen |
| Boost | 1.84.0 | Yes | Yes (git repo) | https://github.com/boostorg/boost |
| JsonCpp | 1.9.5 | No | Yes (git repo) | https://github.com/open-source-parsers/jsoncpp |
| JsonCpp | 1.9.6 | No | Yes (git repo) | https://github.com/open-source-parsers/jsoncpp |
| HDF5 | 1.12.0 | No | No | https://www.hdfgroup.org/, package libhdf5-dev on apt (Ubuntu) |
| GoogleTest | 1.10 | For Tests only | Yes (git repo) | https://github.com/google/googletest |

Expand Down
35 changes: 9 additions & 26 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,17 @@ set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install benchmark" FORCE)
set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE BOOL "Don't download dependencies" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable Google Test in benchmark" FORCE)

if(CMAKE_VERSION VERSION_LESS 3.11)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")

include(DownloadProject)
download_project(PROJ benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1
UPDATE_DISCONNECTED 1
QUIET
)

# CMake warning suppression will not be needed in version 1.9
include(FetchContent)
FetchContent_Declare(benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1)
FetchContent_GetProperties(benchmark)

if(NOT benchmark_POPULATED)
FetchContent_Populate(benchmark)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_SOURCE_DIR} EXCLUDE_FROM_ALL)
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
else()
include(FetchContent)
FetchContent_Declare(benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1)
FetchContent_GetProperties(benchmark)

if(NOT benchmark_POPULATED)
FetchContent_Populate(benchmark)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
endif()
endif()

set_target_properties(benchmark PROPERTIES FOLDER "Extern")
Expand Down
16 changes: 8 additions & 8 deletions cpp/examples/glct_secir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ int main()
// InfectedNoSymptomsToInfectedSymptoms and one for InfectedNoSymptomsToRecovered.
// The strains have a length of NumInfectedNoSymptoms/2. each.
// The transition probability is included in the StartingProbability vector.
mio::Vector<ScalarType> StartingProbabilitiesInfectedNoSymptoms =
mio::Vector<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedNoSymptoms>());
Eigen::VectorX<ScalarType> StartingProbabilitiesInfectedNoSymptoms =
Eigen::VectorX<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedNoSymptoms>());
StartingProbabilitiesInfectedNoSymptoms[0] = 1 - recoveredPerInfectedNoSymptoms;
StartingProbabilitiesInfectedNoSymptoms[(Eigen::Index)(
LctState::get_num_subcompartments<InfectionState::InfectedNoSymptoms>() / 2.)] = recoveredPerInfectedNoSymptoms;
Expand All @@ -152,8 +152,8 @@ int main()
timeInfectedNoSymptoms);
// Do the same for all compartments.
// InfectedSymptoms.
mio::Vector<ScalarType> StartingProbabilitiesInfectedSymptoms =
mio::Vector<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedSymptoms>());
Eigen::VectorX<ScalarType> StartingProbabilitiesInfectedSymptoms =
Eigen::VectorX<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedSymptoms>());
StartingProbabilitiesInfectedSymptoms[0] = severePerInfectedSymptoms;
StartingProbabilitiesInfectedSymptoms[(Eigen::Index)(
LctState::get_num_subcompartments<InfectionState::InfectedSymptoms>() / 2.)] = 1 - severePerInfectedSymptoms;
Expand All @@ -165,8 +165,8 @@ int main()
mio::glsecir::TransitionMatrixInfectedSymptomsToRecovered().get_default(
(size_t)(LctState::get_num_subcompartments<InfectionState::InfectedSymptoms>() / 2.), timeInfectedSymptoms);
// InfectedSevere.
mio::Vector<ScalarType> StartingProbabilitiesInfectedSevere =
mio::Vector<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedSevere>());
Eigen::VectorX<ScalarType> StartingProbabilitiesInfectedSevere =
Eigen::VectorX<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedSevere>());
StartingProbabilitiesInfectedSevere[0] = criticalPerSevere;
StartingProbabilitiesInfectedSevere[(Eigen::Index)(
LctState::get_num_subcompartments<InfectionState::InfectedSevere>() / 2.)] = 1 - criticalPerSevere;
Expand All @@ -178,8 +178,8 @@ int main()
mio::glsecir::TransitionMatrixInfectedSevereToRecovered().get_default(
(size_t)(LctState::get_num_subcompartments<InfectionState::InfectedSevere>() / 2.), timeInfectedSevere);
// InfectedCritical.
mio::Vector<ScalarType> StartingProbabilitiesInfectedCritical =
mio::Vector<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedCritical>());
Eigen::VectorX<ScalarType> StartingProbabilitiesInfectedCritical =
Eigen::VectorX<ScalarType>::Zero(LctState::get_num_subcompartments<InfectionState::InfectedCritical>());
StartingProbabilitiesInfectedCritical[0] = deathsPerCritical;
StartingProbabilitiesInfectedCritical[(Eigen::Index)(
LctState::get_num_subcompartments<InfectionState::InfectedCritical>() / 2.)] = 1 - deathsPerCritical;
Expand Down
8 changes: 4 additions & 4 deletions cpp/examples/lct_secir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ int main()
if (use_initializer_flows) {
// Example how to use the class Initializer for the definition of an initial vector for the LCT model.

ScalarType dt = 0.001;
mio::Vector<ScalarType> total_population = mio::Vector<ScalarType>::Constant(1, 1000000.);
mio::Vector<ScalarType> deaths = mio::Vector<ScalarType>::Constant(1, 10.);
mio::Vector<ScalarType> total_confirmed_cases = mio::Vector<ScalarType>::Constant(1, 16000.);
ScalarType dt = 0.001;
Eigen::VectorX<ScalarType> total_population = Eigen::VectorX<ScalarType>::Constant(1, 1000000.);
Eigen::VectorX<ScalarType> deaths = Eigen::VectorX<ScalarType>::Constant(1, 10.);
Eigen::VectorX<ScalarType> total_confirmed_cases = Eigen::VectorX<ScalarType>::Constant(1, 16000.);

// Create TimeSeries with num_transitions elements.
int num_transitions = (int)mio::lsecir::InfectionTransition::Count;
Expand Down
28 changes: 14 additions & 14 deletions cpp/memilio/compartments/compartmentalmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ struct CompartmentalModel {
{
}

CompartmentalModel(const CompartmentalModel&) = default;
CompartmentalModel(CompartmentalModel&&) = default;
CompartmentalModel(const CompartmentalModel&) = default;
CompartmentalModel(CompartmentalModel&&) = default;
CompartmentalModel& operator=(const CompartmentalModel&) = default;
CompartmentalModel& operator=(CompartmentalModel&&) = default;
virtual ~CompartmentalModel() = default;
CompartmentalModel& operator=(CompartmentalModel&&) = default;
virtual ~CompartmentalModel() = default;

// REMARK: Not pure virtual for easier java/python bindings.
virtual void get_derivatives(Eigen::Ref<const Vector<FP>>, Eigen::Ref<const Vector<FP>> /*y*/, FP /*t*/,
Eigen::Ref<Vector<FP>> /*dydt*/) const {};
virtual void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>>, Eigen::Ref<const Eigen::VectorX<FP>> /*y*/,
FP /*t*/, Eigen::Ref<Eigen::VectorX<FP>> /*dydt*/) const {};

/**
* @brief This function evaluates the right-hand-side f of the ODE dydt = f(y, t).
Expand All @@ -118,8 +118,8 @@ struct CompartmentalModel {
* @param[in] t The current time.
* @param[out] dydt A reference to the calculated output.
*/
void eval_right_hand_side(Eigen::Ref<const Vector<FP>> pop, Eigen::Ref<const Vector<FP>> y, FP t,
Eigen::Ref<Vector<FP>> dydt) const
void eval_right_hand_side(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
Eigen::Ref<Eigen::VectorX<FP>> dydt) const
{
dydt.setZero();
this->get_derivatives(pop, y, t, dydt);
Expand All @@ -130,7 +130,7 @@ struct CompartmentalModel {
* See eval_right_hand_side for more detail.
* @return Current value of model populations as a flat vector.
*/
Vector<FP> get_initial_values() const
Eigen::VectorX<FP> get_initial_values() const
{
return populations.get_compartments();
}
Expand Down Expand Up @@ -183,10 +183,9 @@ struct CompartmentalModel {
* @tparam M a type that has a eval_right_hand_side member function, e.g. a compartment model type.
*/
template <typename FP, class M>
using eval_right_hand_side_expr_t =
decltype(std::declval<const M&>().eval_right_hand_side(std::declval<Eigen::Ref<const Vector<FP>>>(),
std::declval<Eigen::Ref<const Vector<FP>>>(),
std::declval<FP>(), std::declval<Eigen::Ref<Vector<FP>>>()));
using eval_right_hand_side_expr_t = decltype(std::declval<const M&>().eval_right_hand_side(
std::declval<Eigen::Ref<const Eigen::VectorX<FP>>>(), std::declval<Eigen::Ref<const Eigen::VectorX<FP>>>(),
std::declval<FP>(), std::declval<Eigen::Ref<Eigen::VectorX<FP>>>()));

/**
* Detect the get_initial_values member function of a compartment model.
Expand All @@ -197,7 +196,8 @@ using eval_right_hand_side_expr_t =
* @tparam M a type that has a get_initial_values member function, e.g. a compartment model type.
*/
template <typename FP, class M>
using get_initial_values_expr_t = decltype(std::declval<Vector<FP>&>() = std::declval<const M&>().get_initial_values());
using get_initial_values_expr_t =
decltype(std::declval<Eigen::VectorX<FP>&>() = std::declval<const M&>().get_initial_values());

/**
* Template meta function to check if a type is a valid compartment model.
Expand Down
29 changes: 15 additions & 14 deletions cpp/memilio/compartments/flow_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>

// Note: use get_flat_flow_index when accessing flows
// Note: by convention, we compute incoming flows, thus entries in flows must be non-negative
virtual void get_flows(Eigen::Ref<const Vector<FP>> /*pop*/, Eigen::Ref<const Vector<FP>> /*y*/, FP /*t*/,
Eigen::Ref<Vector<FP>> /*flows*/) const = 0;
virtual void get_flows(Eigen::Ref<const Eigen::VectorX<FP>> /*pop*/, Eigen::Ref<const Eigen::VectorX<FP>> /*y*/,
FP /*t*/, Eigen::Ref<Eigen::VectorX<FP>> /*flows*/) const = 0;

/**
* @brief Compute the right-hand-side of the ODE dydt = f(y, t) from flow values.
Expand All @@ -108,7 +108,7 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
* @param[in] flows The current flow values (as calculated by get_flows) as a flat array.
* @param[out] dydt A reference to the calculated output.
*/
void get_derivatives(Eigen::Ref<const Vector<FP>> flows, Eigen::Ref<Vector<FP>> dydt) const
void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> flows, Eigen::Ref<Eigen::VectorX<FP>> dydt) const
{
// set dydt to 0, then iteratively add all flow contributions
dydt.setZero();
Expand All @@ -134,8 +134,8 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
* @param[in] t The current time.
* @param[out] dydt A reference to the calculated output.
*/
void get_derivatives(Eigen::Ref<const Vector<FP>> pop, Eigen::Ref<const Vector<FP>> y, FP t,
Eigen::Ref<Vector<FP>> dydt) const override final
void get_derivatives(Eigen::Ref<const Eigen::VectorX<FP>> pop, Eigen::Ref<const Eigen::VectorX<FP>> y, FP t,
Eigen::Ref<Eigen::VectorX<FP>> dydt) const override final
{
m_flow_values.setZero();
get_flows(pop, y, t, m_flow_values);
Expand All @@ -147,9 +147,9 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
* This can be used as initial conditions in an ODE solver. By default, this is a zero vector.
* @return The initial flows.
*/
Vector<FP> get_initial_flows() const
Eigen::VectorX<FP> get_initial_flows() const
{
return Vector<FP>::Zero((this->populations.numel() / static_cast<size_t>(Comp::Count)) * Flows::size());
return Eigen::VectorX<FP>::Zero((this->populations.numel() / static_cast<size_t>(Comp::Count)) * Flows::size());
}

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
}

private:
mutable Vector<FP> m_flow_values; ///< Cache to avoid allocation in get_derivatives (using get_flows).
mutable Eigen::VectorX<FP> m_flow_values; ///< Cache to avoid allocation in get_derivatives (using get_flows).

/**
* @brief Compute the derivatives of the compartments.
Expand All @@ -216,7 +216,7 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
* @tparam I The index of a flow in FlowChart.
*/
template <size_t I = 0>
inline void get_rhs_impl(Eigen::Ref<const Vector<FP>> flows, Eigen::Ref<Vector<FP>> rhs,
inline void get_rhs_impl(Eigen::Ref<const Eigen::VectorX<FP>> flows, Eigen::Ref<Eigen::VectorX<FP>> rhs,
const FlowIndex& index) const
{
using Flow = type_at_index_t<I, Flows>;
Expand Down Expand Up @@ -244,16 +244,17 @@ class FlowModel : public CompartmentalModel<FP, Comp, Pop, Params>
*/
template <typename FP, class M>
using get_derivatives_expr_t = decltype(std::declval<const M&>().get_derivatives(
std::declval<Eigen::Ref<const Vector<FP>>>(), std::declval<Eigen::Ref<Vector<FP>>>()));
std::declval<Eigen::Ref<const Eigen::VectorX<FP>>>(), std::declval<Eigen::Ref<Eigen::VectorX<FP>>>()));

template <typename FP, class M>
using get_flows_expr_t =
decltype(std::declval<const M&>().get_flows(std::declval<Eigen::Ref<const Vector<FP>>>(),
std::declval<Eigen::Ref<const Vector<FP>>>(), std::declval<FP>(),
std::declval<Eigen::Ref<Vector<FP>>>()));
decltype(std::declval<const M&>().get_flows(std::declval<Eigen::Ref<const Eigen::VectorX<FP>>>(),
std::declval<Eigen::Ref<const Eigen::VectorX<FP>>>(),
std::declval<FP>(), std::declval<Eigen::Ref<Eigen::VectorX<FP>>>()));

template <typename FP, class M>
using get_initial_flows_expr_t = decltype(std::declval<Vector<FP>>() = std::declval<const M&>().get_initial_flows());
using get_initial_flows_expr_t =
decltype(std::declval<Eigen::VectorX<FP>>() = std::declval<const M&>().get_initial_flows());
/** @} */

/**
Expand Down
4 changes: 2 additions & 2 deletions cpp/memilio/compartments/flow_simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FlowSimulation : public Simulation<FP, M>
* tmax must be greater than get_result().get_last_time_point().
* @param[in] tmax Next stopping time of the simulation.
*/
Eigen::Ref<Vector<FP>> advance(FP tmax)
Eigen::Ref<Eigen::VectorX<FP>> advance(FP tmax)
{
// the derivfunktion (i.e. the lambda passed to m_integrator.advance below) requires that there are at least
// as many entries in m_flow_result as in Base::m_result
Expand Down Expand Up @@ -132,7 +132,7 @@ class FlowSimulation : public Simulation<FP, M>
}
}

Vector<FP> m_pop; ///< pre-allocated temporary, used in right_hand_side()
Eigen::VectorX<FP> m_pop; ///< pre-allocated temporary, used in right_hand_side()

private:
mio::TimeSeries<FP> m_flow_result; ///< flow result of the simulation
Expand Down
2 changes: 1 addition & 1 deletion cpp/memilio/compartments/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Simulation
* tmax must be greater than get_result().get_last_time_point()
* @param tmax next stopping point of simulation
*/
Eigen::Ref<Vector<FP>> advance(FP tmax)
Eigen::Ref<Eigen::VectorX<FP>> advance(FP tmax)
{
return m_integrator.advance(
[this](auto&& y, auto&& t, auto&& dydt) {
Expand Down
1 change: 0 additions & 1 deletion cpp/memilio/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define MIO_CONFIG_H

#include "memilio/config_internal.h"
#include <type_traits>

using ScalarType = double;

Expand Down
4 changes: 2 additions & 2 deletions cpp/memilio/epidemiology/lct_infection_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class LctInfectionState
* The size of the vector has to match the LctInfectionState.
* @return Vector with accumulated values for the InfectionStates.
*/
static Vector<ScalarType> calculate_compartments(const Vector<ScalarType>& subcompartments)
static Eigen::VectorX<ScalarType> calculate_compartments(const Eigen::VectorX<ScalarType>& subcompartments)
{
assert(subcompartments.rows() == Count);

Vector<ScalarType> compartments((Eigen::Index)InfectionState::Count);
Eigen::VectorX<ScalarType> compartments((Eigen::Index)InfectionState::Count);
// Use segment of the vector subcompartments of each InfectionState and sum up the values of subcompartments.
compartments[(Eigen::Index)InfectionState::Susceptible] = subcompartments[0];
compartments[(Eigen::Index)InfectionState::Exposed] =
Expand Down
2 changes: 1 addition & 1 deletion cpp/memilio/epidemiology/lct_populations.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class LctPopulations
* This can be used as initial conditions for the ODE solver.
* @return Eigen::VectorXd of populations.
*/
inline Vector<FP> get_compartments() const
inline Eigen::VectorX<FP> get_compartments() const
{
return m_y.array().template cast<FP>();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/memilio/epidemiology/populations.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
* as initial conditions for the ODE solver
* @return Eigen::VectorXd of populations
*/
inline Vector<FP> get_compartments() const
inline Eigen::VectorX<FP> get_compartments() const
{
return this->array().template cast<FP>();
}
Expand Down
6 changes: 5 additions & 1 deletion cpp/memilio/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,11 @@ using compare_iterators_t = decltype(std::declval<const C&>().begin() != std::de
* @tparam C any type.
*/
template <class C>
using is_container = is_expression_valid<details::compare_iterators_t, C>;
using is_container =
conjunction<is_expression_valid<details::compare_iterators_t, C>,
std::is_constructible<C, decltype(std::declval<C>().begin()), decltype(std::declval<C>().end())>,
// Eigen types may pass as container, but we want to handle them separately
negation<std::is_base_of<Eigen::EigenBase<C>, C>>>;

/**
* serialize an STL compatible container.
Expand Down
2 changes: 1 addition & 1 deletion cpp/memilio/math/adapt_rk.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class RKIntegratorCore : public IntegratorCore<FP>
TableauFinal m_tab_final;
FP m_abs_tol, m_rel_tol;
mutable Eigen::Matrix<FP, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> m_kt_values;
mutable Vector<FP> m_yt_eval;
mutable Eigen::VectorX<FP> m_yt_eval;

private:
mutable Eigen::Array<FP, Eigen::Dynamic, Eigen::Dynamic> m_eps,
Expand Down
Loading