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 9 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
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
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
7 changes: 3 additions & 4 deletions cpp/memilio/math/stepper_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "memilio/utils/logging.h"

#include "boost/numeric/odeint/external/eigen/eigen_algebra.hpp"
#include "boost/numeric/odeint/external/eigen/eigen_resize.hpp"
#include "boost/numeric/odeint/stepper/controlled_runge_kutta.hpp"
#include "boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp"
#include "boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp"
Expand All @@ -44,7 +45,7 @@ class ControlledStepperWrapper : public mio::IntegratorCore<FP>
using Stepper = boost::numeric::odeint::controlled_runge_kutta<
ControlledStepper<Vector<FP>, FP, Vector<FP>, FP, boost::numeric::odeint::vector_space_algebra,
typename boost::numeric::odeint::operations_dispatcher<Vector<FP>>::operations_type,
boost::numeric::odeint::never_resizer>>;
boost::numeric::odeint::initially_resizer>>;
mknaranja marked this conversation as resolved.
Show resolved Hide resolved
static constexpr bool is_fsal_stepper = std::is_same_v<typename Stepper::stepper_type::stepper_category,
boost::numeric::odeint::explicit_error_stepper_fsal_tag>;
static_assert(!is_fsal_stepper,
Expand Down Expand Up @@ -109,7 +110,6 @@ class ControlledStepperWrapper : public mio::IntegratorCore<FP>
step_result = m_stepper.try_step(
// reorder arguments of the DerivFunction f for the stepper
[&](const Vector<FP>& x, Vector<FP>& dxds, FP s) {
dxds.resizeLike(x); // boost resizers cannot resize Eigen::Vector, hence we need to do that here
mknaranja marked this conversation as resolved.
Show resolved Hide resolved
f(x, s, dxds);
},
m_yt, t, m_ytp1, dt);
Expand Down Expand Up @@ -186,7 +186,7 @@ class ExplicitStepperWrapper : public mio::IntegratorCore<FP>
public:
using Stepper = ExplicitStepper<Vector<FP>, FP, Vector<FP>, FP, boost::numeric::odeint::vector_space_algebra,
typename boost::numeric::odeint::operations_dispatcher<Vector<FP>>::operations_type,
boost::numeric::odeint::never_resizer>;
boost::numeric::odeint::initially_resizer>;

/**
* @brief Set up the integrator.
Expand All @@ -213,7 +213,6 @@ class ExplicitStepperWrapper : public mio::IntegratorCore<FP>
m_stepper.do_step(
// reorder arguments of the DerivFunction f for the stepper
[&](const Vector<FP>& x, Vector<FP>& dxds, FP s) {
dxds.resizeLike(x); // do_step calls sys with a vector of size 0 for some reason
f(x, s, dxds);
},
ytp1, t, dt);
Expand Down
18 changes: 16 additions & 2 deletions cpp/memilio/utils/custom_index_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ class CustomIndexArray
}

/**
* Resize all dimensions.
* @param new_dims new dimensions.
* @brief Resize all dimensions.
' Note that when increasing the overall size, new values may be uninitialized.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
' Note that when increasing the overall size, new values may be uninitialized.
* Note that when increasing the overall size, new values may be uninitialized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when reducing multi-dim arrays? Is the form kept or do information get mixed?

E.g.

3x3 of
1 2 3
4 5 6
7 8 9
changing to 2x2 becomes
1 2
4 5
or rather
1 2
3 4
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The internal array is stored linearly and reduced (or extended) to the product of all dimensions. So your 3x3 matrix is really just an array (1 2 3 4 5 6 7 8 9), with matrix accessor. So resizing to 1x9 or 9x1 would leave the array untouched. If we cut that matrix to

  • 3x2, we get
    1 2
    3 4
    5 6
  • 3x1, we get
    1
    2
    3
  • 2x3, we get
    1 2 3
    4 5 6
  • 2x2, we get
    1 2
    3 4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that. Is that really expected behavior for a (new) user? Shouldn't we avoid sizing down with keeping the values as this is normally not what you what want when reducing dimensions?

* @param new_dims New dimensions.
*/
void resize(Index new_dims)
{
Expand All @@ -245,6 +246,19 @@ class CustomIndexArray
m_y.conservativeResize(m_numel);
}

/**
* @brief Resize all dimensions, destroying all values.
* This Version of resize should only be used when the CustomIndexArray contains non-movable and non-copyable
reneSchm marked this conversation as resolved.
Show resolved Hide resolved
* values, like atomics. New entries are all default initialized.
* @param new_dims New dimensions.
*/
void resize_destructive(Index new_dims)
{
m_dimensions = new_dims;
m_numel = product(m_dimensions);
m_y.resize(m_numel);
}

/**
* Resize a single dimension.
* @param new dimension.
Expand Down
46 changes: 16 additions & 30 deletions cpp/memilio/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,24 @@ inline void log(LogLevel level, spdlog::string_view_t fmt, const Args&... args)

} // namespace mio

/**
* @brief The fmt::formatter class provides formatting capabilities for the ad::gt1s<double>::type
* to help SPD log to handle it.
*/
template <>
struct fmt::formatter<ad::gt1s<double>::type> {
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return ctx.end();
}
template <typename FormatContext>
auto format(const ad::gt1s<double>::type& input, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}", ad::value(input));
}
};
mknaranja marked this conversation as resolved.
Show resolved Hide resolved
namespace ad
{
namespace internal
{

/**
* @brief The fmt::formatter class provides formatting capabilities for the ad::ga1s<double>::type
* to help SPD log to handle it.
* @brief Format AD types (like ad::gt1s<double>) using their value for logging with spdlog.
*
* If derivative information is needed as well, use `ad::derivative(...)` or define a `fmt::formatter<...>`.
*/
template <>
struct fmt::formatter<ad::ga1s<double>::type> {
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return ctx.end();
}
template <typename FormatContext>
auto format(const ad::ga1s<double>::type& input, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}", ad::value(input));
}
};
template <class FP, class DataHandler>
FP format_as(const active_type<FP, DataHandler>& ad_type)
{
// Note: the format_as function needs to be in the same namespace as the value it takes
return value(ad_type);
}

} // namespace internal
} // namespace ad

