theochem/PyCI

P,T2'

Closed this issue · 6 comments

P,T2'

@PaulWAyers Me and @Pavlo3P can't find the P-condition in thesis. Should we take a look at other sources or it has a different name?

As for the T2', The only condition we found is
image
It's not straight forward which transformation we need to apply to $\Gamma$ to get T2'.
For the $T_2'^{\dagger}$ it doable using this formula:
image

So the $T_2'$ matrix has four blocks, a $m^3 \times m^3$ block, a $m^3 \times m$ block, a $m \times m^3$ block (adjoint of the previous block, and a $m \times m$ block. This all gives you an $(m^3 + m) \times (m^3 + m)$ matrix which is positive semidefinite.

The $T_2^\dagger$ formula is F.9. The $T_2$ formula is Eq. (2.60).

Both equations from Ward Poelman's thesis.

The P condition is merely that the 2-electron reduced density matrix is positive semi-definite. The inverse of the (identity) mapping is the identity. I.e., the P condition is $\mathcal{L}(\Gamma) = \Gamma = \mathcal{L}^\dagger(\Gamma)$

@PaulWAyers So, the semicolon means reshaping of array? For example, if T2-transformation gives array of (1, 2, 3, 4, 5, 6) shape, it should be reshaped to (1*2*3, 4*5*6) in a straightforward way (i.e. with np.reshape)?

No semicolon's show up. It's simple using NumPy documentation for reshape or ChatGPT. Her's what the latter said....

  1. Understand the dimensions: Your initial array is a 6-dimensional array of shape $(n, n, n, n, n, n) $. The total number of elements in this array is $n^6$.

  2. Calculate the desired shape: You want to reshape this into a square matrix with $n^3 $ rows and $ n^3 $ columns. Thus, the target shape of the matrix is $(n^3, n^3) $.

  3. Use np.reshape: You can use np.reshape to transform the array. This function needs the new shape you want to convert your array into. For your case, it should be reshaped as mentioned above.

Here's how you can do it in Python:

import numpy as np

# Assume n is known and your array `a` is defined as:
a = np.random.rand(n, n, n, n, n, n)  # This creates a 6D array with random values

# Reshape the array to a square matrix of shape (n^3, n^3)
reshaped_matrix = np.reshape(a, (n**3, n**3))

Make sure that n is set appropriately, as the reshape operation requires that the total number of elements remains constant. In this case, since both the original array and the reshaped array have $n^6$ elements, this condition is naturally satisfied.

You need to be careful to understand how the indices are ordered and to make sure the right indices are being combined. This can be controlled somewhat by intrinsic orderings in reshape but you may have to use moveaxis in some cases. I always suggest looking at a simple example in detail to be sure the numpy functionality is doing what you want.

I think the semicolon @Pavlo3P is referring to is the semicolon in the notation for constructing matrices from tensors.
I created a simple wrapper around numpy.reshape function to convert tensors into arrays. I made it a separate function so that it's easier to add some extra functionality on top of it, such as swapping axis, etc. if we need it in the future.

I think for now it would be good if calc_T2_prime function return just a matrix for which we will impose positive semidefinite constraint later.

So, the code can look something like this:

def calc_T2_prime(gamma, N, conjugate=False):
    if not conjugate:
        T2 = calc_T2(gamma, N)
        omega = ...
        rho = ...
        omega_conj = ....
        row_1 = np.hstack([
                flatten_tensor(T2, (N**3, N**3)), flatten_tensor(omega, (N***3, N))])
        row_2 = np.hstack([
                flatten_tensor(omega_conj, (N, N**3)),  rho])
        return np.vstack([row_1, row_2])