def daeg_to_rotational_superoperator(daeg, Rsuper): """Convert the frame order matrix (daeg) to the rotational superoperator. @param daeg: The second degree frame order matrix, daeg. This must be in the Kronecker product layout. @type daeg: numpy 9D, rank-2 array or numpy 3D, rank-4 array @param Rsuper: The rotational superoperator structure to be populated. @type Rsuper: numpy 5D, rank-2 array """ # First perform the T23 transpose. transpose_23(daeg) # Convert to rank-4. orig_shape = daeg.shape daeg.shape = (3, 3, 3, 3) # First column of the superoperator. Rsuper[0, 0] = daeg[0, 0, 0, 0] - daeg[2, 0, 2, 0] Rsuper[1, 0] = daeg[0, 1, 0, 1] - daeg[2, 1, 2, 1] Rsuper[2, 0] = daeg[0, 0, 0, 1] - daeg[2, 0, 2, 1] Rsuper[3, 0] = daeg[0, 0, 0, 2] - daeg[2, 0, 2, 2] Rsuper[4, 0] = daeg[0, 1, 0, 2] - daeg[2, 1, 2, 2] # Second column of the superoperator. Rsuper[0, 1] = daeg[1, 0, 1, 0] - daeg[2, 0, 2, 0] Rsuper[1, 1] = daeg[1, 1, 1, 1] - daeg[2, 1, 2, 1] Rsuper[2, 1] = daeg[1, 0, 1, 1] - daeg[2, 0, 2, 1] Rsuper[3, 1] = daeg[1, 0, 1, 2] - daeg[2, 0, 2, 2] Rsuper[4, 1] = daeg[1, 1, 1, 2] - daeg[2, 1, 2, 2] # Third column of the superoperator. Rsuper[0, 2] = daeg[0, 0, 1, 0] + daeg[1, 0, 0, 0] Rsuper[1, 2] = daeg[0, 1, 1, 1] + daeg[1, 1, 0, 1] Rsuper[2, 2] = daeg[0, 0, 1, 1] + daeg[1, 0, 0, 1] Rsuper[3, 2] = daeg[0, 0, 1, 2] + daeg[1, 0, 0, 2] Rsuper[4, 2] = daeg[0, 1, 1, 2] + daeg[1, 1, 0, 2] # Fourth column of the superoperator. Rsuper[0, 3] = daeg[0, 0, 2, 0] + daeg[2, 0, 0, 0] Rsuper[1, 3] = daeg[0, 1, 2, 1] + daeg[2, 1, 0, 1] Rsuper[2, 3] = daeg[0, 0, 2, 1] + daeg[2, 0, 0, 1] Rsuper[3, 3] = daeg[0, 0, 2, 2] + daeg[2, 0, 0, 2] Rsuper[4, 3] = daeg[0, 1, 2, 2] + daeg[2, 1, 0, 2] # Fifth column of the superoperator. Rsuper[0, 4] = daeg[1, 0, 2, 0] + daeg[2, 0, 1, 0] Rsuper[1, 4] = daeg[1, 1, 2, 1] + daeg[2, 1, 1, 1] Rsuper[2, 4] = daeg[1, 0, 2, 1] + daeg[2, 0, 1, 1] Rsuper[3, 4] = daeg[1, 0, 2, 2] + daeg[2, 0, 1, 2] Rsuper[4, 4] = daeg[1, 1, 2, 2] + daeg[2, 1, 1, 2] # Revert the shape. daeg.shape = orig_shape # Undo the T23 transpose. transpose_23(daeg)
def test_transpose_23(self): """Check the 2,3 transpose of a rank-4, 3D tensor.""" # Manually create the string rep of the transpose. daegT = self.string_transpose(2, 3) print("The real 2,3 transpose:") self.print_nice(daegT) # Convert to numpy. daegT = self.to_numpy(daegT) # Check. print("The numerical 2,3 transpose:") transpose_23(self.daeg) self.print_nice(self.daeg) for i in range(9): for j in range(9): print("i = %2s, j = %2s, daeg[i,j] = %s" % (i, j, daegT[i, j])) self.assertEqual(self.daeg[i, j], daegT[i, j])
def test_compile_2nd_matrix_pseudo_ellipse_point1(self): """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" # The simulated in frame pseudo-ellipse 2nd degree frame order matrix. real = array( [[ 0.7901, 0, 0, 0, 0.7118, 0, 0, 0, 0.6851], [ 0, 0.0816, 0, -0.0606, 0, 0, 0, 0, 0], [ 0, 0, 0.1282, 0, 0, 0, -0.1224, 0, 0], [ 0, -0.0606, 0, 0.0708, 0, 0, 0, 0, 0], [ 0.7118, 0, 0, 0, 0.6756, 0, 0, 0, 0.6429], [ 0, 0, 0, 0, 0, 0.2536, 0, -0.2421, 0], [ 0, 0, -0.1224, 0, 0, 0, 0.1391, 0, 0], [ 0, 0, 0, 0, 0, -0.2421, 0, 0.2427, 0], [ 0.6851, 0, 0, 0, 0.6429, 0, 0, 0, 0.6182]], float64) transpose_23(real) # Init. x = pi/4.0 y = 3.0*pi/8.0 z = pi/6.0 # The Kronecker product of the eigenframe rotation. Rx2_eigen = self.calc_Rx2_eigen_full(0.0, 0.0, 0.0) # Calculate the matrix. f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, Rx2_eigen, x, y, z) # Print out. print_frame_order_2nd_degree(real, "real") print_frame_order_2nd_degree(f2, "calculated") print_frame_order_2nd_degree(real-f2, "difference") # Check the values. for i in range(9): for j in range(9): print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) self.assert_(abs(f2[i, j] - real[i, j]) < 1e-4)