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 product of edge weight Hamiltonian and test #1209

Merged
merged 56 commits into from
Apr 21, 2021

Conversation

anthayes92
Copy link
Contributor

This Hamiltonian holds the edge weight information that is used in the cost function during optimisation to find the max weighted cycle in the directed graph of interest.

Add function to generate this Hamiltonian.

In the unconstrained QAOA approach penalty terms are added to this Hamiltonian
In the constrained QAOA approach, the penalty complexity is added to the accompanying mixer Hamiltonian

@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.

@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #1209 (e6a8965) into master (164b409) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1209   +/-   ##
=======================================
  Coverage   98.13%   98.14%           
=======================================
  Files         146      146           
  Lines       11017    11035   +18     
=======================================
+ Hits        10812    10830   +18     
  Misses        205      205           
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 164b409...e6a8965. Read the comment docs.

Comment on lines 124 to 125
if len(edges) != len(set(edges)):
raise ValueError("Graph contains parallel edges")
Copy link
Contributor Author

@anthayes92 anthayes92 Apr 14, 2021

Choose a reason for hiding this comment

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

I think this can be removed as parallel edges are not allowed for nx.DiGraphs according to the documentation . A separate class nx.MultiDiGraph must be used to support parallel edges

@anthayes92 anthayes92 marked this pull request as ready for review April 14, 2021 16:50
trbromley and others added 9 commits April 15, 2021 16:15
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
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! 💯 Code looks great, but I think we can polish the docstrings a bit more.

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 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
tests/test_qaoa.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 and others added 19 commits April 20, 2021 12:38
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Base automatically changed from qaoa_cycles_module to master April 21, 2021 10:17
pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
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! 🚀 Would be good to add the following line to the changelog so we keep track of the PRs:

  [(#1209)](https://github.com/PennyLaneAI/pennylane/pull/1209)

pennylane/qaoa/cycle.py Outdated Show resolved Hide resolved
>>> edge_weight_data = {edge: (i + 1) * 0.5 for i, edge in enumerate(g.edges)}
>>> for k, v in edge_weight_data.items():
g[k[0]][k[1]]["weight"] = v
>>>> h = loss_hamiltonian(g)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Would be good to also print it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added here: 104ec3f

tests/test_qaoa.py Outdated Show resolved Hide resolved
@anthayes92 anthayes92 merged commit 35ab137 into master Apr 21, 2021
@anthayes92 anthayes92 deleted the add_edge_weight_product_hamiltonian branch April 21, 2021 13:17
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