#endif // LOGGING_H
9 changes: 9 additions & 0 deletions cpp/memilio/utils/uncertain_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ class UncertainValue
std::unique_ptr<ParameterDistribution> m_dist;
};

/**
* @brief Format UncertainValues using their value for logging with spdlog.
*/
template <class FP>
double format_as(const UncertainValue<FP>& uv)
mknaranja marked this conversation as resolved.
Show resolved Hide resolved
{
return uv;
}

// gtest printer
// TODO: should be extended when UncertainValue gets operator== that compares distributions as well
template <typename FP = double>
Expand Down
8 changes: 5 additions & 3 deletions cpp/models/abm/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ void Model::build_exposure_caches()
m_contact_exposure_rates_cache.resize(num_locations);
PRAGMA_OMP(taskloop)
for (size_t i = 0; i < num_locations; i++) {
m_air_exposure_rates_cache[i].resize({CellIndex(m_locations[i].get_cells().size()), VirusVariant::Count});
m_contact_exposure_rates_cache[i].resize({CellIndex(m_locations[i].get_cells().size()), VirusVariant::Count,
AgeGroup(parameters.get_num_groups())});
m_air_exposure_rates_cache[i].resize_destructive(
{CellIndex(m_locations[i].get_cells().size()), VirusVariant::Count});
m_contact_exposure_rates_cache[i].resize_destructive({CellIndex(m_locations[i].get_cells().size()),
VirusVariant::Count,
AgeGroup(parameters.get_num_groups())});
} // implicit taskloop barrier
m_are_exposure_caches_valid = false;
m_exposure_caches_need_rebuild = false;
Expand Down
12 changes: 7 additions & 5 deletions cpp/tests/abm_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ mio::abm::Person make_test_person(mio::RandomNumberGenerator& rng, mio::abm::Loc
return p;
}

