Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision setting improvement #446

Merged
merged 8 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions models/spike_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ nest::spike_detector::spike_detector()
: Node()
// record time and gid
, device_( *this, RecordingDevice::SPIKE_DETECTOR, "gdf", true, true )
, user_set_precise_times_( false )
, has_proxies_( false )
, local_receiver_( true )
{
Expand All @@ -54,7 +53,6 @@ nest::spike_detector::spike_detector()
nest::spike_detector::spike_detector( const spike_detector& n )
: Node( n )
, device_( *this, n.device_ )
, user_set_precise_times_( n.user_set_precise_times_ )
, has_proxies_( false )
, local_receiver_( true )
{
Expand All @@ -80,21 +78,34 @@ nest::spike_detector::init_buffers_()
void
nest::spike_detector::calibrate()
{
if ( !user_set_precise_times_
&& kernel().event_delivery_manager.get_off_grid_communication() )

if ( kernel().event_delivery_manager.get_off_grid_communication()
and not device_.is_precise_times_user_set() )
{
device_.set_precise( true, 15 );

LOG( M_INFO,
"spike_detector::calibrate",
String::compose(
"Precise neuron models exist: the property precise_times "
"of the %1 with gid %2 has been set to true, precision has "
"been set to 15.",
get_name(),
get_gid() ) );
device_.set_precise_times( true );
std::string msg = String::compose(
"Precise neuron models exist: the property precise_times "
"of the %1 with gid %2 has been set to true",
get_name(),
get_gid() );

if ( device_.is_precision_user_set() )
{
// if user explicitly set the precision, there is no need to do anything.
msg += ".";
}

else
{
// it makes sense to increase the precision if precise models are used.
device_.set_precision( 15 );
msg += ", precision has been set to 15.";
}

LOG( M_INFO, "spike_detector::calibrate", msg );
}


device_.calibrate();
}

Expand Down Expand Up @@ -138,9 +149,6 @@ nest::spike_detector::get_status( DictionaryDatum& d ) const
void
nest::spike_detector::set_status( const DictionaryDatum& d )
{
if ( d->known( names::precise_times ) )
user_set_precise_times_ = true;

device_.set_status( d );
}

Expand Down
5 changes: 3 additions & 2 deletions models/spike_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ By default, GID and time of each spike is recorded.

The spike detector can also record spike times with full precision
from neurons emitting precisely timed spikes. Set /precise_times to
achieve this.
achieve this. If there are precise models and /precise_times is not
set, it will be set to True at the start of the simulation and
/precision will be increased to 15 from its default value of 3.

Any node from which spikes are to be recorded, must be connected to
the spike detector using a normal connect command. Any connection weight
Expand Down Expand Up @@ -182,7 +184,6 @@ class spike_detector : public Node
RecordingDevice device_;
Buffers_ B_;

bool user_set_precise_times_;
bool has_proxies_;
bool local_receiver_;
};
Expand Down
3 changes: 2 additions & 1 deletion models/spin_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ nest::spin_detector::calibrate()
if ( !user_set_precise_times_
&& kernel().event_delivery_manager.get_off_grid_communication() )
{
device_.set_precise( true, 15 );
device_.set_precise_times( true );
device_.set_precision( 15 );

LOG( M_INFO,
"spin_detector::calibrate",
Expand Down
16 changes: 14 additions & 2 deletions nestkernel/recording_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ nest::RecordingDevice::Parameters_::Parameters_( const std::string& file_ext,
, withgid_( withgid )
, withtime_( withtime )
, withweight_( withweight )
, user_set_precise_times_( false )
, user_set_precision_( false )
, precision_( 3 )
, scientific_( false )
, binary_( false )
Expand Down Expand Up @@ -153,9 +155,19 @@ nest::RecordingDevice::Parameters_::set( const RecordingDevice& rd,
updateValue< bool >( d, names::withweight, withweight_ );
updateValue< bool >( d, names::time_in_steps, time_in_steps_ );
if ( rd.mode_ == RecordingDevice::SPIKE_DETECTOR )
updateValue< bool >( d, names::precise_times, precise_times_ );
{
if ( d->known( names::precise_times ) )
{
user_set_precise_times_ = true;
updateValue< bool >( d, names::precise_times, precise_times_ );
}
}
updateValue< std::string >( d, names::file_extension, file_ext_ );
updateValue< long >( d, names::precision, precision_ );
if ( d->known( names::precision ) )
{
user_set_precision_ = true;
updateValue< long >( d, names::precision, precision_ );
}
updateValue< bool >( d, names::scientific, scientific_ );

updateValue< bool >( d, names::binary, binary_ );
Expand Down
38 changes: 36 additions & 2 deletions nestkernel/recording_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,16 @@ class RecordingDevice : public Device
return P_.to_accumulator_;
}

inline void set_precise( bool use_precise, long precision );
inline void set_precise_times( bool precise_times );

inline void set_precision( long precision );

inline bool records_precise_times() const;

inline bool is_precision_user_set() const;

inline bool is_precise_times_user_set() const;


private:
/**
Expand Down Expand Up @@ -449,6 +458,9 @@ class RecordingDevice : public Device
long precision_; //!< precision of doubles written to file
bool scientific_; //!< use scientific format if true, else fixed

bool user_set_precise_times_; //!< true if user set precise_times
bool user_set_precision_; //!< true if user set precision

bool binary_; //!< true if to write files in binary mode instead of ASCII
long fbuffer_size_; //!< the buffer size to use when writing to file
long fbuffer_size_old_; //!< the buffer size to use when writing
Expand Down Expand Up @@ -506,6 +518,23 @@ class RecordingDevice : public Device
Buffers_ V_;
};

inline bool
RecordingDevice::is_precision_user_set() const
{
return P_.user_set_precision_;
}

inline bool
RecordingDevice::is_precise_times_user_set() const
{
return P_.user_set_precise_times_;
}

inline bool
RecordingDevice::records_precise_times() const
{
return P_.precise_times_;
}

inline bool
RecordingDevice::is_active( Time const& T ) const
Expand All @@ -526,9 +555,14 @@ RecordingDevice::get_status( DictionaryDatum& d ) const
}

inline void
RecordingDevice::set_precise( bool use_precise, long precision )
RecordingDevice::set_precise_times( bool use_precise )
{
P_.precise_times_ = use_precise;
}

inline void
RecordingDevice::set_precision( long precision )
{
P_.precision_ = precision;
}

Expand Down
57 changes: 52 additions & 5 deletions testsuite/unittests/test_spike_detector.sli
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
Description:


FirstVersion: Jan 2008
First Version: Jan 2008
Author: Diesmann, Eppler

Second Version: Aug 2016
Description: added more tests
Author: Sepehr Mahmoudian
*/

(unittest) run
Expand Down Expand Up @@ -74,9 +78,34 @@ true exch {and} Fold % all equal ?

assert_or_die

% test the setting of the /precision value absent precise models
% 1. checking the default value and changing it

% Test the behavior of the /precise_times flag
% 1. if the user does not set it
ResetKernel
/spike_detector Create /sd Set

% is the default correctly set to 3?
sd GetStatus /precision get dup /p_val Set 3 eq assert_or_die

% is the precision still the same after simulating for some time?
100 Simulate
sd GetStatus /precision get p_val eq assert_or_die

% 2. setting Precision

ResetKernel
/spike_detector Create /sd Set

% can the precision be correctly set?
sd << /precision 15 >> SetStatus
sd GetStatus /precision get 15 eq assert_or_die

% is the precision the same after simulating?
100 Simulate
sd GetStatus /precision get 15 eq assert_or_die

% test the behavior of the /precise_times flag
% 3. if the user does not set it

ResetKernel
/spike_detector Create /sd Set
Expand All @@ -96,7 +125,10 @@ assert_or_die
100 Simulate
sd GetStatus /precise_times get true eq assert_or_die

% 2.a if the user sets the flag to false
% check if precision correctly increased to 15.
sd GetStatus /precision get 15 eq assert_or_die

% 4.a if the user sets the flag to false

ResetKernel
/spike_detector Create /sd Set
Expand All @@ -105,11 +137,26 @@ assert_or_die
100 Simulate
sd GetStatus /precise_times get false eq assert_or_die

% 2.b if the user sets the flag to true
% 4.b if the user sets the flag to true

ResetKernel
/spike_detector Create /sd Set
sd << /precise_times true >> SetStatus
/iaf_psc_exp_ps Create ;
100 Simulate
sd GetStatus /precise_times get true eq assert_or_die

% 5. can precision be set correctly when precise models exist?

ResetKernel
/spike_detector Create /sd Set

% checking to see if precision gets set correctly.
/iaf_psc_exp_ps Create ;
sd << /precision 15 >> SetStatus
sd GetStatus /precision get 15 eq assert_or_die

% does it remain the same after simulation?
100 Simulate
sd GetStatus /precision get 15 eq assert_or_die