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

[QAOA] Adds Built-In Mixer Hamiltonians #712

Merged
merged 48 commits into from
Jul 30, 2020

Conversation

Lucaman99
Copy link
Contributor

@Lucaman99 Lucaman99 commented Jul 17, 2020

Context:

These changes are a part of the new QAOA functionality that is being introduced into PennyLane.

Description of the Change:

  • Adds a new QAOA submodule to PennyLane, where the new QAOA-specific functionality will be located
  • Adds built-in Pauli-X and XY mixer Hamiltonians for use in QAOA workflows, along with a helper method that is useful for constructing Hamiltonians from graphs
  • Adds tests for all of the new functionality in test_qaoa.py

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@codecov
Copy link

codecov bot commented Jul 17, 2020

Codecov Report

Merging #712 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #712      +/-   ##
==========================================
+ Coverage   95.46%   95.47%   +0.01%     
==========================================
  Files         107      109       +2     
  Lines        6791     6813      +22     
==========================================
+ Hits         6483     6505      +22     
  Misses        308      308              
Impacted Files Coverage Δ
pennylane/__init__.py 64.19% <100.00%> (+0.44%) ⬆️
pennylane/qaoa/__init__.py 100.00% <100.00%> (ø)
pennylane/qaoa/mixers.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 3a3ed68...e852132. Read the comment docs.

@Lucaman99 Lucaman99 changed the title [QAOA Functionality] Adds Built-In Cost and Mixer Hamiltonians [QAOA] Adds Built-In Cost and Mixer Hamiltonians Jul 17, 2020
@Lucaman99 Lucaman99 changed the title [QAOA] Adds Built-In Cost and Mixer Hamiltonians [QAOA] Adds Built-In Mixer Hamiltonians Jul 17, 2020
Copy link
Contributor

@ixfoduap ixfoduap left a comment

Choose a reason for hiding this comment

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

Looks solid! Just a few suggestions, should be good to go after you address them

pennylane/qaoa/__init__.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
tests/test_qaoa.py Outdated Show resolved Hide resolved
Lucaman99 and others added 5 commits July 20, 2020 08:50
Co-authored-by: ixfoduap <40441298+ixfoduap@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 @Lucaman99, I've given it a quick look. My main question is about the motivation for the Iterable type for the input graph?

pennylane/qaoa/__init__.py Outdated Show resolved Hide resolved


def check_iterable_graph(graph):
""" Checks if a graph supplied in 'Iterable format' is formatted correctly
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the iterable format look like? Could be worth adding a note for the developer, even if this function becomes non-user-facing

""" Checks if a graph supplied in 'Iterable format' is formatted correctly

Args:
graph (Iterable): The graph that is being checked
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth adding "Raises: ..." since the function doesn't return anything?

pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
pennylane/qaoa/qaoa.py Outdated Show resolved Hide resolved
for some graph :math:`G`. :math:`X_i` and :math:`Y_i` denote the Pauli-X and Pauli-Y operators on the :math:`i`-th
qubit respectively.
Args:
graph (Iterable or networkx.Graph) A graph defining the pairs of qubits (wires) on which each term of the Hamiltonian acts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a motivation for supporting the Iterable type? I'd be tempted to just support NetworkX Graph type, which is pretty established.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This choice was based off-of Nathan's comments on the QAOA ADR, where he said that supporting both different input types for graphs would be nice.

Copy link
Member

Choose a reason for hiding this comment

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

What is the iterable type? Simply a list of edges of the form g = [(0, 1), (2, 6), ...]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@josh146 It can theoretically be any Iterable with Iterable pairs as elements

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 @Lucaman99, approved provided the two comments are considered:

  • Adding to pennylane.__init__
  • Alphabetical order in the docs toc
    💯

@Lucaman99
Copy link
Contributor Author

Hey @trbromley @josh146 @ixfoduap - I just made a small, yet pretty significant change to the code. Basically, we have decided that having Hamiltonians track the user's physical wires within a QAOA workflow is the best course of action. Thus, the mixer Hamiltonians now take a list of wires as an argument, rather than an integer representing the number of wires on which the Hamiltonian acts.

Other than this, nothing else has changed!

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 @Lucaman99! I just have two questions:

  • What about a test for non-consecutive wires case?
  • For the xy_mixer() function, is the idea that the input graph replaces the Wires? I think that makes sense, although I was also expecting to see wires as an input in that function 🤔

class TestMixerHamiltonians:
"""Tests that the mixer Hamiltonians are being generated correctly"""

def test_x_mixer_output(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a parametrize over this function that tries two cases, one with consecutive and one with non-consecutive wires?

@Lucaman99
Copy link
Contributor Author

@trbromley Thanks! I'll definitely add a test for non-consecutive wires!

As for the xy_mixer, the idea is that the nodes of the graph would be the wire labels of the device, so having a separate wires argument isn't necessary.

@Lucaman99
Copy link
Contributor Author

@trbromley I just added the non-consecutive wires test!

@trbromley
Copy link
Contributor

@Lucaman99, did you mean to do the force push?

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Nice work @Lucaman99!

pennylane/qaoa/mixers.py Outdated Show resolved Hide resolved
pennylane/qaoa/mixers.py Outdated Show resolved Hide resolved
Lucaman99 and others added 4 commits July 30, 2020 11:06
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
@ixfoduap ixfoduap merged commit 485677c into PennyLaneAI:master Jul 30, 2020
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

4 participants