mio::abm::PersonId add_test_person(mio::abm::Model& model, mio::abm::LocationId loc_id,
mio::AgeGroup age, mio::abm::InfectionState infection_state, mio::abm::TimePoint t)
mio::abm::PersonId add_test_person(mio::abm::Model& model, mio::abm::LocationId loc_id, mio::AgeGroup age,
mio::abm::InfectionState infection_state, mio::abm::TimePoint t)
{
return model.add_person(
make_test_person(model.get_rng(), model.get_location(loc_id), age, infection_state, t, model.parameters));
Expand All @@ -49,14 +49,16 @@ void interact_testing(mio::abm::PersonalRandomNumberGenerator& personal_rng, mio
{
// allocate and initialize air exposures with 0
mio::abm::AirExposureRates local_air_exposure;
local_air_exposure.resize({mio::abm::CellIndex(location.get_cells().size()), mio::abm::VirusVariant::Count});
mknaranja marked this conversation as resolved.
Show resolved Hide resolved
local_air_exposure.resize_destructive(
{mio::abm::CellIndex(location.get_cells().size()), mio::abm::VirusVariant::Count});
std::for_each(local_air_exposure.begin(), local_air_exposure.end(), [](auto& r) {
r = 0.0;
});
// allocate and initialize contact exposures with 0
mio::abm::ContactExposureRates local_contact_exposure;
local_contact_exposure.resize({mio::abm::CellIndex(location.get_cells().size()), mio::abm::VirusVariant::Count,
mio::AgeGroup(global_parameters.get_num_groups())});
local_contact_exposure.resize_destructive({mio::abm::CellIndex(location.get_cells().size()),
mio::abm::VirusVariant::Count,
mio::AgeGroup(global_parameters.get_num_groups())});
std::for_each(local_contact_exposure.begin(), local_contact_exposure.end(), [](auto& r) {
r = 0.0;
});
Expand Down
13 changes: 7 additions & 6 deletions cpp/tests/test_abm_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "models/abm/person.h"
#include "models/abm/trip_list.h"
#include "models/abm/model.h"
#include <bitset>
#include <cstddef>

#ifdef MEMILIO_HAS_JSONCPP
Expand Down Expand Up @@ -126,12 +127,12 @@ TEST(TestAbmSerialization, TestingScheme)
unsigned i = 1; // counter s.t. members have different values

Json::Value testing_criteria;
std::array<bool, mio::abm::MAX_NUM_AGE_GROUPS> ages_bits{}; // initialize to false
ages_bits[i++] = true;
testing_criteria["ages"]["bitset"] = mio::serialize_json(ages_bits).value();
std::array<bool, (size_t)mio::abm::InfectionState::Count> inf_st_bits{}; // initialize to false
inf_st_bits[i++] = true;
testing_criteria["infection_states"]["bitset"] = mio::serialize_json(inf_st_bits).value();
std::bitset<mio::abm::MAX_NUM_AGE_GROUPS> ages_bits{}; // initialize to false
ages_bits[i++] = true;
testing_criteria["ages"] = mio::serialize_json(ages_bits).value();
std::bitset<(size_t)mio::abm::InfectionState::Count> inf_st_bits{}; // initialize to false
inf_st_bits[i++] = true;
testing_criteria["infection_states"] = mio::serialize_json(inf_st_bits).value();

Json::Value test_parameters;
test_parameters["sensitivity"] = mio::serialize_json(mio::UncertainValue<double>{(double)i++}).value();
Expand Down
8 changes: 4 additions & 4 deletions cpp/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Versions of the bundled libraries
# If you like to upgrade, just change the number
set(MEMILIO_EIGEN_VERSION "3.3.9")
set(MEMILIO_SPDLOG_VERSION "1.11.0")
set(MEMILIO_EIGEN_VERSION "3.4.0")
set(MEMILIO_SPDLOG_VERSION "1.15.0")
set(MEMILIO_BOOST_VERSION "1.84.0")
set(MEMILIO_MINIMAL_BOOST_VERSION "1.76.0")
set(MEMILIO_JSONCPP_VERSION "1.9.5")
set(MEMILIO_JSONCPP_VERSION "1.9.6")
set(MEMILIO_RANDOM123_VERSION "v1.14.0")
set(MEMILIO_IPOPT_VERSION "3.14.12")

Expand Down Expand Up @@ -58,7 +58,7 @@ if(MEMILIO_USE_BUNDLED_EIGEN)
endif()

add_library(eigen INTERFACE)
target_include_directories(eigen INTERFACE ${eigen_SOURCE_DIR})
target_include_directories(eigen SYSTEM INTERFACE ${eigen_SOURCE_DIR})
add_library(Eigen3::Eigen ALIAS eigen)
else()
find_package(Eigen3 ${MEMILIO_EIGEN_VERSION} REQUIRED NO_MODULE)
Expand Down