Exemple #1
0
def unitary_to_axis(matrix_U, basis):
	(matrix_V, matrix_W) = diagonalize(matrix_U, basis)
	
	#print "V= " + str(matrix_V)
	#print "W= " + str(matrix_W)
	
	matrix_ln = get_matrix_logarithm(matrix_W)
	
	#print "matrix_ln= " + str(matrix_ln)
	
	# Reconjugate to transform into iH
	matrix_iH = matrix_V * matrix_ln * matrix_V.I
	
	# Factor out -i (since we used -i in exp_hermitian_to_unitary)
	matrix_H = (-1.0/1j) * matrix_iH
	
	#print "matrix_H= " + str(matrix_H)
	trace_norm = numpy.trace(matrix_H * matrix_H.H)
	#print "trace_norm(H)= " + str(trace_norm)
	
	# Compare the calculated components with our original
	(components2, K) = get_basis_components(matrix_H, basis)
	#print "K= " + str(K)
	#angle = K/2.0
	# Scale matrix by our calculated angle
	#matrix_H = matrix_H / angle
	return (components2, K, matrix_H)
def unitary_to_axis(matrix_U, basis):
    (matrix_V, matrix_W) = diagonalize(matrix_U, basis)

    #print "V= " + str(matrix_V)
    #print "W= " + str(matrix_W)

    matrix_ln = get_matrix_logarithm(matrix_W)

    #print "matrix_ln= " + str(matrix_ln)

    # Reconjugate to transform into iH
    matrix_iH = matrix_V * matrix_ln * matrix_V.I

    # Factor out -i (since we used -i in exp_hermitian_to_unitary)
    matrix_H = (-1.0 / 1j) * matrix_iH

    #print "matrix_H= " + str(matrix_H)
    trace_norm = numpy.trace(matrix_H * matrix_H.H)
    #print "trace_norm(H)= " + str(trace_norm)

    # Compare the calculated components with our original
    (components2, K) = get_basis_components(matrix_H, basis)
    #print "K= " + str(K)
    #angle = K/2.0
    # Scale matrix by our calculated angle
    #matrix_H = matrix_H / angle
    return (components2, K, matrix_H)
Exemple #3
0
def exp_hermitian_to_unitary(matrix_H, angle, basis):
    #print "exp_hermitian_to_unitary angle= " + str(angle)
    (matrix_V, matrix_W) = diagonalize(matrix_H, basis)
    Udiag = matrix_exp_diag(-1j * angle * matrix_W)
    assert_matrix_unitary(Udiag)
    # Now translate it back to its non-diagonal form
    U = matrix_V * Udiag * matrix_V.I
    assert_matrix_unitary(U)
    return U
Exemple #4
0
def exp_hermitian_to_unitary(matrix_H, angle, basis):
	#print "exp_hermitian_to_unitary angle= " + str(angle)
	(matrix_V, matrix_W) = diagonalize(matrix_H, basis)
	Udiag = matrix_exp_diag(-1j*angle*matrix_W)
	assert_matrix_unitary(Udiag)
	# Now translate it back to its non-diagonal form
	U = matrix_V * Udiag * matrix_V.I
	assert_matrix_unitary(U)
	return U
def test_decomposing_unitary(d):
	#print "*******************************************************************"
	#print "TESTING DECOMPOSITION OF UNITARY IN SU("+str(d)+")"
	B = get_hermitian_basis(d)
	
	(matrix_U, components, angle) = get_random_unitary(B)
	
	#print "U= " + str(matrix_U)
		
	(matrix_V, matrix_W) = diagonalize(matrix_U, B)
	
	#print "V= " + str(matrix_V)
	#print "W= " + str(matrix_W)
	
	matrix_ln = get_matrix_logarithm(matrix_W)
	
	#print "matrix_ln= " + str(matrix_ln)
	
	# Reconjugate to transform into iH
	matrix_iH = matrix_V * matrix_ln * matrix_V.I
	
	# Factor out -i (since we used -i in exp_hermitian_to_unitary)
	matrix_H = (-1.0/1j) * matrix_iH
	
	#print "matrix_H= " + str(matrix_H)
	
	# Compare the calculated components with our original
	(components2, K) = get_basis_components(matrix_H, B)
	
	#print "K= " + str(K)
	#print "angle= " + str(angle)
	assert_approx_equals_tolerance(numpy.abs(K), numpy.abs(2*angle), TOLERANCE4)
	
	#print "Renormalizing... "
	# Renormalize components
	#for key,value in components2.items():
	#	components2[key] = value / K
	#	print "("+str(key)+")= " + str(components2[key])
	
	# Assert that the components are now normalized
	norm = scipy.linalg.norm(components.values())
	norm2= scipy.linalg.norm(components2.values())
	#print "norm= " + str(norm)
	#print "norm2= " + str(norm2)
	assert_approx_equals(norm2, 1)
		
	for key in components2.keys():
		#print str(key)
		#print "  actual= " + str(components[key])
		#print "  comput= " + str(components2[key])
		ratio = abs(components[key]) / abs(components2[key])
		#print "  ratio= " + str(ratio)
		assert_approx_equals_tolerance(ratio, 1, TOLERANCE6)
assert_matrix_hermitian(SX.matrix)

RX2 = matrix_exp(-1j * (math.pi / 2) * SX.matrix, 50)

print "RX2= " + str(RX2)

# We can't assert unitarity here, b/c our matrix_exp misformats the matrix
# somehow so that the elements aren't complex, or something.
# Just visually inspect the print str above.
#assert_matrix_unitary(RX2)

# Verify that exponentiating a Hermitian (via its diagonalized form)
# gives a unitary
B2 = get_hermitian_basis(d=2)

(matrix_V, matrix_W) = diagonalize(SX.matrix, B2)

RX3 = matrix_exp_diag(-1j * (math.pi / 2) * matrix_W)

print "RX3= " + str(RX3)

# Success! Hopefully
assert_matrix_unitary(RX3)

# Now translate it back to its non-diagonal form
RX4 = matrix_V * RX3 * matrix_V.I

print "RX4= " + str(RX4)

# Should still be unitary
assert_matrix_unitary(RX3)