Skip to content

emer/leabrapy

Repository files navigation

Python interface to emergent / Leabra

You can run the Go version of emergent via Python, using the gopy tool that automatically creates Python bindings for Go packages.

See the GoGi Python README for more details on how the python wrapper works and how to use it for GUI-level functionality. If you encounter any difficulties with this install, then try doing the install in GoGi first, and read more about the different install issues there.

See the .py versions of various projects in examples, and especially in the Comp Cog Neuro sims, for many examples of Python versions.

See etable pyet for example code for converting between the Go etable.Table and numpy, torch, and pandas table structures. All of the converted projects rely on etable because it provides a complete GUI interface for viewing and manipulating the data, but it is easy to convert any of these tables into Python-native formats (and copy back-and-forth). The pyet python library (in pyside and auto-installed with this package) has the necessary routines.

Installation

First, you have to install the Go version of emergent: Wiki Install.

Python version 3 (3.6-3.9 have been well tested) is recommended.

This assumes that you are using go modules, as discussed in the wiki install page, and that you are in the leabra directory where you installed leabra (e.g., git clone https://github.com/emer/leabra and then cd leabra)

NOTE: only a modules version of the build is supported, but it has some weirdness about updating the go.mod and go.sum files across the gopy and rest of the build. Pay attention to the output of the make command and if anything is downloaded during the gopy part of the build, it is a good idea to interrupt the go build process (hit Ctrl-C) and start over again, until there are no downloading messages -- then everything should be included properly.

Do NOT do a go mod tidy (which is normally the right thing to do to fix up your go.mod file and download packages) because the context in which that needs to be done involves the files generated by gopy (in the leabra subdir -- safe to do there after gopy runs), not what is present in the python directory where you type make.

$ cd python     # should be in leabra/python now -- i.e., the dir where this README.md is..
$ make          # may need to run multiple times, due to go.mod and go.sum updating and downloading
$ make install  # may need to do: sudo make install -- installs into /usr/local/bin and python site-packages
$ cd ../examples/ra25
$ ./ra25.py     # runs using magic code on first line of file -- alternatively:
$ pyleabra -i ra25.py   # pyleabra was installed during make install into /usr/local/bin

The pyleabra executable combines standard python and the full Go emergent and GoGi gui packages -- see the information in the GoGi python readme for more technical information about this.

Use make install-win for Windows to add the .exe extension and copies into ~/go/bin.

Sharing install

To make a compiled version available to others, you just need the dist/leabra-1.1.15.tar.gz file and the pyleabra executable:

$ ./pyleabra -m pip install leabra-1.1.15.tar.gz
$ ./pyleabra -m pip install numpy  # numpy is needed
$ cp pyleabra /usr/local/bin/

These steps might require sudo permissions.

Releases

No releases published

Packages

No packages published