dwavesystems / dwavesystems/dwave-optimization

``BinaryOp`` sometimes returns ``nan``, ``-inf``, and ``inf`` for ``min()`` and ``max()``

Open
#630 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
31
Forks
36
Avg merge
16h 55m
Merged PRs (30d)
8

Description

There are many possible instances of this.
Below is an example where the ``Multiplies`` node has predecessors with ``min`` and ``max`` values of ``[0,1]`` and ``[-inf, inf]``.
This results in ``min`` and ``max`` values of ``nan``.

```cpp
#include

#include "dwave-optimization/graph.hpp"
#include "dwave-optimization/nodes/binaryop.hpp"
#include "dwave-optimization/nodes/numbers.hpp"
#include "dwave-optimization/nodes/unaryop.hpp"

namespace dwave::optimization {

TEST_CASE("BinaryOpNode - Example Test") {
auto graph = Graph();
constexpr double inf = std::numeric_limits::infinity();

GIVEN("A very contrived example") {
auto* b_ptr = graph.emplace_node(1);
CHECK(b_ptr->min() == 0);
CHECK(b_ptr->max() == 1);

auto* x_ptr = graph.emplace_node(1, -1000000, 1000000);
CHECK(x_ptr->min() == -1000000);
CHECK(x_ptr->max() == 1000000);

auto* exp_x_ptr = graph.emplace_node(x_ptr);
CHECK(exp_x_ptr->min() == 0);
CHECK(exp_x_ptr->max() == inf);

auto* neg_exp_x_ptr = graph.emplace_node(exp_x_ptr);
CHECK(neg_exp_x_ptr->min() == -inf);
CHECK(neg_exp_x_ptr->max() == 0);

auto* inf_ptr = graph.emplace_node(exp_x_ptr, neg_exp_x_ptr);
CHECK(inf_ptr->min() == -inf);
CHECK(inf_ptr->max() == inf);

auto* multiplies_ptr = graph.emplace_node(b_ptr, inf_ptr);
CHECK(std::isnan(multiplies_ptr->min()));
CHECK(std::isnan(multiplies_ptr->max()));

THEN("Min and max of `multiplies_ptr` should be ordered but are not") {
CHECK(multiplies_ptr->min() <= multiplies_ptr->max()); // <- fails
}
}
}

} // namespace dwave::optimization
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.