BioDynaMo  v1.05.119-a4ff3934
parameter_sweep.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #include <json.hpp>
16 
22 #include "core/simulation.h"
23 
24 using nlohmann::json;
25 
26 namespace bdm {
27 namespace experimental {
28 
30 struct ParameterSweep : public Algorithm {
32 
34  Param* default_params) override {
35  auto sweeping_params = default_params->Get<OptimizationParam>()->params;
36 
37  if (sweeping_params.empty()) {
38  Log::Error("ParameterSweep", "No sweeping parameters found!");
39  return;
40  }
41 
42  DynamicNestedLoop(sweeping_params, [&](const std::vector<uint32_t>& slots) {
43  json j_patch;
44 
45  int i = 0;
46  for (auto* param : sweeping_params) {
47  j_patch[param->GetGroupName()][param->GetParamName()] =
48  param->GetValue(slots[i]);
49  i++;
50  }
51 
52  Param final_params = *default_params;
53  final_params.MergeJsonPatch(j_patch.dump());
54 
55  dispatch_experiment(&final_params, nullptr);
56  });
57  };
58 };
59 
60 BDM_REGISTER_ALGO(ParameterSweep);
61 
62 } // namespace experimental
63 } // namespace bdm
bdm::experimental::ParameterSweep
Perform an exhaustive sweep across specified parameters.
Definition: parameter_sweep.cc:30
bdm
Definition: agent.cc:39
algorithm_registry.h
bdm::experimental::Algorithm
An interface for creating new optimization algorithms.
Definition: algorithm.h:30
optimization_param.h
mpi_helper.h
bdm::Param::Get
const TParamGroup * Get() const
Definition: param.h:59
bdm::Functor
Definition: functor.h:24
bdm::OptimizationParam
Definition: optimization_param.h:24
bdm::experimental::BDM_REGISTER_ALGO
BDM_REGISTER_ALGO(ParameterSweep)
bdm::Param::MergeJsonPatch
void MergeJsonPatch(const std::string &patch)
Definition: param.cc:126
bdm::Log::Error
static void Error(const std::string &location, const Args &... parts)
Prints error message.
Definition: log.h:79
algorithm.h
simulation.h
bdm::experimental::DynamicNestedLoop
void DynamicNestedLoop(const std::vector< OptimizationParamType * > &containers, const Lambda &action)
Definition: dynamic_loop.h:30
bdm::experimental::ParameterSweep::BDM_ALGO_HEADER
BDM_ALGO_HEADER()
bdm::Param
Definition: param.h:35
bdm::experimental::ParameterSweep::operator()
void operator()(Functor< void, Param *, TimeSeries * > &dispatch_experiment, Param *default_params) override
Definition: parameter_sweep.cc:33
dynamic_loop.h