NEST main@f146f75
Loading...
Searching...
No Matches
connector_model_impl.h
Go to the documentation of this file.
1/*
2 * connector_model_impl.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef CONNECTOR_MODEL_IMPL_H
24#define CONNECTOR_MODEL_IMPL_H
25
26#include "connector_model.h"
27
28// Generated includes:
29#include "config.h"
30
31// Includes from libnestutil:
32#include "compose.hpp"
33#include "enum_bitfield.h"
34
35// Includes from nestkernel:
36#include "connection.h"
37#include "connector_base.h"
38#include "delay_checker.h"
39#include "delay_types.h"
40#include "kernel_manager.h"
41#include "nest_time.h"
42#include "nest_timeconverter.h"
44
45
46namespace nest
47{
48
49template < typename ConnectionT >
52{
53 ConnectorModel* new_cm = new GenericConnectorModel( *this, name ); // calls copy construtor
54 new_cm->set_syn_id( syn_id );
55
56 const bool is_primary = new_cm->has_property( ConnectionModelProperties::IS_PRIMARY );
57 if ( not is_primary )
58 {
59 new_cm->get_secondary_event()->add_syn_id( syn_id );
60 }
61
62 return new_cm;
63}
64
65template < typename ConnectionT >
66void
68{
69 // calibrate the delay of the default properties here
70 default_connection_.calibrate( tc );
71
72 // Calibrate will be called after a change in resolution, when there are no
73 // network elements present.
74
75 // calibrate any time objects that might reside in CommonProperties
76 cp_.calibrate( tc );
77}
78
79template < typename ConnectionT >
80void
82{
83 // first get properties common to all synapses
84 // these are stored only once (not within each Connection)
85 cp_.get_status( d );
86
87 // then get default properties for individual synapses
88 default_connection_.get_status( d );
89
90 d[ names::receptor_type ] = static_cast< long >( receptor_type_ );
92 d[ names::synapse_modelid ] = static_cast< long >( kernel().model_manager.get_synapse_model_id( name_ ) );
95}
96
97template < typename ConnectionT >
98void
100{
101 d.update_integer_value( names::receptor_type, receptor_type_ );
102#ifdef HAVE_MUSIC
103 // We allow music_channel as alias for receptor_type during connection setup
104 d.update_integer_value( names::music_channel, receptor_type_ );
105#endif
106
107 // If the parameter dict d contains /delay, this should set the delay
108 // on the default connection, but not affect the actual min/max_delay
109 // until a connection with that default delay is created. Since the
110 // set_status calls on common properties and default connection may
111 // modify min/max delay, we need to freeze the min/max_delay checking.
112
114
115 cp_.set_status( d, *this );
116
117 default_connection_.set_status( d, *this );
118
120
121 // we've possibly just got a new default delay. So enforce checking next time it is used
123}
124
125template < typename ConnectionT >
126void
128{
129 // This is called just once per Connect() call, so we need not worry much about performance.
130 // We get a dictionary with synapse default values and check if any of its keys are in syn_spec.
131 Dictionary dummy;
132 cp_.get_status( dummy );
133
134 for ( [[maybe_unused]] const auto& [ key, val ] : syn_spec )
135 {
136 if ( dummy.known( key ) )
137 {
138 throw NotImplemented(
139 String::compose( "Synapse parameter \"%1\" can only be set via SetDefaults() or CopyModel().", key ) );
140 }
141 }
142
143 default_connection_.check_synapse_params( syn_spec );
144}
145
146
147template < typename ConnectionT >
148void
150{
151 // if not used before, check now. Solves bug #138, MH 08-01-08
152 // replaces whole delay checking for the default delay, see bug #217
153 // MH 08-04-24
154 // get_default_delay_ must be overridden by derived class to return the
155 // correct default delay (either from commonprops or default connection)
157 {
158 try
159 {
161 {
162 const double d = default_connection_.get_delay_ms();
164 }
165 // Let connections without delay contribute to the delay extrema with
166 // wfr_comm_interval. For those connections the min_delay is important
167 // as it determines the length of the global communication interval.
168 // The call to assert_valid_delay_ms needs to happen only once
169 // (either here or in add_connection()) when the first connection
170 // without delay is created.
171 else
172 {
173 const double wfr_comm_interval = kernel().simulation_manager.get_wfr_comm_interval();
175 }
176 }
177 catch ( BadDelay& e )
178 {
179 throw BadDelay( default_connection_.get_delay_ms(),
180 String::compose( "Default delay of '%1' must be between min_delay %2 and max_delay %3.",
181 get_name(),
182 Time::delay_steps_to_ms( kernel().connection_manager.get_min_delay() ),
183 Time::delay_steps_to_ms( kernel().connection_manager.get_max_delay() ) ) );
184 }
186 }
187}
188
189template < typename ConnectionT >
190size_t
195
196template < typename ConnectionT >
197void
202
203template < typename ConnectionT >
204void
206{
207 if constexpr ( std::is_base_of< Connection< TargetIdentifierPtrRport, AxonalDendriticDelay >, ConnectionT >::value
208 or std::is_base_of< Connection< TargetIdentifierIndex, AxonalDendriticDelay >, ConnectionT >::value )
209 {
210 if ( syn_params.known( names::delay ) )
211 {
212 throw BadParameter( "Synapse type does not support explicitly setting total transmission delay." );
213 }
214 }
215 else
216 {
217 if ( syn_params.known( names::dendritic_delay ) )
218 {
219 throw BadParameter( "Synapse type does not support explicitly setting dendritic delay." );
220 }
221 if ( syn_params.known( names::axonal_delay ) )
222 {
223 throw BadParameter( "Synapse type does not support explicitly setting axonal delay." );
224 }
225 }
226}
227
228template < typename ConnectionT >
229void
231 Node& tgt,
232 std::vector< ConnectorBase* >& thread_local_connectors,
233 const synindex syn_id,
234 const Dictionary& p,
235 const double delay,
236 const double dendritic_delay,
237 const double axonal_delay,
238 const double weight )
239{
240 // create a new instance of the default connection
241 ConnectionT connection = ConnectionT( default_connection_ );
242
243 bool default_delay_used = true;
244
246 {
247 if constexpr ( std::is_base_of< Connection< TargetIdentifierPtrRport, AxonalDendriticDelay >, ConnectionT >::value
248 or std::is_base_of< Connection< TargetIdentifierIndex, AxonalDendriticDelay >, ConnectionT >::value )
249 {
250 if ( not numerics::is_nan( delay ) )
251 {
252 throw BadProperty( "Setting the total transmission delay via the parameter '" + names::delay
253 + "' is not allowed for synapse types which use both dendritic and axonal delays, because of ambiguity." );
254 }
255
256 if ( not p.empty() )
257 {
258 if ( p.known( names::delay ) )
259 {
260 throw BadProperty( "Setting the total transmission delay via the parameter '" + names::delay
261 + "' is not allowed for synapse types which use both dendritic and axonal delays, because of ambiguity." );
262 }
263
264 if ( not numerics::is_nan( dendritic_delay ) and p.known( names::dendritic_delay ) )
265 {
266 throw BadParameter(
267 "Parameter dictionary must not contain dendritic delay if dendritic delay is given explicitly." );
268 }
269
270 if ( not numerics::is_nan( axonal_delay ) and p.known( names::axonal_delay ) )
271 {
272 throw BadParameter(
273 "Parameter dictionary must not contain axonal delay if axonal delay is given explicitly." );
274 }
275 }
276
277 double actual_dendritic_delay = dendritic_delay;
278 double actual_axonal_delay = axonal_delay;
279 if ( not numerics::is_nan( dendritic_delay )
280 or ( not p.empty() and p.update_value( names::dendritic_delay, actual_dendritic_delay ) ) )
281 {
282 connection.set_dendritic_delay_ms( actual_dendritic_delay );
283 }
284 if ( not numerics::is_nan( axonal_delay )
285 or ( not p.empty() and p.update_value( names::axonal_delay, actual_axonal_delay ) ) )
286 {
287 connection.set_axonal_delay_ms( actual_axonal_delay );
288 }
289 if ( not numerics::is_nan( actual_dendritic_delay ) or not numerics::is_nan( actual_axonal_delay ) )
290 {
291 default_delay_used = false;
292 }
293 }
294 else
295 {
296 if ( not numerics::is_nan( dendritic_delay ) )
297 {
298 throw BadParameter( "Synapse type does not support explicitly setting dendritic delay." );
299 }
300
301 if ( not numerics::is_nan( axonal_delay ) )
302 {
303 throw BadParameter( "Synapse type does not support explicitly setting axonal delay." );
304 }
305
306 double actual_delay = delay;
307 if ( not p.empty() )
308 {
309 if ( p.known( names::dendritic_delay ) )
310 {
311 throw BadParameter( "Synapse type does not support explicitly setting dendritic delay." );
312 }
313
314 if ( p.known( names::axonal_delay ) )
315 {
316 throw BadParameter( "Synapse type does not support explicitly setting axonal delay." );
317 }
318
319 if ( p.update_value( names::delay, actual_delay ) )
320 {
321 if ( not numerics::is_nan( delay ) )
322 {
323 throw BadParameter( "Parameter dictionary must not contain delay if delay is given explicitly." );
324 }
325 connection.set_delay_ms( actual_delay );
326 default_delay_used = false;
327 }
328 else if ( not numerics::is_nan( delay ) )
329 {
330 connection.set_delay_ms( delay );
331 default_delay_used = false;
332 }
333 }
334 else if ( not numerics::is_nan( delay ) )
335 {
336 connection.set_delay_ms( delay );
337 default_delay_used = false;
338 }
339 }
340 }
341 else
342 {
343 if ( not numerics::is_nan( delay ) or not numerics::is_nan( dendritic_delay )
344 or not numerics::is_nan( axonal_delay ) )
345 {
346 throw BadProperty( "Delay specified for a connection type which doesn't use delays." );
347 }
348 if ( not p.empty()
349 and ( p.known( names::delay ) or p.known( names::dendritic_delay ) or p.known( names::axonal_delay ) ) )
350 {
351 throw BadProperty( "Delay specified for a connection type which doesn't use delays." );
352 }
353 }
354
355 if ( not numerics::is_nan( weight ) )
356 {
357 connection.set_weight( weight );
358 }
359
360 if ( not p.empty() )
361 {
362 // Reference to connector model needed here to check delay (maybe this could be done one level above?).
363 connection.set_status( p, *this );
364 }
365
366 // Checking a delay the connection did not set would re-check the model default on every connection.
367 if ( default_delay_used )
368 {
370 }
372 {
373 kernel().connection_manager.get_delay_checker().assert_valid_delay_ms( connection.get_delay_ms() );
374 }
375
376 // We must use a local variable here to hold the actual value of the
377 // receptor type. We must not change the receptor_type_ data member, because
378 // that represents the *default* value. See #921.
379 size_t actual_receptor_type = receptor_type_;
380#ifdef HAVE_MUSIC
381 // We allow music_channel as alias for receptor_type during connection setup
382 p.update_integer_value( names::music_channel, actual_receptor_type );
383#endif
384 p.update_integer_value( names::receptor_type, actual_receptor_type );
385 assert( syn_id != invalid_synindex );
386
387 if ( not thread_local_connectors[ syn_id ] )
388 {
389 // No homogeneous Connector with this syn_id exists, we need to create a new
390 // homogeneous Connector.
391 thread_local_connectors[ syn_id ] = new Connector< ConnectionT >( syn_id );
392 }
393
394 ConnectorBase* connector = thread_local_connectors[ syn_id ];
395 // The following line will throw an exception, if it does not work.
396 connection.check_connection( src, tgt, actual_receptor_type, syn_id, get_common_properties() );
397
398 assert( connector );
399
400 Connector< ConnectionT >* vc = static_cast< Connector< ConnectionT >* >( connector );
401 vc->push_back( std::move( connection ) );
402}
403
404} // namespace nest
405
406#endif
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
bool known(const std::string &key) const
Check whether there exists a value with specified key in the dictionary.
Definition dictionary.h:677
Exception to be thrown if an invalid delay is used in a connection.
Definition exceptions.h:583
Exception to be thrown if a parameter cannot be set.
Definition exceptions.h:717
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition exceptions.h:680
DelayChecker & get_delay_checker()
Returns the delay checker for the current thread.
Definition connection_manager.cpp:214
Base class to allow storing Connectors for different synapse types in vectors.
Definition connector_base.h:66
Definition connector_model.h:69
bool has_property(const ConnectionModelProperties &property) const
Definition connector_model.h:136
std::string name_
name of the ConnectorModel
Definition connector_model.h:148
std::string get_name() const
Definition connector_model.h:130
ConnectorModel(const std::string, const ConnectionModelProperties &properties)
Definition connector_model.cpp:28
virtual void set_syn_id(synindex syn_id)=0
virtual std::unique_ptr< SecondaryEvent > get_secondary_event()=0
bool default_delay_needs_check_
indicates whether the default delay must be checked
Definition connector_model.h:149
Homogeneous connector, contains synapses of one particular type (syn_id_).
Definition connector_base.h:232
void push_back(const ConnectionT &c)
Definition connector_base.h:300
void assert_valid_delay_ms(double)
Raise exception if delay value in milliseconds is invalid.
Definition delay_checker.cpp:149
void enable_delay_update()
This method enables the min/ max delay update in SetDefaults of connections method.
Definition delay_checker.h:127
void freeze_delay_update()
This method freezes the min/ max delay update in SetDefaults of connections method.
Definition delay_checker.h:121
void add_connection(Node &src, Node &tgt, std::vector< ConnectorBase * > &hetconn, const synindex syn_id, const Dictionary &d, const double delay, const double dendritic_delay, const double axonal_delay, const double weight) override
Adds a connection.
Definition connector_model_impl.h:230
void check_valid_default_delay_parameters(const Dictionary &syn_params) const override
Definition connector_model_impl.h:205
void used_default_delay()
Definition connector_model_impl.h:149
size_t get_syn_id() const override
Definition connector_model_impl.h:191
ConnectionT::CommonPropertiesType cp_
Definition connector_model.h:158
synindex syn_id_
Definition connector_model.h:162
ConnectionT default_connection_
Definition connector_model.h:160
void set_syn_id(synindex syn_id) override
Definition connector_model_impl.h:198
ConnectionT::CommonPropertiesType const & get_common_properties() const override
Definition connector_model.h:199
void calibrate(const TimeConverter &tc) override
Definition connector_model_impl.h:67
ConnectorModel * clone(std::string, synindex) const override
Definition connector_model_impl.h:51
size_t receptor_type_
Definition connector_model.h:161
GenericConnectorModel(const std::string name)
Definition connector_model.h:165
void check_synapse_params(const Dictionary &syn_spec) const override
Checks to see if illegal parameters are given in syn_spec.
Definition connector_model_impl.h:127
void get_status(Dictionary &) const override
Definition connector_model_impl.h:81
void set_status(const Dictionary &) override
Definition connector_model_impl.h:99
size_t get_synapse_model_id(std::string model_name)
Definition model_manager.cpp:321
Base class for all NEST network objects.
Definition node.h:99
Exception to be thrown if a feature is unavailable.
Definition exceptions.h:108
double get_wfr_comm_interval() const
Get the desired communication interval for the waveform relaxation.
Definition simulation_manager.h:325
Class to convert times from one representation to another.
Definition nest_timeconverter.h:42
static double delay_steps_to_ms(long steps)
Convert between delays given in steps and milliseconds.
Definition nest_time.h:529
ConnectionManager connection_manager
Definition kernel_manager.h:239
ModelManager model_manager
Definition kernel_manager.h:243
SimulationManager simulation_manager
Definition kernel_manager.h:237
const std::string delay("delay")
const std::string axonal_delay("axonal_delay")
const std::string receptor_type("receptor_type")
const std::string has_delay("has_delay")
const std::string synapse_modelid("synapse_modelid")
const std::string requires_symmetric("requires_symmetric")
const std::string synapse_model("synapse_model")
const std::string dendritic_delay("dendritic_delay")
const std::string music_channel("music_channel")
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
constexpr synindex invalid_synindex
Definition nest_types.h:122
KernelManager & kernel()
Definition kernel_manager.h:311
@ REQUIRES_SYMMETRIC
Definition connector_model.h:56
@ HAS_DELAY
Definition connector_model.h:54
@ IS_PRIMARY
Definition connector_model.h:53
size_t synindex
For enumerations of synapse types.
Definition nest_types.h:121
bool is_nan(T f)
Definition numerics.h:51