Example #1
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()
        
        objects = [ 1,           # int
                    3.14,        # double
                    1e-4,        # double
                    -100,        # negative
                    'string',    # string
                    {'key':123}, # dict
                    [1,2,3,4,5], # list
                    ]

        for o in objects:
            nest.sps(o)
            self.assertEqual(o, nest.spp())

        try:
            import numpy
            arr = numpy.array([[1,2,3,4,5],[6,7,8,9,0]])
            nest.sps(arr[1,:])
            self.assert_( (nest.spp() == numpy.array([6, 7, 8, 9, 0])).all())
            nest.sps(arr[:,1])
            self.assert_( (nest.spp() == numpy.array([2, 7])).all())
        except ImportError:
            pass # numpy's not required for pynest to work
Example #2
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = [
            1,  # int
            3.14,  # double
            1e-4,  # double
            -100,  # negative
            'string',  # string
            {
                'key': 123
            },  # dict
            [1, 2, 3, 4, 5],  # list
        ]

        for o in objects:
            nest.sps(o)
            self.assertEqual(o, nest.spp())

        try:
            import numpy
            arr = numpy.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 0]])
            nest.sps(arr[1, :])
            self.assert_((nest.spp() == numpy.array([6, 7, 8, 9, 0])).all())
            nest.sps(arr[:, 1])
            self.assert_((nest.spp() == numpy.array([2, 7])).all())
        except ImportError:
            pass  # numpy's not required for pynest to work
Example #3
0
    def _setup_music(self):
        """
        Setup music connection.
        """
        _nest.sli_run('statusdict/have_music ::')
        if not _nest.spp():
            print('NEST was not compiled with support for MUSIC, not running.')
            _sys.exit()

        # Setup music spike output.
        self._music_spike_output = _nest.Create('music_event_out_proxy', 1)
        _nest.SetStatus(self._music_spike_output,
                        {'port_name': self._spike_port_name})

        # Connecting neurons to music event channels. In case of the BBP
        # circuit, each channel corresponds to a gid.
        for gid, neuron in self._gid_to_neuron_map.items():
            _nest.Connect([neuron], self._music_spike_output, 'one_to_one',
                          {'music_channel': gid})

        # Connecting the last music channel (value specified in the
        # configuration file) to a dummy neuron
        dummy = _nest.Create('iaf_neuron', 1)
        _nest.Connect(dummy, self._music_spike_output, 'one_to_one',
                      {'music_channel': 10000000})

        # Setup music steering input.
        self._music_steering_input = _nest.Create('music_message_in_proxy', 1)
        _nest.SetStatus(self._music_steering_input,
                        {'port_name': self._steering_port_name,
                         'acceptable_latency': 40.0})
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = (
            (True, ) * 2,
            (False, ) * 2,

            (1, ) * 2,
            (-100, ) * 2,

            (3.14, ) * 2,
            (-1.7588e11, ) * 2,

            ('string', ) * 2,

            # Literals should be converted to SLI literals
            (nest.SLILiteral('test'), ) * 2,

            # Arrays are converted to tuples on the way out
            ((1, 2, 3, 4, 5), ) * 2,
            ([1, 2, 3, 4, 5], (1, 2, 3, 4, 5)),

            # Dictionary round trip conversion should be consistent
            ({'key': 123, 'sub_dict': {nest.SLILiteral('foo'): 'bar'}}, ) * 2,
        )

        for obj_in, obj_out in objects:
            nest.sps(obj_in)
            self.assertEqual(obj_out, nest.spp())
