CQCL / pytket-cutensornet

cuTensorNet Python API extensions for pytket quantum SDK
Apache License 2.0
8 stars 1 forks source link

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

Closed PabloAndresCQ closed 3 months ago

PabloAndresCQ commented 3 months ago

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

PabloAndresCQ commented 3 months ago

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