Skip to content

Specified error (epsilon) not met because of np.isclose() #77

Description

@OliRom

The np.isclose() condition is sometimes used to return specific results, either to avoid division by zero errors or to skip calculations in trivial cases. By default, np.isclose() uses a tolerance of 1e-8. However, if the user specifies a decomposition tolerance of 1e-10, the resulting error may exceed the requested precision.

These occurrences of np.isclose() should either be replaced with a more robust check (e.g., verifying that the returned value lies within the allowed error margin using the operator norm before returning it) or should adapt its tolerance dynamically based on the maximum error specified by the user.

Moreover, this special case should be covered in the tests.

For example, in rz_approx.z_rotational_approximation() we currently have:

    # Checks if the angle is trivial
    exponent = round(2 * theta / math.pi)
    if np.isclose(0, theta):
        return np.array(
            [
                [Domega.from_ring(1), Domega.from_ring(0)],
                [Domega.from_ring(0), Domega.from_ring(1)],
            ],
            dtype=object,
        )
    elif np.isclose(2 * theta / math.pi, exponent):
        T = np.array(
            [
                [Domega(-D(1, 0), D(0, 0), D(0, 0), D(0, 0)), Domega.from_ring(0)],
                [Domega.from_ring(0), Domega(D(0, 0), D(0, 0), D(1, 0), D(0, 0))],
            ],
            dtype=object,
        )
        M = T**exponent
        return M

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions