-
Notifications
You must be signed in to change notification settings - Fork 575
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
Net flow constraint #1214
Net flow constraint #1214
Conversation
…cting duplicate terms, add unit tests
Hello. You may have forgotten to update the changelog!
|
Codecov Report
@@ Coverage Diff @@
## master #1214 +/- ##
=======================================
Coverage 98.13% 98.14%
=======================================
Files 147 147
Lines 11279 11306 +27
=======================================
+ Hits 11069 11096 +27
Misses 210 210
Continue to review full report at Codecov.
|
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.
Thanks @anthayes92! Looks great, just left some requested changes for docs + tests.
tests/test_qaoa.py
Outdated
assert expected_coeffs == h.coeffs | ||
assert all([op.wires == exp.wires for op, exp in zip(h.ops, expected_ops)]) |
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 we need another check to compare the ops.
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.
assert expected_coeffs == h.coeffs | |
assert all([op.wires == exp.wires for op, exp in zip(h.ops, expected_ops)]) | |
assert expected_coeffs == h.coeffs | |
assert all([op.wires == exp.wires for op, exp in zip(h.ops, expected_ops)]) | |
assert h.ops[0].name == "Identity" | |
assert all("-".join(op1.name) == "-".join(op2.name) for op1, op2 in zip(h.ops[1:], expected_ops[1:])) |
As an example - maybe there's a better way
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.
addressed here: f4456ac
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
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.
Thanks @anthayes92! Approved, subject to the suggestions and updating the changelog.
🚀
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
For the max weighted cycle QAOA problem, the unconstrained approach requires constraints to be included in the cost Hamiltonian. A net flow constraint is introduced to the cost Hamiltonian to help ensure it's minimised by selecting edges such that each node has a net flow of zero edges entering and leaving.
Add a net flow constraint function
Add a private function to calculate quadratic terms of the constraint.
Allows a user to easily introduce constraints to cost Hamiltonian.
It relies on private functions that may be redundant when changes to
qml.Hamiltonian
are introduced