SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
parameter_sweep.hpp
Go to the documentation of this file.
1 /*
2  * SNABSuite -- Spiking Neural Architecture Benchmark Suite
3  * Copyright (C) 2016 Christoph Jenzen
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #ifndef SNABSUITE_COMMON_PARAMETER_SWEEP
22 #define SNABSUITE_COMMON_PARAMETER_SWEEP
23 
24 #include <cypress/cypress.hpp>
25 
26 #include <fstream>
27 #include <memory>
28 #include <string>
29 
30 #include "common/snab_base.hpp"
31 
32 namespace SNAB {
33 
38 private:
39  // String containing the simulation backend
40  std::string m_backend;
41  // Sweep Configuration
42  cypress::Json m_sweep_config;
43  // Benchmark class
44  std::shared_ptr<SNABBase> m_snab;
45  // Shuffled indices
46  std::vector<size_t> m_indices;
47  // List of indices with jobs already done
48  std::vector<size_t> m_jobs_done;
49  // Vector containing all configuration files of a sweep
50  std::vector<cypress::Json> m_sweep_vector;
51  // Names and Keys for parameters swept over
52  std::vector<std::string> m_sweep_names;
53  // Vector containing all resulting json files
54  std::vector<std::vector<std::array<cypress::Real, 4>>> m_results;
55  // TODO: Number of repetitions for every simulation
56  size_t m_repetitions = 1;
57 
58  std::string m_file_name;
59 
60  // Number of threads for panellizing sweep
61  size_t m_n_threads = 1;
62 
67  void shuffle_sweep_indices(size_t size);
68 
75  void recover_broken_simulation();
76 
77 public:
92  ParameterSweep(std::string backend, cypress::Json &config,
93  size_t bench_index = 0, size_t threads = 1);
94 
98  void execute();
99 
110  static std::vector<cypress::Json> generate_sweep_vector(
111  const cypress::Json &source, const cypress::Json &target,
112  std::vector<std::string> &sweep_names);
113 
118  void write_csv();
125 
130  ~ParameterSweep();
131 };
132 } // namespace SNAB
133 
134 #endif
static std::vector< cypress::Json > generate_sweep_vector(const cypress::Json &source, const cypress::Json &target, std::vector< std::string > &sweep_names)
void backup_simulation_results()
ParameterSweep(std::string backend, cypress::Json &config, size_t bench_index=0, size_t threads=1)