vprusso / toqito

|toqito> (Theory of Quantum Information Toolkit) in Python :snake:
https://toqito.readthedocs.io/en/latest/
MIT License
155 stars 61 forks source link

Feature: Compute mutual overlaps of vectors or density matrices #556

Closed vprusso closed 1 month ago

vprusso commented 7 months ago

It would be helpful to have a function that provides the mutual overlaps (inner products) of a list of numpy arrays (representing vectors of quantum states).

Something like the following:

def compute_overlaps(vectors: list[np.ndarray]) -> list[np.ndarray]:
    """Returns list of all overlaps such that i != j."""
    inner_products = []
    for i in range(len(vectors)):
        for j in range(i + 1, len(vectors)):
            inner_products.append(np.vdot(vectors[i], vectors[j]))
    return inner_products

In addition, we can refactor is_mutually_orthogonal.py to use this function as there is going to be a good amount of redundancy between these functions as is.

The function should also include proper documentation, examples, and tests.

tnemoz commented 1 month ago

Upon being given a list of $n$ vectors in dimension $d$, wouldn't it more convenient for the end-user to return a $n\times n$ matrix whose $(i,j)$ entry would be $\left\langle\psi_i\middle|\psi_j\right\rangle$ (that is, the Gram matrix if I'm not mistaken)?

Wouldn't returning a list like this may make this a bit difficult to index a specific inner product?

vprusso commented 1 month ago

True. I suppose one way around this would be to retain the indices and have the return be a dictionary whose keys are the index pairs and whose values are the corresponding inner product values. Would that seem a bit more sensible to you, @tnemoz ?

tnemoz commented 1 month ago

Sure! I wouldn't mind doing it if that's OK with you!

vprusso commented 1 month ago

That would be wonderful, thank you, @tnemoz !

tnemoz commented 1 month ago

I just noticed that there is a vectors_to_gram_matrix function in matrix_ops. Since this already allows for getting the inner products, I'm unsure about what should be done here. Wouldn't this function clearly overlap (haha) with vectors_to_gram_matrix? What would be the difference between the two?

vprusso commented 1 month ago

Hmm, that's a good point. In some sense, this information is already accessible from this function. I would even say that we can close this one out in favor of that. Good point, @tnemoz , I'll close this issue with the note that vectors_to_gram_matrix already has the overlap information baked into it. Thanks for the comment!