Example #5
0
    def _setup_music(self):
        """
        Setup music connection.
        """
        _nest.sli_run('statusdict/have_music ::')
        if not _nest.spp():
            print('NEST was not compiled with support for MUSIC, not running.')
            _sys.exit()

        # Setup music spike output.
        self._music_spike_output = _nest.Create('music_event_out_proxy', 1)
        _nest.SetStatus(self._music_spike_output,
                        {'port_name': self._spike_port_name})

        # Connecting neurons to music event channels. In case of the BBP
        # circuit, each channel corresponds to a gid.
        for gid, neuron in self._gid_to_neuron_map.items():
            _nest.Connect([neuron], self._music_spike_output, 'one_to_one',
                          {'music_channel': gid})

        # Setup music steering input.
        self._music_steering_input = _nest.Create('music_message_in_proxy', 1)
        _nest.SetStatus(self._music_steering_input, {
            'port_name': self._steering_port_name,
            'acceptable_latency': 40.0
        })
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')

        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99 - i))

        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
    def test_Count(self):
        """Object count"""

        nest.ResetKernel()
        nest.sr('clear')

        for i in range(100):
            nest.sps(i)

        nest.sr('count')
        self.assertEqual(nest.spp(), 100)

        for i in range(100):
            self.assertEqual(nest.spp(), (99 - i))

        nest.sr('count')
        self.assertEqual(nest.spp(), 0)
    def test_PushPop_no_NumPy(self):

        nest.ResetKernel()

        a1 = array('i', [1, 2, 3])
        a2 = array('l', [1, 2, 3])
        a3 = array('f', [1.0, 2.0, 3.0])
        a4 = array('d', [1.0, 2.0, 3.0])

        for x in (a1, a2, a3, a4):
            nest.sps(x)
            self.assertEqual(x, nest.spp())
    def test_PushPop_no_NumPy(self):

        nest.ResetKernel()

        a1 = array('i', [1, 2, 3])
        a2 = array('l', [1, 2, 3])
        a3 = array('f', [1.0, 2.0, 3.0])
        a4 = array('d', [1.0, 2.0, 3.0])

        for x in (a1, a2, a3, a4):
            nest.sps(x)
            self.assertEqual(x, nest.spp())
 def setUp(self):
     nest.ResetKernel()
     nest.sr("statusdict/threading :: (no) eq not")
     if not nest.spp():
         # no multi-threading
         nest.SetKernelStatus({'grng_seed': 120,
                               'rng_seeds': [576]})
     else:
         # multi-threading
         nest.SetKernelStatus({'local_num_threads': 2,
                               'grng_seed': 120,
                               'rng_seeds': [576, 886]})
     pass
 def setUp(self):
     nest.ResetKernel()
     nest.sr("statusdict/threading :: (no) eq not")
     if not nest.spp():
         # no multi-threading
         nest.SetKernelStatus({'grng_seed': 120,
                               'rng_seeds': [576]})
     else:
         # multi-threading
         nest.SetKernelStatus({'local_num_threads': 2,
                               'grng_seed': 120,
                               'rng_seeds': [576, 886]})
     pass
Example #12
0
    def test_PushPop_NumPy(self):

        nest.ResetKernel()

        # Test support for slices and strides
        arr = numpy.array(((1, 2, 3, 4, 5), (6, 7, 8, 9, 0)))

        nest.sps(arr[1, :])
        self.assertTrue((nest.spp() == numpy.array((6, 7, 8, 9, 0))).all())

        nest.sps(arr[:, 1])
        self.assertTrue((nest.spp() == numpy.array((2, 7))).all())

        # Test conversion using buffer interface
        nest.sps(array('l', [1, 2, 3]))
        self.assertTrue((nest.spp() == numpy.array((1, 2, 3))).all())

        nest.sps(array('d', [1., 2., 3.]))
        self.assertTrue((nest.spp() == numpy.array((1., 2., 3.))).all())

        # Test conversion without using buffer interface
        if hasattr(numpy, 'int16'):
            i16 = numpy.array((1, 2, 3), dtype=numpy.int16)
            nest.sps(i16)
            self.assertTrue((nest.spp() == i16).all())

        # Test support for scalars and zero-dimensional arrays
        a1 = numpy.array((1, 2, 3))[1]
        a2 = numpy.array((1., 2., 3.))[1]
        a3 = numpy.array(2)
        a4 = numpy.array(2.)

        for x in (a1, a3):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2)

        for x in (a2, a4):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2.)
    def test_PushPop_NumPy(self):

        nest.ResetKernel()

        # Test support for slices and strides
        arr = numpy.array(((1, 2, 3, 4, 5), (6, 7, 8, 9, 0)))

        nest.sps(arr[1, :])
        self.assertTrue((nest.spp() == numpy.array((6, 7, 8, 9, 0))).all())

        nest.sps(arr[:, 1])
        self.assertTrue((nest.spp() == numpy.array((2, 7))).all())

        # Test conversion using buffer interface
        nest.sps(array('l', [1, 2, 3]))
        self.assertTrue((nest.spp() == numpy.array((1, 2, 3))).all())

        nest.sps(array('d', [1., 2., 3.]))
        self.assertTrue((nest.spp() == numpy.array((1., 2., 3.))).all())

        # Test conversion without using buffer interface
        if hasattr(numpy, 'int16'):
            i16 = numpy.array((1, 2, 3), dtype=numpy.int16)
            nest.sps(i16)
            self.assertTrue((nest.spp() == i16).all())

        # Test support for scalars and zero-dimensional arrays
        a1 = numpy.array((1, 2, 3))[1]
        a2 = numpy.array((1., 2., 3.))[1]
        a3 = numpy.array(2)
        a4 = numpy.array(2.)

        for x in (a1, a3):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2)

        for x in (a2, a4):
            nest.sps(x)
            self.assertEqual(nest.spp(), 2.)
