Skip to content

Add ASV#158

Closed
kwohlfahrt wants to merge 4 commits intoPyWavelets:masterfrom
kwohlfahrt:asv
Closed

Add ASV#158
kwohlfahrt wants to merge 4 commits intoPyWavelets:masterfrom
kwohlfahrt:asv

Conversation

@kwohlfahrt
Copy link
Member

Adds a basic benchmarking suite, hopefully giving an idea of how to write something similar for other components. Still a number of things to do, tracking in #136

@kwohlfahrt
Copy link
Member Author

AppVeyor is failing in the install process somewhere, which is not touched by this PR.

@grlee77
Copy link
Contributor

grlee77 commented Mar 1, 2016

Thanks for working on this Kai! It will definitely be very useful to have.

I had not used asv before, but I like how you can manipulate the plots through the web browser.

I agree using the latest packages from upstream is reasonable for development purposes. In that case I guess the workflow would be to run asv on a proposed PR vs. master to check that no unexpected performance regressions are being introduced.

@rgommers
Copy link
Member

rgommers commented Mar 1, 2016

+1 for using the latest released versions of numpy and cython.

@rgommers
Copy link
Member

rgommers commented Mar 1, 2016

AppVeyor is failing in the install process somewhere, which is not touched by this PR.

Is a pip issue, looks like it's fixed by pip install --upgrade pip (works in gh-161). You could add that here, or gh-161 could be merged first.

EDIT: or we just ignore the failure; not like something will break by adding asv support

@@ -0,0 +1,57 @@
import numpy as np
import pywt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for newer functions the way to write the import in asv is:

try:
    from pywt import dwt, idwt
except ImportError:
    pass

Otherwise when you run the benchmarks for newly added functions against an older pywt version that doesn't have them, the tests crash. Obviously dwt, idwt have existed for a while, but if we're going to copy this as a template for other benchmarks, maybe good to keep the style uniform.

See https://github.com/scipy/scipy/blob/master/benchmarks/README.rst#writing-benchmarks for this and other benchmarking pointers to steal for a basic README here.

@rgommers
Copy link
Member

rgommers commented Mar 1, 2016

asv run
asv publish
asv preview

works as expected. Merging this PR without sorting out hosting etc. first would be fine with me.

@kwohlfahrt
Copy link
Member Author

My main concern with this at the moment is that ASV is incredibly slow. It takes about 20 minutes to run asv run --quick for one environment. This has an average of 99% CPU utilization, but I don't see which of the benchmarks could be taking this long. pywt.dwtn(np.ones((256,) * 3, 'sym20') is the slowest and takes about 10 seconds when run manually.

Is anybody else encountering this?

@grlee77
Copy link
Contributor

grlee77 commented Mar 3, 2016

I have not tried with --quick, but it definitely took a long time to run for the 2 python versions and 4 commits shown in #162. I didn't measure the time, but I think it was at least 1 hour.

@kwohlfahrt
Copy link
Member Author

That matches my experience, most of the time seems to be spent in initialization rather than actual timing. This is possibly still useful to control for regressions, but it's too slow to get any kind of feedback during development so I'd prefer another alternative.

There is a module for pytest here, so I'll check that out. If anybody else has ideas let me know.

@grlee77
Copy link
Contributor

grlee77 commented Mar 3, 2016

initialization may be a little faster if you are able to use conda rather than virtualenv in the ASV configuration. I think it would be fetching a prebuilt numpy in that case.

@rgommers
Copy link
Member

rgommers commented Mar 3, 2016

Since the envs don't get cleaned up even with git clean -xdf, the initial build time is a one-time cost. And with asv run --python=same, the total runtime of the benchmarks is about 5 min for me. Could be better, but it's not that bad considering that there are actually quite a few benchmarks here. The first DwtTimeSuiteBase param definition alone is 7 values of n times 3 wavelets times 6 modes x 4 time_ methods = 504 benchmarks.

@rgommers
Copy link
Member

rgommers commented Mar 3, 2016

I think it would help to steal benchmarks/run.py and the benchmark related stuff in runtests.py from Scipy. That avoids having to reinvent stuff like --python=same.

@kwohlfahrt
Copy link
Member Author

Yeah, 5 minutes would be a reasonable time for full benchmarks. What do you get with --quick enabled as well? I can't get asv run --python=same to work at the moment (ditto for asv dev):

