Skip to content

Set up airspeed velocity benchmarks #1049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ecf2a9e
add airspeed velocity config and tests
wholmgren Aug 13, 2018
d53b782
add documentation
wholmgren Aug 14, 2018
cd25327
Merge branch 'master' into asv_setup
kandersolar Mar 22, 2020
c75c24d
move whatsnew line to 0.7.2
kandersolar Mar 22, 2020
53568cb
update asv.conf.json to most recent asv format
kandersolar Mar 22, 2020
37095c2
add useful tips to readme
kandersolar Mar 22, 2020
1c6cbb7
modify asv conf to install optional pvlib reqs (pytables etc)
kandersolar Mar 22, 2020
8db2f63
add more benchmarks for location and solarposition
kandersolar Mar 22, 2020
48e6366
fix solarposition docstring
kandersolar Mar 22, 2020
636bcaf
add tracking benchmark file
kandersolar Mar 22, 2020
5a93520
add irradiance benchmark file
kandersolar Mar 22, 2020
d480806
fix tracking benchmarks
kandersolar Mar 22, 2020
8b3eb3c
Merge branch 'master' into asv_setup
kandersolar Jul 22, 2020
c07003a
test python3.7 only, regardless of installed version
kandersolar Jul 22, 2020
329ba90
switch from conda to virtualenv
kandersolar Jul 22, 2020
066bd9e
restructure
kandersolar Sep 5, 2020
2e3c76e
stickler
kandersolar Sep 6, 2020
3f5b1ba
drop old whatsnew entry
kandersolar Sep 6, 2020
008f8ca
use separate classes for version checking
kandersolar Sep 6, 2020
25d7b9f
fix aoi_projection benchmark
kandersolar Sep 7, 2020
daf7e40
do version switching in setup() instead of in global scope
kandersolar Sep 7, 2020
c7bb2ec
singular space to satisfy stickler
kandersolar Sep 7, 2020
01e79a4
move asv conf to pvlib
kandersolar Sep 8, 2020
0ff98b6
move benchmarks to subdirectory
kandersolar Sep 8, 2020
d42ef6d
change to local repo instead of cloning from GH
kandersolar Sep 9, 2020
37993fa
docs
kandersolar Sep 9, 2020
605d744
update benchmark readme
kandersolar Sep 9, 2020
8c43a12
Merge branch 'master' into asv_setup
kandersolar Sep 10, 2020
73e6347
create 0.8.1 whatsnew
kandersolar Sep 10, 2020
791ee9b
conda channel ordering
kandersolar Sep 10, 2020
64adc84
link to readme
kandersolar Sep 10, 2020
1021400
fix wrong link
kandersolar Sep 10, 2020
85235a5
benchmark on minimum and latest dependency versions
kandersolar Sep 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@ coverage.xml

# Ignore Mac DS_store files
*.DS_Store

# airspeed velocity
env
results

93 changes: 93 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Benchmarks
==========

