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

[feature] Decompose gates to remove zero singular values #91

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

PabloAndresCQ
Copy link
Collaborator

@PabloAndresCQ PabloAndresCQ commented Apr 3, 2024

Description

This PR makes it so that we apply SVD on every two-qubit gate tensor before contracting it to the state. This means that gates such as XXPhase and locally equivalent ones (CX, CZ, ZZPhase, etc) are cheaper to apply since they can be decomposed using only 2 singular values instead of the usual 4. This reduces the overhead of MPS methods by a factor of 2 when using these special gates and by a factor of 4 in TTN.

The change for MPS is straightforward: decompose the gate tensor, remove any zero singular value and replace any contraction of gate_tensor with a contraction with U and V.

The change for TTN is a bit more involved, but simpler than it looks. Before we'd apply the gate_tensor to the leaf node with the qubit q0 and "push a message tensor" with the open bonds corresponding to the input and output of q1 all the way to the leaf node containing q1. Now, we do the same but with a previous step that decomposes gate_tensor into U and V, and applying U instead of gate_tensor to q0. That way, the open bond that we push through with the message tensor is the shared bond between U and V (which has dimension 4 in general, but 2 in the case of XXPhase etc). Once the message tensor reaches the leaf node containing q1 we contract it along with V to get the resulting state.

In both cases the is equivalent as what we'd get in the develop branch (that's why none of the tests need to change), but some of the virtual bonds during execution will have smaller dimension.

Checklist

  • I have run the tests on a machine with GPUs.
  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the changelog with any user-facing changes.

Sorry, something went wrong.

@PabloAndresCQ
Copy link
Collaborator Author

This one is not so straightforward. It's a simple change in the logic, but it required to change a bunch of small details in the code, which without prior context, might be hard to follow. I'm happy to walk you through this @cqc-melf

@PabloAndresCQ PabloAndresCQ requested a review from cqc-melf April 3, 2024 15:30
@@ -115,6 +115,7 @@ def _apply_2q_gate(self, q0: Qubit, q1: Qubit, gate: Op) -> TTNxGate:
# b -> the input bond of the gate on q1
# A -> the output bond of the gate on q0
# B -> the output bond of the gate on q1
# S -> the shared bond of the gate tensor's SVD
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we maybe have a a short chat and you can explain to me the meaning of this letters?

Copy link
Collaborator

@cqc-melf cqc-melf left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for all the explanations!

@PabloAndresCQ PabloAndresCQ merged commit 057adf1 into develop Apr 4, 2024
6 checks passed
@PabloAndresCQ PabloAndresCQ deleted the feature/decompose_gates branch April 4, 2024 12:30
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