kai@kjw53-laptop ~/D/c/p/asv> asv run --python=same
· Discovering benchmarks
·· Error running /usr/bin/python3.4 /usr/lib64/python3.4/site-packages/asv/benchmark.py discover benchmarks /tmp/tmp40ddvr65
             STDOUT -------->

             STDERR -------->
             Traceback (most recent call last):
               File "/usr/lib64/python3.4/site-packages/asv/benchmark.py", line 658, in <module>
                 list_benchmarks(benchmark_dir, fp)
               File "/usr/lib64/python3.4/site-packages/asv/benchmark.py", line 639, in list_benchmarks
                 for benchmark in disc_benchmarks(root):
               File "/usr/lib64/python3.4/site-packages/asv/benchmark.py", line 624, in disc_benchmarks
                 for module in disc_files(root, os.path.basename(root) + '.'):
               File "/usr/lib64/python3.4/site-packages/asv/benchmark.py", line 613, in disc_files
                 module = import_module(package + filename)
               File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
                 return _bootstrap._gcd_import(name[level:], package, level)
               File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
               File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
               File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
               File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
               File "<frozen importlib._bootstrap>", line 1129, in _exec
               File "<frozen importlib._bootstrap>", line 1471, in exec_module
               File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
               File "/home/kai/Documents/code/pywt/asv/benchmarks/dwt_benchmarks.py", line 5, in <module>
                 class DwtTimeSuiteBase(object):
               File "/home/kai/Documents/code/pywt/asv/benchmarks/dwt_benchmarks.py", line 11, in DwtTimeSuiteBase
                 pywt.Modes.modes)
             AttributeError: 'module' object has no attribute 'Modes'
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.4/asv", line 9, in <module>
    load_entry_point('asv==0.1.1', 'console_scripts', 'asv')()
  File "/usr/lib64/python3.4/site-packages/asv/main.py", line 36, in main
    result = args.func(args)
  File "/usr/lib64/python3.4/site-packages/asv/commands/__init__.py", line 47, in run_from_args
    return cls.run_from_conf_args(conf, args)
  File "/usr/lib64/python3.4/site-packages/asv/commands/run.py", line 122, in run_from_conf_args
    skip_existing_commits=args.skip_existing_commits
  File "/usr/lib64/python3.4/site-packages/asv/commands/run.py", line 197, in run
    benchmarks = Benchmarks(conf, regex=bench)
  File "/usr/lib64/python3.4/site-packages/asv/benchmarks.py", line 285, in __init__
    for benchmark in benchmarks:
  File "/usr/lib64/python3.4/site-packages/asv/benchmarks.py", line 325, in disc_benchmarks
    dots=False)
  File "/usr/lib64/python3.4/site-packages/asv/environment.py", line 429, in run
    self._executable] + args, **kwargs)
  File "/usr/lib64/python3.4/site-packages/asv/util.py", line 431, in check_output
    raise ProcessError(args, retcode, stdout, stderr)
asv.util.ProcessError: Command '/usr/bin/python3.4 /usr/lib64/python3.4/site-packages/asv/benchmark.py discover benchmarks /tmp/tmp40ddvr65' returned non-zero exit status 1

@kwohlfahrt kwohlfahrt force-pushed the asv branch 2 times, most recently from 0271143 to 2a76224 Compare March 7, 2016 11:40
@kwohlfahrt kwohlfahrt force-pushed the asv branch 2 times, most recently from 5bd52bb to 42b7033 Compare July 6, 2016 21:35
@codecov-io
Copy link

codecov-io commented Jul 6, 2016

Current coverage is 86.86% (diff: 100%)

Merging #158 into master will not change coverage

@@             master       #158   diff @@
==========================================
  Files            17         17          
  Lines          2216       2216          
  Methods           0          0          
  Messages          0          0          
  Branches        242        242          
==========================================
  Hits           1925       1925          
+ Misses          245        244     -1   
- Partials         46         47     +1   

Powered by Codecov. Last update ef5033a...6842bdd

Kai Wohlfahrt and others added 4 commits October 2, 2016 12:23
No benchmarks setup, but ASV builds correctly
Interestingly, 1D dwt is significantly slower on python 3.
Benchmarking these functions should hopefully give a closer view of how
performance in the C core changes without requiring a lot of effort to
instrument them separately.

The different modes should have somewhat different performance, especially
for small sizes/large filters. If this doesn't happen, there is too much
overhead to benchmark the convolution directly and this needs to be done
separately.

modes are only set for 1D, since n-dimensional path is not affected by the
mode (it is just passed through to the 1D).
This was referenced Oct 7, 2016
@rgommers
Copy link
Member

While we're in PR merging mode: would be good to get this in. We can worry about a site for displaying results and fine-tuning later, but once we have the beginning then new PRs can add benchmarks quite easily for new functions or performance improvements.

asv had a new release, so hopefully --python=same works for you now. With asv run --quick things work partially for me, takes about 10 min including creating 2.7 and 3.4 envs and building pywt in those. The 2.7 benchmarks all work as expected, the 3.4 ones fail - that's not my default Python, so it's probably something in my environment.

To get this in, I suggest:

  • address the couple of open review comments
  • rename asv/ to benchmarks/
  • add a benchmarks/README with basic instructions (a simple pip install asv and then asv run --python=same will do)

@rgommers
Copy link
Member

The full run indeed takes forever, not yet sure why.


// The Pythons you'd like to test against. If not provided, defaults
// to the current version of Python used to run `asv`.
"pythons": ["2.7", "3.4"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this to start with, cuts down on runtime and build issues. The benchmarking results won't really depend on Python version in an interesting/significant way.

pywt.dwt(self.data, wavelet, mode)

def time_dwt_ext(self, n, wavelet, mode):
pywt._extensions._dwt.dwt_single(self.data, self.wavelet, self.mode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't be in a benchmark - only need/want to benchmark public functions/methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment applies to time_idwt_ext

// If missing or the empty string, the tool will be automatically
// determined by looking for tools on the PATH environment
// variable.
"environment_type": "virtualenv",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better not define this. I'd expect the majority of Windows users to have better luck with conda.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we comment out the line, we should mention that the user should uncomment and set to either conda or virtualenv. When I had it commented out altogether asv issued a warning stating that this field would be required in a future release.

@grlee77
Copy link
Contributor

grlee77 commented Oct 27, 2016

just tried this again using asv 0.2.
asv run --python=same --quick worked for me and took < 5 mins
Setting "environment_type": "conda" in the config also worked and tests completed for 2.7 and 3.4


class SwtTimeSuiteBase(object):
"""
Set-up for (I)DWT timing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: DWT->SWT

grlee77 added a commit to grlee77/pywt that referenced this pull request Dec 30, 2016
@grlee77 grlee77 mentioned this pull request Dec 31, 2016
@rgommers
Copy link
Member

continued in gh-264, so closing this PR.

@rgommers rgommers closed this Dec 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants