dwavesystems / dwave-optimization

Enables the formulation of nonlinear models for industrial optimization problems.
https://docs.ocean.dwavesys.com/en/stable/docs_optimization/index.html#index-optimization
Apache License 2.0
7 stars 18 forks source link

Silent casting of int symbol's state in some cases #25

Open JoelPasvolsky opened 4 months ago

JoelPasvolsky commented 4 months ago

Silent casting of int only when boundaries are defined:

  1. Got what I expected:

    >>> i = model.integer()
    >>> with model.lock():
            model.states.resize(1)
            i.set_state(0, -2.5)
            print(i.state(0))
    ValueError: Invalid data provided for node
  2. Got surprised:

    j = model.integer(lower_bound=-5, upper_bound=0)
    >>> with model.lock():
            model.states.resize(1)
            j.set_state(0, -2.5)
            print(j.state(0))
    -2.0
arcondello commented 4 months ago

Also needs a better error message.

arcondello commented 4 months ago

That said, I think we want to silent cast in both cases. To follow NumPy

In [11]: arr = np.zeros(1, dtype=int)

In [12]: arr[0] = 2.5

In [13]: arr[0]
Out[13]: 2