Skip to main content

PymoNNtorch

pymonntorch logo

https://img.shields.io/pypi/v/pymonntorch.svg Documentation Status

PymoNNtorch is a Pytorch-adapted version of PymoNNto.

Features

  • Use torch tensors and Pytorch-like syntax to create a spiking neural network (SNN).

  • Simulate an SNN on CPU or GPU.

  • Define dynamics of SNN components as Behavior modules.

  • Control over the order of applying different behaviors in each simulation time step.

Usage

You can use the same syntax as PymoNNto to create you network:

from pymonntorch import *

net = Network()
ng = NeuronGroup(net=net, tag="my_neuron", size=100, behavior=None)
SynapseGroup(src=ng, dst=ng, net=net, tag="recurrent_synapse")
net.initialize()
net.simulate_iterations(1000)

Similarly, you can write your own Behavior Modules with the same logic as PymoNNto; except using torch tensors instead of numpy ndarrays.

from pymonntorch import *

class BasicBehavior(Behavior):
    def initialize(self, neurons):
        super().initialize(neurons)
        neurons.voltage = neurons.vector(mode="zeros")
        self.threshold = 1.0

    def forward(self, neurons):
        firing = neurons.voltage >= self.threshold
        neurons.spike = firing.byte()
        neurons.voltage[firing] = 0.0 # reset

        neurons.voltage *= 0.9 # voltage decay
        neurons.voltage += neurons.vector(mode="uniform", density=0.1)

class InputBehavior(Behavior):
    def initialize(self, neurons):
        super().initialize(neurons)
        for synapse in neurons.afferent_synapses['GLUTAMATE']:
            synapse.W = synapse.matrix('uniform', density=0.1)
            synapse.enabled = synapse.W > 0

    def forward(self, neurons):
        for synapse in neurons.afferent_synapses['GLUTAMATE']:
            neurons.voltage += synapse.W@synapse.src.spike.float() / synapse.src.size * 10

net = Network()
ng = NeuronGroup(net=net,
                size=100,
                behavior={
                    1: BasicBehavior(),
                    2: InputBehavior(),
                    9: Recorder(['voltage']),
                    10: EventRecorder(['spike'])
                })
SynapseGroup(src=ng, dst=ng, net=net, tag='GLUTAMATE')
net.initialize()
net.simulate_iterations(1000)

import matplotlib.pyplot as plt

plt.plot(net['voltage',0][:, :10])
plt.show()

plt.plot(net['spike.t',0], net['spike.i',0], '.k')
plt.show()

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template. It changes the codebase of PymoNNto to use torch rather than numpy and tensorflow numpy.

History

0.1.4 (2024-03-16)

  • Bug fixes.

  • Src and dst can be None for syanpses.

  • Hierarchical structure.

0.1.3 (2023-08-16)

  • BREAKING CHANGE: Network no longer accept settings. Individual setting are now argument for Network.

  • Bug fixes.

0.1.2 (2023-06-14)

  • tensor method for NetworkObject

0.1.1 (2023-05-26)

  • Every NetworkObject can have a recorder behavior.

  • Network settings accept “index” entry.

  • Bug fixes and general improvement.

0.1.0 (2023-03-17)

  • Repository made public.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymonntorch-0.1.4.tar.gz (274.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymonntorch-0.1.4-py2.py3-none-any.whl (38.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pymonntorch-0.1.4.tar.gz.

File metadata

  • Download URL: pymonntorch-0.1.4.tar.gz
  • Upload date:
  • Size: 274.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pymonntorch-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9c82e5d263d462810cb0d435603de49cd14322a054bfa4dac2d45f7c8d2bdd72
MD5 98d2085b7a702f1e3f0e0c2355d1aebc
BLAKE2b-256 a97a86e6b0623a4420ec16f9c8da9e41ec7936feedd6d0c2a2c92a87f4fac478

See more details on using hashes here.

File details

Details for the file pymonntorch-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: pymonntorch-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pymonntorch-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 24a2240dc28ea38831a20ddb4fa193721ab24d01fe0e4e9929298fcff3f0c036
MD5 53350422c5ecb9e88df253bb9652029a
BLAKE2b-256 9f286f79264ca48faa626333bcf8f6bbf62f4ae39428957562462dea0371600c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page