-
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
add out_flow_constraint function and private function, add unit tests #1220
Conversation
…cting duplicate terms, add unit tests
Hello. You may have forgotten to update the changelog!
|
Codecov Report
@@ Coverage Diff @@
## master #1220 +/- ##
=======================================
Coverage 98.14% 98.14%
=======================================
Files 147 147
Lines 11306 11333 +27
=======================================
+ Hits 11096 11123 +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 💯 Looking great, mainly left comments for the docs.
Should be able to start merging in tomorrow and will clear the backlog. Great that we've got this in so quickly!
pennylane/qaoa/cycle.py
Outdated
hamiltonian = qml.Hamiltonian(coeffs, ops) | ||
|
||
return hamiltonian |
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.
hamiltonian = qml.Hamiltonian(coeffs, ops) | |
return hamiltonian | |
return qml.Hamiltonian(coeffs, ops) |
g = nx.complete_graph(3) # undirected graph | ||
|
||
with pytest.raises(ValueError): | ||
h = out_flow_constraint(g) |
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.
We were also thinking of a test_net_flow_and_out_flow_constraint
, perhaps we can add in a follow up PR 👍
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! Although I left some quick suggestions. Also, don't forget to update 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. An out flow constraint is introduced to the cost Hamiltonian to help ensure it's minimised by selecting edges such that each node has an out flow equal to 0 or 1.
Add a out 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