``set_state()`` method quietly accepts transposed array

Open
#490 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp

Research direction

Start by reproducing the two set_state() calls from the issue and locate the set_state() implementation and its existing tests. Trace how array shapes are checked and determine the intended handling of the transposed input; done means the behavior is explicitly validated by tests and no longer accepts an unintended shape silently.

Written by the indexing model from the issue text.

Description

bug
>>> model = Model()
>>> x = model.integer((2, 5))
>>> with model.lock():
...     model.states.resize(2)
...     x.set_state(0, [[1, 2], [1, 3], [4, 1], [3, 2], [5, 5]])
...     x.set_state(1, [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]])
...     print(x.state(1))
...     print(x.state(0))
[[1. 2. 3. 4. 5.]
 [5. 4. 3. 2. 1.]]
[[1. 2. 1. 3. 4.]
 [1. 3. 2. 5. 5.]]

It's a nice "feature" to use but it will probably trip someone up.

Dominant language
C++
Stars
31
Forks
36
Avg merge
1d 9h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dwavesystems/dwave-optimization

All issues in dwavesystems/dwave-optimization

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.