-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Bug fix on QNSPSA #9483
Bug fix on QNSPSA #9483
Changes from 5 commits
5858cf5
d50455f
032821f
a1e72f2
db9252e
246d8a5
32afd3b
df36a71
16d2a9d
b89370b
2368ac8
79da909
9ca84bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed bug in QNSPSA which raised a type error when trying to divide or subtract | ||
an int by a float or viceversa. | ||
luciacuervovalor marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,3 +255,26 @@ def objective(x): | |
with self.subTest("check number of function calls"): | ||
expected_nfev = 8 # 7 * maxiter + 1 | ||
self.assertEqual(result.nfev, expected_nfev) | ||
|
||
def test_point_sample(self): | ||
"""Test point sample function in QNSPSA""" | ||
|
||
def fidelity(x, y): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pylint's moaning about the unused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh man, and now Pylint's complaining that that's not a valid name... I'm not a fan of these pylint rules at all. At any rate, you can put a comment just under the docstring of |
||
x = np.asarray(x) | ||
return np.ones_like(x, dtype=float) # some float | ||
|
||
def objective(x): | ||
return x | ||
|
||
def get_perturbation(): | ||
def perturbation(): | ||
while True: | ||
yield 1 | ||
return perturbation | ||
|
||
qnspsa = QNSPSA(fidelity, maxiter=1, learning_rate=0.1, perturbation=get_perturbation()) | ||
initial_point = 1. | ||
result = qnspsa.minimize(objective, initial_point) | ||
|
||
expected_nfev = 8 # 7 * maxiter + 1 | ||
self.assertEqual(result.nfev, expected_nfev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the casts to float still required now that we explicitly use
diff = diff / thing
instead ofdiff /= thing
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so because it failed again with
diff = diff / thing
with the same error