Cypress  1.0
C++ Spiking Neural Network Simulation Framework
network_base.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2016 Andreas Stöckel
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 
31 #pragma once
32 
33 #ifndef CYPRESS_CORE_NETWORK_BASE_HPP
34 #define CYPRESS_CORE_NETWORK_BASE_HPP
35 
36 #include <memory>
37 #include <string>
38 #include <unordered_set>
39 #include <vector>
40 
42 #include <cypress/core/data.hpp>
44 #include <cypress/core/types.hpp>
45 #include <cypress/util/json.hpp>
46 
47 namespace cypress {
48 
49 /*
50  * Forward declarations
51  */
52 namespace internal {
53 class NetworkData;
54 }
55 
56 class Backend;
57 class NetworkBase;
58 class PopulationBase;
59 class PopulationViewBase;
60 class NeuronBase;
61 class Logger;
62 
63 template <typename Impl, typename Accessor>
65 
66 template <typename Impl, typename Accessor, typename Params, typename Signals>
67 class DataMixin;
68 
69 template <typename Impl, typename Accessor>
71 
80 
86 
91 
97 
103 
107  Real duration = 0;
108 };
109 
116 class NetworkBase {
117 private:
121  std::shared_ptr<internal::NetworkData> m_impl;
122 
123 protected:
124  template <typename Impl, typename Accessor>
125  friend class PopulationMixin;
126 
127  template <typename Impl, typename Accessor, typename Params,
128  typename Signals>
129  friend class DataMixin;
130 
131  template <typename Impl, typename Accessor>
132  friend class ConnectableMixin;
133 
152  void connect(PopulationIndex pid_src, NeuronIndex nid_src0,
153  NeuronIndex nid_src1, PopulationIndex pid_tar,
154  NeuronIndex nid_tar0, NeuronIndex nid_tar1,
155  std::unique_ptr<Connector> connector, const char *name = "");
156 
172  PopulationIndex create_population_index(size_t size, const NeuronType &type,
173  const NeuronParameters &params,
174  const NeuronSignals &signals,
175  const std::string &name);
176 
177 public:
181  NetworkBase();
182 
187  NetworkBase(std::shared_ptr<internal::NetworkData> impl) : m_impl(impl) {}
188 
193  ~NetworkBase();
194 
199  Logger &logger() const;
200 
205  void logger(Logger &logger);
206 
215  std::shared_ptr<PopulationData> population_data(PopulationIndex pid);
216 
225  std::shared_ptr<const PopulationData> population_data(
226  PopulationIndex pid) const;
227 
232  bool operator==(const NetworkBase &o) const { return m_impl == o.m_impl; }
233 
238  bool operator!=(const NetworkBase &o) const { return m_impl != o.m_impl; }
239 
243  NetworkBase clone() const;
244 
248  size_t population_count() const;
249 
253  size_t population_count(const NeuronType &type) const;
254 
258  template <typename T>
259  size_t population_count() const
260  {
261  return population_count(T::inst());
262  }
263 
267  size_t neuron_count() const;
268 
272  size_t neuron_count(const NeuronType &type) const;
273 
277  template <typename T>
278  size_t neuron_count() const
279  {
280  return neuron_count(T::inst());
281  }
282 
287  PopulationBase population(PopulationIndex pid);
288 
289  const PopulationBase population(PopulationIndex pid) const;
290 
291  PopulationBase operator[](PopulationIndex pid);
292 
293  const PopulationBase operator[](PopulationIndex pid) const;
294 
307  const std::vector<PopulationBase> populations(
308  const std::string &name = std::string(),
309  const NeuronType &type = NullNeuron::inst()) const;
310 
320  const std::vector<PopulationBase> populations(const NeuronType &type) const;
321 
330  PopulationBase population(const std::string &name = std::string());
331 
339  const std::vector<ConnectionDescriptor> &connections() const;
340 
348  const ConnectionDescriptor &connection(std::string name) const;
349 
350 
357  void update_connection(std::unique_ptr<Connector> connector, const char *name);
358 
377  static std::unique_ptr<Backend> make_backend(std::string backend_id,
378  int argc = 0,
379  const char *argv[] = nullptr,
380  Json setup = Json());
381 
387  bool use_lossy_trafos() const;
388 
394  void use_lossy_trafos(bool use_lossy) const;
395 
399  const std::unordered_set<std::string> &disabled_trafo_ids() const;
400 
404  std::unordered_set<std::string> &disabled_trafo_ids();
405 
417  void run(const Backend &backend, Real duration = 0.0);
418 
434  void run(const std::string &backend_id, Real duration = 0.0, int argc = 0,
435  const char *argv[] = nullptr);
436 
443  Real duration() const;
444 
449  NetworkRuntime runtime() const;
450 
454  void runtime(const NetworkRuntime &runtime);
455 };
456 }
457 
458 #endif /* CYPRESS_CORE_NETWORK_BASE_HPP */
Definition: neurons_base.hpp:54
static const NullNeuron & inst()
Definition: network_base.hpp:67
Definition: network_base_objects.hpp:241
int32_t NeuronIndex
Definition: types.hpp:74
Definition: network_base.hpp:64
Definition: backend.hpp:50
size_t neuron_count() const
Definition: network_base.hpp:278
Definition: network_base.hpp:70
Real sim_pure
Definition: network_base.hpp:102
Real initialize
Definition: network_base.hpp:90
double Real
Definition: types.hpp:56
Definition: neurons_base.hpp:151
NetworkBase(std::shared_ptr< internal::NetworkData > impl)
Definition: network_base.hpp:187
nlohmann::json Json
Definition: json.hpp:27
Definition: network_base.hpp:75
Real sim
Definition: network_base.hpp:85
bool operator==(const NetworkBase &o) const
Definition: network_base.hpp:232
bool operator!=(const NetworkBase &o) const
Definition: network_base.hpp:238
Definition: network_base.hpp:116
size_t population_count() const
Definition: network_base.hpp:259
Definition: network_base_objects.hpp:53
Definition: brainscales_lib.hpp:39
Definition: neurons_base.hpp:322
Real total
Definition: network_base.hpp:79
Definition: connector.hpp:705
int32_t PopulationIndex
Definition: types.hpp:75
Real finalize
Definition: network_base.hpp:96
Definition: logger.hpp:107