Giter Club home page Giter Club logo

pytest-plt's Introduction

Latest PyPI version Python versions

Nengo: Large-scale brain modelling in Python

An illustration of the three principles of the NEF

Nengo is a Python library for building and simulating large-scale neural models. Nengo can create sophisticated spiking and non-spiking neural simulations with sensible defaults in a few lines of code. Yet, Nengo is highly extensible and flexible. You can define your own neuron types and learning rules, get input directly from hardware, build and run deep neural networks, drive robots, and even simulate your model on a completely different neural simulator or neuromorphic hardware.

Installation

Nengo depends on NumPy, and we recommend that you install NumPy before installing Nengo. If you're not sure how to do this, we recommend using Anaconda.

To install Nengo:

pip install nengo

If you have difficulty installing Nengo or NumPy, please read the more detailed Nengo installation instructions first.

If you'd like to install Nengo from source, please read the developer installation instructions.

Nengo is tested to work on Python 3.6 and above. Python 2.7 and Python 3.4 were supported up to and including Nengo 2.8.0. Python 3.5 was supported up to and including Nengo 3.1.

Examples

Here are six of many examples showing how Nengo enables the creation and simulation of large-scale neural models in few lines of code.

  1. 100 LIF neurons representing a sine wave
  2. Computing the square across a neural connection
  3. Controlled oscillatory dynamics with a recurrent connection
  4. Learning a communication channel with the PES rule
  5. Simple question answering with the Semantic Pointer Architecture
  6. A summary of the principles underlying all of these examples

Documentation

Usage and API documentation can be found at https://www.nengo.ai/nengo/.

To build the documentation yourself, run the following command:

python setup.py build_sphinx

This requires Pandoc to be installed, as well as some additional Python packages. For more details, see the Developer Guide.

Development

Information for current or prospective developers can be found at https://www.nengo.ai/contributing/.

Getting Help

Questions relating to Nengo, whether it's use or it's development, should be asked on the Nengo forum at https://forum.nengo.ai.

pytest-plt's People

Contributors

drasmuss avatar hunse avatar tbekolay avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

hunse joniemi

pytest-plt's Issues

Add option to clear all old plots

It's pretty a pretty common annoyance to generate plots and then not know which ones are new and which ones you generated some other time. Also, it's common when iterating on a test you're writing to change the parametrizations and therefore leave a bunch of stale plots behind that are no longer valid. All to say that it would be nice to have a command line option that would remove all of the existing plots in the plot directory before generating the plots for the current run. Something like

pytest --plots-clear --plots

would clear all the plots first, then generate new ones.

Add documentation

Currently the docs folder only contains stub files. They should be filled in with real documentation.

Better file structure in plots folder

Currently, the plots folder created by pytest-plt is based on the test function's nodeid. So, if the nodeid is something like nengo/tests/test_thing.py::test_simple_thing you end up with a nested folder like

plots
└── nengo
    └── tests
        └── test_thing.py::test_simple_thing.pdf

We should simplify / flatten this, though first we should decide the best way to simplify / flatten this.

Make --plots a flag with no arguments

Right now you can do

pytest --plots

or

pytest --plots my_cool_plotdir

to pass a directory in which to make plots. However, it's now also possible to set the plot directory in a config file. And it's quite annoying to do something like

pytest --plots nengo/tests/test_ensemble.py

and end up inadvertently making a nengo/tests/test_ensemble.py directory with a bunch of plots in it. So maybe we should just remove the ability to pass in a plot directory through the command line, and have --plots just be a flag.

Add tests

We should add tests to make sure that plots are created and that their filenames are as we expect when passing --plots, and that nothing is created when not passing --plots.

Make default plot directory customizable

Currently, if you do not pass a string to --plots, the default directory that plots will be placed in is called plots. In Nengo core we had some automated ways of setting this directory (using the Simulator fixture), but since this needs to work for any repository, we can't expect a Simulator fixture to exist.

A few ways we could think about automating the name of this directory:

  1. Add a configuration option that you can set through the setup.cfg / pytest.ini file that sets the default plot directory name for a given project.
  2. Somehow use the passed in args / configuration to generate a plot directory (so that if you pass in, e.g., --target loihi you get a different default plot directory name than if you pass in --target sim).

Invoking --plots through PyCharm gives error

I haven't done any digging into why this is, just noting it down for future work. When you run tests through PyCharm, they get invoked with something like this command:

python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pycharm\_jb_pytest_runner.py" --target test_simulator.py::test_train_recurrent -- --plots

Something about this confuses the way we parse the dirname:

...\lib\site-packages\pytest_plt\plugin.py:80: in __init__
    self.dirname = dirname
...\lib\site-packages\pytest_plt\plugin.py:96: in dirname
    os.makedirs(_dirname)

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'test_simulator.py::test_train_recurrent'

This isn't a new problem, the same issue was present with the plt fixture in nengo core.

Although it's kind of an edge case, it'd be nice to get this working since a) PyCharm is a not-uncommon IDE, and b) it's possible this same problem could be triggered in other ways when pytest is invoked in a "non-standard" way.

Invalid file name on Windows

To reproduce:

  1. Create file test.py
def test_plt(plt):
    plt.plot(range(100))
  1. Run pytest test.py --plots

Gives:

  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\pytest_plt\plugin.py", line 188, in _finalize
    plotter.__exit__(None, None, None)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\pytest_plt\plugin.py", line 144, in __exit__
    self.save(os.path.join(self.dirname, self.plt.saveas))
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\pytest_plt\plugin.py", line 152, in save
    self.plt.savefig(path, **savefig_kw)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\pyplot.py", line 689, in savefig
    res = fig.savefig(*args, **kwargs)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\figure.py", line 2094, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure
    **kwargs)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2558, in print_pdf
    file = PdfFile(filename, metadata=metadata)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\backends\backend_pdf.py", line 433, in __init__
    fh, opened = cbook.to_filehandle(filename, "wb", return_opened=True)
  File "d:\miniconda3\envs\nengo-dl\lib\site-packages\matplotlib\cbook\__init__.py", line 392, in to_filehandle
    fh = open(fname, flag, encoding=encoding)
OSError: [Errno 22] Invalid argument: 'plots\\tmp.test.py::test_plt.pdf'

I suspect it's the :: (since colons are used to denote drives on Windows).

Adjust dirname or filename based on parameters

In Nengo SPA some tests are parametrized like this:

def pytest_generate_tests(metafunc):
    if 'algebra' in metafunc.fixturenames:
        metafunc.parametrize('algebra', [a for a in TestConfig.algebras])

It would be nice if there were an official way to include the algebra argument (or any other argument in the general case) in the dirname or filename/path of the output file without setting saveas in every test that makes use of this. (If this is not included in the filename, plots will be overwritten.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.