Skip to content

Wrong sign for right boundary with Sympy #338

@Davide-sd

Description

@Davide-sd

Let's consider the following simple example. First, I'm going to show the correct result when using Numpy:

import numpy as np
from adaptive import notebook_extension, Learner1D
from adaptive.runner import simple
import dill

notebook_extension()

def func(x):
    return np.imag(np.sqrt(-(x + 0j)))

def goal(learner):
    return learner.loss() < 0.1

learner = Learner1D(func, bounds=(-1, 1))
simple(learner, goal)
learner.plot()

bokeh_plot

Now, I'm going to use Sympy to generate a function which is going to be evaluated with Numpy:

from sympy import *
var("x")
f = im(sqrt(-x))

# func is going to use Numpy
func = lambdify(x, f)

def goal(learner):
    return learner.loss() < 0.1

learner = Learner1D(func, bounds=(-1, 1))
learner_bytes = dill.dumps(learner)
learner_loaded = dill.loads(learner_bytes)
simple(learner_loaded, goal)
learner_loaded.plot()

bokeh_plot(1)

As you can see, the last evaluation point (the right boundary) has the wrong sign. Even if I change the boundaries, the last point will always have the wrong sign. Why does it happen? Is it something that I can fix with some option in the learner/runner or is it an internal bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions