Skip to content
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

[BUG] equality_check fails when a kernel has reached its cutoff #161

Open
pdemarti opened this issue Dec 19, 2022 · 0 comments
Open

[BUG] equality_check fails when a kernel has reached its cutoff #161

pdemarti opened this issue Dec 19, 2022 · 0 comments

Comments

@pdemarti
Copy link

Describe the bug

A nice feature of perfplot is to be able to compare results that take dramatically different times. Imagine one is O(n) and another O(n!). In that case, using the parameter max_time cuts off a kernel once its measurements get larger than max_time over the course of n_range.

However, the timings produced for that kernel after cutoff are NaN. This is fine (even desired) for the benchmark results and for plotting, but alas, equality_check is called even though there is no result for that kernel.

To Reproduce

from math import factorial
import time

def f(n):
    time.sleep(0.001 * factorial(n))
    return 1

def g(n):
    time.sleep(0.001 * n)
    return 1

perfplot.plot(
    setup=lambda n: n,
    n_range=range(6),
    kernels=[f, g],
    max_time=0.005,
)

# raises: TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
# and: PerfplotError: Error in equality_check. Try setting equality_check=None.

Note: to make it work (with equality check), we can invert the order of the kernels (s.t. kernels[0] doesn't reach cutoff), or alternatively define a custom equality_check that handles the presence of None:

    ...
    equality_check=lambda a, b: a is None or b is None or a == b,

Diagnose
I may ask you to cut and paste the output of the following command.

conda list perfplot
# packages in environment at /mnt/miniconda3/envs/py39:
#
# Name                    Version                   Build  Channel
perfplot                  0.10.2             pyh6c4a22f_0    conda-forge

Did I help?

If I was able to resolve your problem, consider sponsoring my work on perfplot, or buy me a coffee to say thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant