SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
snab_base.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_SNAB_BASE_HPP
22 #define SNABSUITE_COMMON_SNAB_BASE_HPP
23 
24 #include <cypress/cypress.hpp>
25 #include <string>
26 
27 namespace SNAB {
33 class SNABBase {
34 public:
52  SNABBase(std::string name, std::string backend,
53  std::initializer_list<std::string> indicator_names,
54  std::initializer_list<std::string> indicator_types,
55  std::initializer_list<std::string> indicator_measures,
56  std::initializer_list<std::string> indicator_units,
57  std::initializer_list<std::string> required_parameters,
58  size_t bench_index);
59 
70  virtual cypress::Network &build_netw(cypress::Network &network) = 0;
71 
77  cypress::Network &build() { return build_netw(m_netw); };
78 
85  virtual void run_netw(cypress::Network &network) = 0;
86 
91  void run() { run_netw(m_netw); };
92 
98  const std::string snab_name() const { return m_snab_name; }
99 
106  const std::vector<std::string> &indicator_names() const
107  {
108  return m_indicator_names;
109  }
110 
117  const std::vector<std::string> &indicator_types() const
118  {
119  return m_indicator_types;
120  }
121 
128  const std::vector<std::string> &indicator_measures() const
129  {
130  return m_indicator_measures;
131  }
132 
139  virtual std::vector<std::array<cypress::Real, 4>> evaluate() = 0;
140 
147  cypress::Json evaluate_json();
148 
154  cypress::Json get_config() const { return m_config_file; }
155 
163  void set_config(cypress::Json json) { m_config_file = json; }
164 
170  void reset_network() { m_netw = cypress::Network(); }
171 
179  bool valid() const { return m_valid; }
180 
184  virtual std::shared_ptr<SNABBase> clone() = 0;
185 
190  virtual ~SNABBase() {}
191 
192 protected:
197  cypress::Network m_netw;
198 
204  cypress::Json m_config_file;
205 
210  std::string m_backend;
211 
217  bool m_valid = false;
218 
222  const std::string m_snab_name;
223 
231  const std::vector<std::string> m_indicator_names;
232 
237  const std::vector<std::string> m_indicator_types;
238 
244  const std::vector<std::string> m_indicator_measures;
245 
250  const std::vector<std::string> m_indicator_units;
251 
258  std::string _debug_filename(const std::string append = std::string()) const;
259 
260  const size_t m_bench_index;
261 };
262 
266 cypress::Real NaN();
267 } // namespace SNAB
268 
269 #endif /* SNABSUITE_COMMON_SNAB_BASE_HPP */
cypress::Json evaluate_json()
The result of evaluation() is converted into the format used by the HBP benchmark repository...
cypress::Json get_config() const
Getter for the config file.
Definition: snab_base.hpp:154
virtual std::vector< std::array< cypress::Real, 4 > > evaluate()=0
This should contain the evaluation process and return the result in order of those in names()...
cypress::Json m_config_file
Platform specific config file which is read in with the constructor.
Definition: snab_base.hpp:204
std::string m_backend
String which contains the name of the simulation backend.
Definition: snab_base.hpp:210
void set_config(cypress::Json json)
Setting a new config file. Note that before building the new network you probably want to reset the n...
Definition: snab_base.hpp:163
const std::vector< std::string > m_indicator_types
indicator_types can be e.g. "quality", "performance", "energy consumption". See also SNABBase::indica...
Definition: snab_base.hpp:237
virtual cypress::Network & build_netw(cypress::Network &network)=0
Building the neural network for benchmarking. If you want to use an external network, you should use the first version of building (and the corresponding run function), for the member network use the second function. The implementation is contained in the first one.
const std::string m_snab_name
The name of the Benchmark/SNAB.
Definition: snab_base.hpp:222
cypress::Network & build()
Calls SNABBase::build_netw with the internal network.
Definition: snab_base.hpp:77
virtual ~SNABBase()
Default destructor.
Definition: snab_base.hpp:190
Virtual Base class for SNABs(Benchmarks). All SNABs should have seperate building of networks...
Definition: snab_base.hpp:33
std::string _debug_filename(const std::string append=std::string()) const
Beginning of the filename of all debug data (including directories)
cypress::Network m_netw
Internal spiking network which should be used by the SNAB.
Definition: snab_base.hpp:197
const std::vector< std::string > m_indicator_names
For formatting the output in the correct structure introduced in the SP9 Guidebook, the evaluation process needs the exact order of the names, types and measures of the results returned from the function SNABBase::evaluate(). indicator_names should be unique for the measurement and represent the idea behind the value.
Definition: snab_base.hpp:231
cypress::Real NaN()
Used to indicate bad or invalid results.
const std::vector< std::string > & indicator_measures() const
Getter for SNABSSuite::m_indicator_measures.
Definition: snab_base.hpp:128
const std::vector< std::string > & indicator_names() const
Getter for SNABSSuite::m_indicator_names.
Definition: snab_base.hpp:106
void reset_network()
Reset the internal cypress network, therefore deleting all old populations. For example in several co...
Definition: snab_base.hpp:170
const std::vector< std::string > m_indicator_units
indicator_units should be the "unit of the measurement", therefore the unit of the value...
Definition: snab_base.hpp:250
const std::vector< std::string > & indicator_types() const
Getter for SNABSSuite::m_indicator_types.
Definition: snab_base.hpp:117
bool m_valid
Flag which tracks whether the SNAB can be executed on the backend This can be set in config file by s...
Definition: snab_base.hpp:217
const std::vector< std::string > m_indicator_measures
indicator_measures should be the "type of the measurement", or what has been measures, e.g. norm, p-value, time. See also SNABBase::indicator_names.
Definition: snab_base.hpp:244
bool valid() const
Returns the state of the m_valid flag. Simulation should not be executed when valid() returns false...
Definition: snab_base.hpp:179
virtual std::shared_ptr< SNABBase > clone()=0
Virtual method cloning the SNAB without knowing which SNAB it is.
virtual void run_netw(cypress::Network &network)=0
void run()
Calls SNABBase::run_netw on the internal network.
Definition: snab_base.hpp:91
SNABBase(std::string name, std::string backend, std::initializer_list< std::string > indicator_names, std::initializer_list< std::string > indicator_types, std::initializer_list< std::string > indicator_measures, std::initializer_list< std::string > indicator_units, std::initializer_list< std::string > required_parameters, size_t bench_index)
Constructor which reads in platform specific config file For description of the indicator initializer...
const size_t m_bench_index
Definition: snab_base.hpp:260
const std::string snab_name() const
Returns the name of the current benchmark.
Definition: snab_base.hpp:98