📜 ⬆️ ⬇️

We start PyBrain on Python 3

Good day,% username%!

I want to tell the story of porting to Python3 of the PyBrain library, described recently in Habré .
Details under the cut.

Since I only recently started learning python , and also interested in neural networks , I was very intrigued by the library’s capabilities.
It is useful to load and install, but here's bad luck! Pybrain does not support python3 , and it hasn’t been updated for about four months.
Sad, I thought, opened the book “Python: Complete Reference Book” by David Beasley and plunged into reading.
It turns out there is a 2to3 utility bundled with python3 .
I made a fork of the pybrain project on github and began to torture her.
First, with the help of 2to3, I abused the pybrain folder, and then the folder with examples examples.
Strangely enough, everything went almost painlessly, and the command is simple to ugliness (see the subsection "Brief information on options 2to3" at the end of the article):
2to3 -Wn -o pybrain3/ pybrain/ 2to3 -Wn -o examples3/ examples/ 

In this case, I did not want to edit the code right on the spot, but created 2 additional folders (examples3 and pybrain3) where the utility saved the already ported source texts.

Testing the library for bugs


To test the library's performance, I decided to use the examples accompanying it as tests.
During the first launches, I got errors like this:
 Traceback (most recent call last): File "test1.py", line 2, in <module> from pybrain.tools.shortcuts import buildNetwork File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/__init__.py", line 1, in <module> from .structure.__init__ import * File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/structure/__init__.py", line 1, in <module> from .connections.__init__ import * File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/structure/connections/__init__.py", line 1, in <module> from .full import FullConnection File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/structure/connections/full.py", line 5, in <module> from .connection import Connection File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/structure/connections/connection.py", line 3, in <module> from pybrain.utilities import abstractMethod, Named File "/usr/lib/python3.2/site-packages/PyBrain-0.3.1-py3.2.egg/pybrain/utilities.py", line 15, in <module> from string import split ImportError: cannot import name split 

I had to work with a file. Erroneous import commented, corrected a couple of function names ... In general, nothing particularly difficult, even for a beginner.
On a number of examples, I encountered a failure due to the lack of matplotlib and pylab modules .
I searched, found in AUR'e (I have ArchLinux) the python-matplotlib-git package, installed it. Fortunately, it has already been ported to python3 , but it is not included in the list of supported packages. In other systems, you probably have to install the module manually. Take here .
I didn't really understand pylab . He is a member of scipy . Put the community / python-scipy version 0.10 - some more examples earned.
I will give a couple of pictures from the examples that display these beautiful graphics through matplotlib.
I will not give dumps of the work of other examples that give output to the console - a bunch of numbers and nothing particularly interesting.
Image and video hosting by TinyPic
Image and video hosting by TinyPic
')

Conclusion


Thus, for literally a couple of hours, it was possible with minimal effort to port the library to a sufficiently working state. Thanks 2to3 !
It seems that the library is efficient, but:

Ideally, write a test suite for full library coverage. Run tests on python2 and python3 , and compare the results. Only then can it be concluded that the port is correct.

I will be glad to any advice, suggestions and recommendations!
If anyone is willing to help - write, I will be glad!

Ps. Pull-request to the main branch of pybrain on github has not yet done. I also want to twist it, look for less obvious bugs. In the meantime, the ported pybrain library can be found here .

Literature:

  1. "PyBrain work with neural networks in Python"
  2. PyBrain
  3. David Beazley, "Python: The Complete Guide," fourth edition


List of working examples


List of broken examples


Quick Reference for 2to3 Options

 Usage: 2to3 [options] file|dir ... : -h, --help      -d, --doctests_only   doctests -f FIX, --fix=FIX  FIX  ;  : all -j PROCESSES, --processes=PROCESSES  2to3  PROCESSES  -x NOFIX, --nofix=NOFIX    NOFIX -l, --list-fixes    -p, --print-function Modify the grammar so that print() is a function -v, --verbose   --no-diffs      -w, --write    -n, --nobackups      -o OUTPUT_DIR, --output-dir=OUTPUT_DIR         .    -n. -W, --write-unchanged-files   .    (  --output-dir);  -w. --add-suffix=ADD_SUFFIX       .   -n,    . : --add-suffix='3'   .py3 

Source: https://habr.com/ru/post/148597/


All Articles