Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add numpy version #11

Merged
merged 5 commits into from
Aug 23, 2021
Merged

Conversation

vgoliber
Copy link
Collaborator

@vgoliber vgoliber commented Aug 20, 2021

Update unittest for new test that is inconsistent.

Note: the unittest fails when num_new_cs = 1, so this has been updated to choose a number between 2 and 4 instead of 1 and 4.

@vgoliber vgoliber requested a review from hhtong August 20, 2021 05:12
@hhtong
Copy link
Contributor

hhtong commented Aug 20, 2021

Do you know why the error is occurring when num_new_cs==1? I see that it's not that the test fails when num_new_cs==1, it's that an exception is raised in demo_np.py:

Traceback (most recent call last):
  File "C:\Users\circleci\repo\tests\test_integration.py", line 119, in test_same_bqm
    bqm_np = demo_numpy.build_bqm(potential_new_cs_nodes, num_poi, pois, num_cs, charging_stations, num_new_cs)
  File "C:\Users\circleci\repo\demo_numpy.py", line 86, in build_bqm
    q2 = quad_col[dist_mat != 0]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 90601 but corresponding boolean dimension is 903

So it seems like something needs to be adjusted in the demo_numpy.py formulation, if num_new_cs==1 is a valid argument.

@@ -111,7 +111,7 @@ def test_same_bqm(self):
"""Run demo.py and demo_numpy.py with same inputs to check same BQM created."""

w, h = (random.randint(10,20), random.randint(10,20))
num_poi, num_cs, num_new_cs = (random.randint(1,4), random.randint(1,4), random.randint(1,4))
num_poi, num_cs, num_new_cs = (random.randint(2,4), random.randint(2,4), random.randint(2,4))
Copy link
Contributor

@hhtong hhtong Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do end up needing to enforce that num_new_cs>1, it should be explained in the docstring why.

And then if that's the case, in this test, I think we'd only need to do:

Suggested change
num_poi, num_cs, num_new_cs = (random.randint(2,4), random.randint(2,4), random.randint(2,4))
num_poi, num_cs, num_new_cs = (random.randint(1,4), random.randint(1,4), random.randint(2,4))

@hhtong
Copy link
Contributor

hhtong commented Aug 20, 2021

Also, I see that in demo_numpy.py, when num_new_cs>1, the dist_mat calculated for constraint 2 seems to be ignored/overwritten by constraint 3. I'm not familiar with this formulation, so I wanted to double check with you that the new dist_mat equation for constraint 3 also takes constraint 2 into consideration. (My assumption is that it does, since the unit test you wrote passes in this case)

@vgoliber
Copy link
Collaborator Author

The distance matrix getting written over is correct because it's a different distance matrix each time - I just reused the same object.

@vgoliber
Copy link
Collaborator Author

@hhtong this should be resolved now.

@vgoliber vgoliber merged commit 47b3172 into dwave-examples:main Aug 23, 2021
@vgoliber vgoliber deleted the add-numpy-version branch August 23, 2021 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants