toqito icon indicating copy to clipboard operation
toqito copied to clipboard

Function for tensor combination

Open vprusso opened this issue 1 year ago • 0 comments

Create a function that allows the user to take all tensor combinations of a set of states of size k:

def tensor_comb(states: list[np.ndarray], k: int) -> dict:
    """
    Create a tensor combination (quantum sequence) from a set of states.

    Args:
    states: A dictionary of states where keys are state identifiers and values are state vectors.
    k: The length of the sequence.

    Returns:
        A dictionary of tensor products representing the quantum sequence.
    """
    # Generate all possible functions σ from [k] to [n]. This is equivalent to
    # generating all possible sequences of length k.
    possible_sequences = list(itertools.product(range(len(states)), repeat=k))

    # Convert sequences of state identifiers to sequences of state vectors.
    sequences_of_states = {}
    for seq in possible_sequences:
        state_sequence = [states[i] for i in seq]
        # Calculate the tensor product of the state vectors.
        sequence_tensor_product = np.array(state_sequence[0])
        for state in state_sequence[1:]:
            sequence_tensor_product = np.kron(sequence_tensor_product, state)
        sequences_of_states[seq] = vector_to_density_matrix(sequence_tensor_product)

    return sequences_of_states

This can be placed within matrix_ops/ and would require appropriate testing coverage as well.

vprusso avatar Oct 05 '24 14:10 vprusso