pvlib includes a small number of performance benchmarking tests. These
tests are run using
[airspeed velocity](https://asv.readthedocs.io/en/stable/) (ASV).

The basic structure of the tests and how to run them is described below.
We refer readers to the ASV documentation for more details. The AstroPy
[documentation](https://github.com/astropy/astropy-benchmarks/tree/master)
may also be helpful.

The test configuration is described in [asv.conf.json](asv.conf.json).
The performance tests are located in the [benchmarks](benchmarks) directory.

Comparing timings
-----------------

Note that, unlike pytest, the asv tests require changes to be committed
to git before they can be tested. The ``run`` command takes a positional
argument to describe the range of git commits or branches to be tested.
For example, if your feature branch is named ``feature``, a useful asv
run may be (from the same directory as `asv.conf.json`):

```
$ asv run master..feature
```

This will generate timings for every commit between the two specified
revisions. If you only care about certain commits, you can run them by
their git hashes directly like this:

```
$ asv run e42f8d24^!
```

Note: depending on what shell they use, Windows users may need to use
double-carets:

```
$ asv run e42f8d24^^!
```

You can then compare the timing results of two commits:

```
$ asv compare 0ff98b62 e42f8d24

All benchmarks:

before after ratio
[0ff98b62] [e42f8d24]
<asv_setup~1> <asv_setup>
+ 3.90±0.6ms 31.3±5ms 8.03 irradiance.Irradiance.time_aoi
3.12±0.4ms 2.94±0.2ms 0.94 irradiance.Irradiance.time_aoi_projection
256±9ms 267±10ms 1.05 irradiance.Irradiance.time_dirindex
```

The `ratio` column shows the ratio of `after / before` timings. For this
example, the `aoi` function was slowed down on purpose to demonstrate
the comparison.

Generating an HTML report
-------------------------

asv can generate a collection of interactive plots of benchmark timings across
a commit history. First, generate timings for a series of commits, like:

```
$ asv run v0.6.0..v0.8.0
```

Next, generate the HTML report:

```
$ asv publish
```

Finally, start a http server to view the test results:

```
$ asv preview

```


Nightly benchmarking
--------------------

The benchmarks are run nightly for new commits to pvlib-python/master.

- Timing results: https://pvlib-benchmarker.github.io/pvlib-benchmarks/
- Information on the process: https://github.com/pvlib-benchmarker/pvlib-benchmarks
162 changes: 162 additions & 0 deletions benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
// The version of the config file format. Do not change, unless
// you know what you are doing.
"version": 1,

// The name of the project being benchmarked
"project": "pvlib-python",

// The project's homepage
"project_url": "https://pvlib-python.readthedocs.io",

// The URL or local path of the source code repository for the
// project being benchmarked
"repo": "..",

// The Python project's subdirectory in your repo. If missing or
// the empty string, the project is assumed to be located at the root
// of the repository.
// "repo_subdir": "",

// Customizable commands for building, installing, and
// uninstalling the project. See asv.conf.json documentation.
//
// "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
// "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
// "build_command": [
// "python setup.py build",
// "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
// ],

// List of branches to benchmark. If not provided, defaults to "master"
// (for git) or "default" (for mercurial).
// "branches": ["master"], // for git
// "branches": ["default"], // for mercurial

// The DVCS being used. If not set, it will be automatically
// determined from "repo" by looking at the protocol in the URL
// (if remote), or by looking for special directories, such as
// ".git" (if local).
"dvcs": "git",

// The tool to use to create environments. May be "conda",
// "virtualenv" or other value depending on the plugins in use.
// If missing or the empty string, the tool will be automatically
// determined by looking for tools on the PATH environment
// variable.
"environment_type": "conda",

// timeout in seconds for installing any dependencies in environment
// defaults to 10 min
//"install_timeout": 600,

// the base URL to show a commit for the project.
"show_commit_url": "http://github.com/pvlib/pvlib-python/commit/",

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

// The list of conda channel names to be searched for benchmark
// dependency packages in the specified order
// "conda_channels": ["conda-forge", "defaults"],

// The matrix of dependencies to test. Each key is the name of a
// package (in PyPI) and the values are version numbers. An empty
// list or empty string indicates to just test against the default
// (latest) version. null indicates that the package is to not be
// installed. If the package to be tested is only available from
// PyPi, and the 'environment_type' is conda, then you can preface
// the package name by 'pip+', and the package will be installed via
// pip (with all the conda available packages installed first,
// followed by the pip installed packages).
//
"matrix": {
"numpy": ["1.18.5"],
"pandas": ["1.1.0"],
"scipy": ["1.2.0"],
"pytables": ["3.6.1"],
"ephem": ["3.7.6.0"],
},

// Combinations of libraries/python versions can be excluded/included
// from the set to test. Each entry is a dictionary containing additional
// key-value pairs to include/exclude.
//
// An exclude entry excludes entries where all values match. The
// values are regexps that should match the whole string.
//
// An include entry adds an environment. Only the packages listed
// are installed. The 'python' key is required. The exclude rules
// do not apply to includes.
//
// In addition to package names, the following keys are available:
//
// - python
// Python version, as in the *pythons* variable above.
// - environment_type
// Environment type, as above.
// - sys_platform
// Platform, as in sys.platform. Possible values for the common
// cases: 'linux2', 'win32', 'cygwin', 'darwin'.
//
// "exclude": [
// {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
// {"environment_type": "conda", "six": null}, // don't run without six on conda
// ],
//
// "include": [
// // additional env for python2.7
// {"python": "2.7", "numpy": "1.8"},
// // additional env if run on windows+conda
// {"platform": "win32", "environment_type": "conda", "python": "2.7", "libpython": ""},
// ],

// The directory (relative to the current directory) that benchmarks are
// stored in. If not provided, defaults to "benchmarks"
"benchmark_dir": "benchmarks",

// The directory (relative to the current directory) to cache the Python
// environments in. If not provided, defaults to "env"
// "env_dir": "env",

// The directory (relative to the current directory) that raw benchmark
// results are stored in. If not provided, defaults to "results".
// "results_dir": "results",

// The directory (relative to the current directory) that the html tree
// should be written to. If not provided, defaults to "html".
// "html_dir": "html",

// The number of characters to retain in the commit hashes.
// "hash_length": 8,

// `asv` will cache results of the recent builds in each
// environment, making them faster to install next time. This is
// the number of builds to keep, per environment.
// "build_cache_size": 2,

// The commits after which the regression search in `asv publish`
// should start looking for regressions. Dictionary whose keys are
// regexps matching to benchmark names, and values corresponding to
// the commit (exclusive) after which to start looking for
// regressions. The default is to start from the first commit
// with results. If the commit is `null`, regression detection is
// skipped for the matching benchmark.
//
// "regressions_first_commits": {
// "some_benchmark": "352cdf", // Consider regressions only after this commit
// "another_benchmark": null, // Skip regression detection altogether
// },

// The thresholds for relative change in results, after which `asv
// publish` starts reporting regressions. Dictionary of the same
// form as in ``regressions_first_commits``, with values
// indicating the thresholds. If multiple entries match, the
// maximum is taken. If no entry matches, the default is 5%.
//
// "regressions_thresholds": {
// "some_benchmark": 0.01, // Threshold of 1%
// "another_benchmark": 0.5, // Threshold of 50%
// },
}
Empty file.
68 changes: 68 additions & 0 deletions benchmarks/benchmarks/irradiance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
ASV benchmarks for irradiance.py
"""

import pandas as pd
from pvlib import irradiance, location


class Irradiance:

def setup(self):
self.times = pd.date_range(start='20180601', freq='1min',
periods=14400)
self.days = pd.date_range(start='20180601', freq='d', periods=30)
self.location = location.Location(40, -80)
self.solar_position = self.location.get_solarposition(self.times)
self.clearsky_irradiance = self.location.get_clearsky(self.times)
self.tilt = 20
self.azimuth = 180
self.aoi = irradiance.aoi(self.tilt, self.azimuth,
self.solar_position.apparent_zenith,
self.solar_position.azimuth)

def time_get_extra_radiation(self):
irradiance.get_extra_radiation(self.days)

def time_aoi(self):
irradiance.aoi(self.tilt, self.azimuth,
self.solar_position.apparent_zenith,
self.solar_position.azimuth)

def time_aoi_projection(self):
irradiance.aoi_projection(self.tilt, self.azimuth,
self.solar_position.apparent_zenith,
self.solar_position.azimuth)

def time_get_ground_diffuse(self):
irradiance.get_ground_diffuse(self.tilt, self.clearsky_irradiance.ghi)

def time_get_total_irradiance(self):
irradiance.get_total_irradiance(self.tilt, self.azimuth,
self.solar_position.apparent_zenith,
self.solar_position.azimuth,
self.clearsky_irradiance.dni,
self.clearsky_irradiance.ghi,
self.clearsky_irradiance.dhi)

def time_disc(self):
irradiance.disc(self.clearsky_irradiance.ghi,
self.solar_position.apparent_zenith,
self.times)

def time_dirint(self):
irradiance.dirint(self.clearsky_irradiance.ghi,
self.solar_position.apparent_zenith,
self.times)

def time_dirindex(self):
irradiance.dirindex(self.clearsky_irradiance.ghi,
self.clearsky_irradiance.ghi,
self.clearsky_irradiance.dni,
self.solar_position.apparent_zenith,
self.times)

def time_erbs(self):
irradiance.erbs(self.clearsky_irradiance.ghi,
self.solar_position.apparent_zenith,
self.times)
51 changes: 51 additions & 0 deletions benchmarks/benchmarks/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
ASV benchmarks for location.py
"""

import pandas as pd
import pvlib
from pkg_resources import parse_version


def set_solar_position(obj):
obj.location = pvlib.location.Location(32, -110, altitude=700,
tz='Etc/GMT+7')
obj.times = pd.date_range(start='20180601', freq='3min',
periods=1440)
obj.days = pd.date_range(start='20180101', freq='d', periods=365,
tz=obj.location.tz)
obj.solar_position = obj.location.get_solarposition(obj.times)


class Location:

def setup(self):
set_solar_position(self)

# GH 502
def time_location_get_airmass(self):
self.location.get_airmass(solar_position=self.solar_position)

def time_location_get_solarposition(self):
self.location.get_solarposition(times=self.times)

def time_location_get_clearsky(self):
self.location.get_clearsky(times=self.times,
solar_position=self.solar_position)


class Location_0_6_1:

def setup(self):
if parse_version(pvlib.__version__) < parse_version('0.6.1'):
raise NotImplementedError

set_solar_position(self)

def time_location_get_sun_rise_set_transit_pyephem(self):
self.location.get_sun_rise_set_transit(times=self.days,
method='pyephem')

def time_location_get_sun_rise_set_transit_spa(self):
self.location.get_sun_rise_set_transit(times=self.days,
method='spa')
Loading