Example #14
0
    def test_PushPop(self):
        """Object push and pop"""

        nest.ResetKernel()

        objects = (
            (True, ) * 2,
            (False, ) * 2,
            (1, ) * 2,
            (-100, ) * 2,
            (3.14, ) * 2,
            (-1.7588e11, ) * 2,
            ('string', ) * 2,

            # Literals should be converted to SLI literals
            (
                nest.SLILiteral('test'), ) * 2,

            # Arrays are converted to tuples on the way out
            (
                (1, 2, 3, 4, 5), ) * 2,
            ([1, 2, 3, 4, 5], (1, 2, 3, 4, 5)),

            # Dictionary round trip conversion should be consistent
            (
                {
                    'key': 123,
                    'sub_dict': {
                        nest.SLILiteral('foo'): 'bar'
                    }
                }, ) * 2,
        )

        for obj_in, obj_out in objects:
            nest.sps(obj_in)
            self.assertEqual(obj_out, nest.spp())
Example #15
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST.  If not, see <http://www.gnu.org/licenses/>.

import nest

nest.sli_run("statusdict/have_music ::")
if not nest.spp():
    import sys
    print("NEST was not compiled with support for MUSIC, not running.")
    sys.exit()

nest.set_verbosity("M_ERROR")

sg = nest.Create('spike_generator')
nest.SetStatus(sg, {'spike_times': [1.0, 1.5, 2.0]})

n = nest.Create('iaf_neuron')

nest.Connect(sg, n, 'one_to_one', {'weight': 750.0, 'delay': 1.0})

vm = nest.Create('voltmeter')
nest.SetStatus(vm, {'to_memory': False, 'to_screen': True})
Example #16
0
    def nest_multithreaded(self):
        """Return True, if we have a thread-enabled NEST, False otherwise"""

        nest.sr("statusdict/threading :: (no) eq not")
        return nest.spp()
Example #17
0
def lambertwm1(x):
    '''Wrapper for LambertWm1 function'''
    nest.sr('{} LambertWm1'.format(x))
    return nest.spp()
Example #18
0
    def nest_multithreaded(self):
        """Return True, if we have a thread-enabled NEST, False otherwise"""

        nest.sr("statusdict/threading :: (no) eq not")
        return nest.spp()
Example #19
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST.  If not, see <http://www.gnu.org/licenses/>.

import nest

nest.sli_run("statusdict/have_music ::")
if not nest.spp():
    import sys

    print("NEST was not compiled with support for MUSIC, not running.")
    sys.exit()

mmip = nest.Create('music_message_in_proxy')
nest.SetStatus(mmip, {'port_name': 'msgdata'})

# Simulate and get message data with a granularity of 10 ms:
time = 0
while time < 1000:
    nest.Simulate(10)
    data = nest.GetStatus(mmip, 'data')
    print(data)
    time += 10
Example #20
0
def memory_thisjob():
    '''Wrapper to obtain current memory usage'''
    nest.sr('memory_thisjob')
    return nest.spp()
Example #21
0
def memory_thisjob():
    '''Wrapper to obtain current memory usage'''
    nest.sr('memory_thisjob')
    return nest.spp()
Example #22
0
def lambertwm1(x):
    '''Wrapper for LambertWm1 function'''
    nest.sr('{} LambertWm1'.format(x))
    return nest.spp()