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 out_flow_constraint function and private function, add unit tests #1220

Merged
merged 29 commits into from
May 6, 2021

Conversation

anthayes92
Copy link
Contributor

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

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@anthayes92 anthayes92 marked this pull request as ready for review April 15, 2021 16:21
@codecov
Copy link

codecov bot commented Apr 15, 2021

Codecov Report

Merging #1220 (81387cc) into master (ea74076) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1220   +/-   ##
=======================================
  Coverage   98.14%   98.14%           
=======================================
  Files         147      147           
  Lines       11306    11333   +27     
=======================================
+ Hits        11096    11123   +27     
  Misses        210      210           
Impacted Files Coverage Δ
pennylane/qaoa/cycle.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea74076...81387cc. Read the comment docs.

Copy link
Contributor

@trbromley trbromley left a 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 Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
Comment on lines 249 to 251
hamiltonian = qml.Hamiltonian(coeffs, ops)

return hamiltonian
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hamiltonian = qml.Hamiltonian(coeffs, ops)
return hamiltonian
return qml.Hamiltonian(coeffs, ops)

pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
tests/test_qaoa.py Show resolved Hide resolved
tests/test_qaoa.py Outdated Show resolved Hide resolved
g = nx.complete_graph(3) # undirected graph

with pytest.raises(ValueError):
h = out_flow_constraint(g)
Copy link
Contributor

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 👍

Base automatically changed from square_and_collect_private_helper_functions to master May 6, 2021 12:50
Copy link
Contributor

@trbromley trbromley left a 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!

pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
tests/test_qaoa.py Outdated Show resolved Hide resolved
tests/test_qaoa.py Outdated Show resolved Hide resolved
@anthayes92 anthayes92 merged commit fea7095 into master May 6, 2021
@anthayes92 anthayes92 deleted the out_flow_constraints branch May 6, 2021 15:50
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.

None yet

2 participants