P,T2'
Closed this issue · 6 comments
@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
It's not straight forward which transformation we need to apply to
For the
So the
The
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
@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....
-
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$ . -
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) $ . -
Use
np.reshape
: You can usenp.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
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])