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

Use Boolean Hamiltonian Gate for QAOA #3989

Closed
wants to merge 190 commits into from

Conversation

tonybruguier
Copy link
Contributor

No description provided.

@tonybruguier tonybruguier requested review from cduck, vtomole and a team as code owners April 3, 2021 06:55
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Apr 3, 2021
@BichengYing
Copy link
Collaborator

@tonybruguier @balopat I just want to mention that this diagonal Hamiltonian representation is highly related with diagonal gate decomposition #3890. One main application of diagonal gate is to simulate the Hamiltonian (Ref. Sec 4. in (https://iopscience.iop.org/article/10.1088/1367-2630/16/3/033040/pdf).

@tonybruguier
Copy link
Contributor Author

@tonybruguier @balopat I just want to mention that this diagonal Hamiltonian representation is highly related with diagonal gate decomposition #3890. One main application of diagonal gate is to simulate the Hamiltonian (Ref. Sec 4. in (https://iopscience.iop.org/article/10.1088/1367-2630/16/3/033040/pdf).

Ohhhh, nice! Thanks for the reference.

I will need more time to digest the paper and your PR. I took a little time to study both, and my temporary understanding is that the approach you just linked is that it approximates a function defined by its enumerated values while the present PR is an exact representation of a function defined by its formula.

Also, do you suggest a refactoring (now or later)? I'm open to suggestions, I just could use some more advice on how to proceed (if you have the time). I will read the paper more carefully later no matter what.

@BichengYing
Copy link
Collaborator

BichengYing commented Apr 8, 2021

@tonybruguier I don't suggest any refactoring at all. Just mention the connection. For example, here this Hamiltonian representation exploited the special format of QAOA \sum(1-s_is_j), which is not considered in the diagonal gate at all. But I am interested to have a deep look and check more differences and connections here.

@tonybruguier
Copy link
Contributor Author

@tonybruguier I don't suggest any refactoring at all. Just mention the connection. For example, here this Hamiltonian representation exploited the special format of QAOA \sum(1-s_is_j), which is not considered in the diagonal gate at all. But I am interested to have a deep look and check more differences and connections here.

Thanks. I think I understand a little bit more now. I think it is indeed the case that the diagonal gates uses the values directly to construct an approximate circuit, while the present PR uses the formula to construct an exact circuit.

It seems the circuit could be a bit different though:
https://github.com/tonybruguier/sandbox/blob/master/try_out_diagonal_gate.py#L29

@BichengYing
Copy link
Collaborator

BichengYing commented Apr 10, 2021

The main difference and the biggest advantage of this work, I think, is it does not evaluate the whole truth table of boolean function directly to construct the circuit. Meanwhile, the diagonal gate has to know all values (not limited to boolean function through).
I want to correct that diagonal gates give the exact circuit instead of the approximate one if the function is f:[0,1]^n -> R. It gives an approximation for f: R -> R.

It seems the circuit could be a bit different though:
https://github.com/tonybruguier/sandbox/blob/master/try_out_diagonal_gate.py#L29

Yes, they will give different circuits. As for this particular circuit example you showed, they are exactly the same actually (if you ignore the identical operatorRz(0)). You can try print(cirq.Circuit(cirq.decompose(circuit2))) to see. (cirq.decompose will further decompose the CNOT gates)

Since the connection, I am reviewing this PR. (so me again :) ) Will send more comments after I understand this better.

Copy link
Collaborator

@BichengYing BichengYing left a comment

Choose a reason for hiding this comment

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

@tonybruguier This is an interesting work, thanks for adding an example for this! I left some comments more about the coding actually.

After understanding better the reference you gave, the following is my latest understanding of the connection between diagonal gates :

  • Same: The underlying math foundation is exactly the same. One called Fourier expansions, one called Walsh-Hadamard transform (They are the same thing under Z_2^n). The construction of these basis/expansions -- exp^(-i \gamma H_f) through CNOT and Z gates are the same as well. (Some re-ordering for optimization is used in the diagonal gate but is not important here.)
  • Diff: Diagonal gate use the full Walsh transform to get these coefficients directly, which requires O(Nlog(N)) = O(n2^n) even under the FFT style. Hamiltonian represents through the boolean expressions and composite rules. Under many well-structured situations, like the ISING model, it only needs to be expanded to be quadratic terms, hence it can save huge computation requirements. (I need to understand better on the cost of general cases)

examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation_test.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
examples/hamiltonian_representation.py Outdated Show resolved Hide resolved
@tonybruguier
Copy link
Contributor Author

Thanks. PTAL. I am thinking about what you said, and trying to see whether I can improve the number of gates.

@tonybruguier
Copy link
Contributor Author

Thanks @balopat . I think this is what you had suggested. PTAL?

@tonybruguier
Copy link
Contributor Author

@MichaelBroughton
Would you be interested in taking this over from Balint?

@google-cla
Copy link

google-cla bot commented Sep 8, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes Makes googlebot stop complaining. labels Sep 8, 2021
@google-cla
Copy link

google-cla bot commented Sep 16, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@tonybruguier
Copy link
Contributor Author

@MichaelBroughton
Friendly ping. Not super urgent and I can withdraw it if you have objections.

@google-cla
Copy link

google-cla bot commented Oct 12, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…antumlib#4282)

As part of the the review quantumlib#3989 we could use the ability to build a PauliSum from a Boolean expression. This PR makes available that function (smaller change).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants