예제 #1
0
def test_cont_evo_complete():
	
	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]]),1./4.,-1./2.)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	clas_pos_derivs = lambda q,p : q
	clas_mom_derivs = lambda q,p : p
	delta_time = 2.
	tau = 4.

	QHamlitonian = lambda q,p : q * np.matrix([[0.,1.],[1.,0.]])

	test_cont = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, clas_pos_derivs, clas_mom_derivs, tau, delta_time, 0, 0, 0)
	test_cont._evolution_one_step(-1, 1.)

	obt_state = test_cont.CQstate.state
	obt_position = test_cont.CQstate.position
	obt_momentum = test_cont.CQstate.momentum
	obt_time = test_cont.CQstate.time

	unnorm_exp_state = np.matrix([[(sqrt(3)/sqrt(2) + 1./sqrt(3)) / 2.]
								  ,[1j * (sqrt(3)/4. - 1/sqrt(6)) ]])
	exp_state = unnorm_exp_state/np.linalg.norm(unnorm_exp_state)

	exp_position = -3./4.
	exp_momentum = -1.
	exp_time = 2.

	np.testing.assert_almost_equal( obt_state, exp_state )
	np.testing.assert_almost_equal( obt_position, exp_position )
	np.testing.assert_almost_equal( obt_momentum, exp_momentum )
	np.testing.assert_almost_equal( obt_time, exp_time )
예제 #2
0
def test_jump_evo_L1():
	
	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]]),1./4.,2./3.)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	delta_time = 2.
	tau = 4.

	pos_derivs = [lambda q,p : - 1./3., lambda q,p : 1./6.]
	mom_derivs = [lambda q,p : 1./8., lambda q,p : - 1./4.]

	QHamlitonian = lambda q,p : q * np.matrix([[0.,1.],[1.,0.]])

	test_cont = lib.Unravelling(CQstate, [L0,L1], pos_derivs, mom_derivs, QHamlitonian, 0, 0, tau, delta_time, 0, 0, 0)
	test_cont._evolution_one_step(1, 1.)

	obt_state = test_cont.CQstate.state
	obt_position = test_cont.CQstate.position
	obt_momentum = test_cont.CQstate.momentum
	obt_time = test_cont.CQstate.time

	exp_state = np.matrix([[1j*1./sqrt(3)],[0.]])
	exp_position = - 3./4.
	exp_momentum = 0.
	exp_time = 2.

	np.testing.assert_almost_equal( obt_state, exp_state )
	np.testing.assert_almost_equal( obt_position, exp_position )
	np.testing.assert_almost_equal( obt_momentum, exp_momentum )
	np.testing.assert_almost_equal( obt_time, exp_time )
예제 #3
0
def test_cont_evo_non_diagonal_Hamiltonian_only():
	
	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]]),1./2.,1.)
	L0 = np.matrix([[0.,0.],[0.,0.]])		# set L0 to be zero everywhere so we can check contribution of H only
	clas_pos_derivs = lambda q,p : q
	clas_mom_derivs = lambda q,p : p
	delta_time = 2.
	tau = 8.

	QHamlitonian = lambda q,p : q * np.matrix([[0.,1.],[1.,0.]])

	test_cont = lib.Unravelling(CQstate, [L0], 0, 0, QHamlitonian, clas_pos_derivs, clas_mom_derivs, tau, delta_time, 0, 0, 0)
	test_cont._evolution_one_step(-1, 1.)

	obt_state = test_cont.CQstate.state
	obt_position = test_cont.CQstate.position
	obt_momentum = test_cont.CQstate.momentum
	obt_time = test_cont.CQstate.time

	exp_state = 1./sqrt(2.) * np.matrix([[(1. + sqrt(2))/sqrt(3)]
										 ,[1j * (1. - sqrt(2))/sqrt(3)]])
	exp_position = 5./2.
	exp_momentum = 0.
	exp_time = 2.

	np.testing.assert_almost_equal( obt_state, exp_state )
	np.testing.assert_almost_equal( obt_position, exp_position )
	np.testing.assert_almost_equal( obt_momentum, exp_momentum )
	np.testing.assert_almost_equal( obt_time, exp_time )
예제 #4
0
def test_cont_evo_Lindblad_only():
	
	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]]),0,0)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	clas_pos_derivs = lambda q,p : q
	clas_mom_derivs = lambda q,p : p
	delta_time = 2.
	tau = 8.

	QHamlitonian = lambda q,p : q * np.matrix([[0.,1.],[1.,0.]])

	test_cont = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, clas_pos_derivs, clas_mom_derivs, tau, delta_time, 0, 0, 0)
	test_cont._evolution_one_step(-1, 1.)

	obt_state = test_cont.CQstate.state
	obt_position = test_cont.CQstate.position
	obt_momentum = test_cont.CQstate.momentum
	obt_time = test_cont.CQstate.time

	exp_state = np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]])
	exp_position = 0.
	exp_momentum = 0.
	exp_time = 2.

	np.testing.assert_almost_equal( obt_state, exp_state )
	np.testing.assert_almost_equal( obt_position, exp_position )
	np.testing.assert_almost_equal( obt_momentum, exp_momentum )
	np.testing.assert_almost_equal( obt_time, exp_time )
예제 #5
0
def test_choose_evo_jump_0():

	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1./sqrt(3)]]),0,0)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	delta_time = 1.
	tau = 2.
	seed = 10
	rn.seed(seed)

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_evo = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, tau, delta_time, 0, seed, 0)
	obt_type, obt_norm = test_evo._choose_evolution()
	obt_randomness_first = test_evo.random_list[0]
	obt_randomness_second = test_evo.random_list[1]

	exp_type = 0
	exp_norm = 2./3.
	exp_randomness_first = 0.5714025946899135
	exp_randomness_second = 0.4288890546751146

	assert_equal( obt_type, exp_type, "Different type returned." )
	np.testing.assert_almost_equal( obt_norm, exp_norm )
	np.testing.assert_almost_equal( obt_randomness_first, exp_randomness_first )
	np.testing.assert_almost_equal( obt_randomness_second, exp_randomness_second )
예제 #6
0
def test_choose_evo_jump_1():
	
	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1./sqrt(3)]]),0,0)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	delta_time = 1.
	tau = 2.
	seed = 2
	rn.seed(seed)

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_evo = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, tau, delta_time, 0, seed, 0)
	obt_type, obt_norm = test_evo._choose_evolution()
	obt_randomness_first = test_evo.random_list[0]
	obt_randomness_second = test_evo.random_list[1]

	exp_type = 1
	exp_norm = 1./3.
	exp_randomness_first = 0.9560342718892494
	exp_randomness_second = 0.9478274870593494

	assert_equal( obt_type, exp_type, "Different type returned." )
	np.testing.assert_almost_equal( obt_norm, exp_norm )
	np.testing.assert_almost_equal( obt_randomness_first, exp_randomness_first )
	np.testing.assert_almost_equal( obt_randomness_second, exp_randomness_second )
예제 #7
0
def test_inconsistent_state_lindblad():

	CQstate = lib.CQState(np.matrix([[1.],[1.],[1.]]),0,0)

	L0 = np.matrix([[0.,1.],[0.,0.]])
	L1 = np.matrix([[0.,0.],[0.,1.]])

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	with assert_raises(RuntimeError):
		lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, 0, 0, 0, 0, 0)
예제 #8
0
def test_non_squared_lindblad():

	CQstate = lib.CQState(np.matrix([[1.],[1.]]),0,0)

	L0 = np.matrix([[0.,1.,0.],[0.,0.,3.]])
	L1 = np.matrix([[0.,0.,0.],[2.,0.,1.]])

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	with assert_raises(TypeError):
		lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, 0, 0, 0, 0, 0)
예제 #9
0
def test_different_shape():

	CQstate = lib.CQState(np.matrix([[1.],[1.]]),0,0)

	L0 = np.matrix([[0.,1.],[0.,0.]])
	L1 = np.matrix([[0.,0.,0.],[2.,0.,1.]])

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	with assert_raises(TypeError):
		lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, 0, 0, 0, 0, 0)
예제 #10
0
def test_non_self_adjoint_hamiltonian():

	CQstate = lib.CQState(np.matrix([[1.],[1.]]),0,0)

	L0 = np.matrix([[0.,1.],[0.,0.]])
	L1 = np.matrix([[0.,0.],[0.,1.]])

	QHamlitonian = lambda q,p : q * np.matrix([[1.,1j],[-2*1j,-3.]])

	with assert_raises(TypeError):
		lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, 0, 0, 0, 0, 0)
예제 #11
0
def test_probability_continuous():

	CQstate = lib.CQState(np.matrix([[1/sqrt(2)],[1j/sqrt(2)]]),0,0)
	L = np.matrix([[0.,1.],[0.,0.]])
	delta_time = 4.
	tau = 3.

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_prob = lib.Unravelling(CQstate, [L], 0, 0, QHamlitonian, 0, 0, tau, delta_time, 0, 0, 0)

	obt_prob = test_prob._probability_continuous()
	exp_prob = 1./3.

	np.testing.assert_almost_equal(obt_prob,exp_prob)
예제 #12
0
def test_probability_jump():

	CQstate = lib.CQState(np.matrix([[1/sqrt(3)],[1j*sqrt(2)/sqrt(3)]]),0,0)
	L0 = np.matrix([[0.,1.],[0.,0.]])
	L1 = np.matrix([[1j,0.],[0.,0.]])
	delta_time = 4.
	tau = 3.

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_prob = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, tau, delta_time, 0, 0, 0)

	obt_prob1 = test_prob._probability_jump(0)
	exp_prob1 = 2./3.
	obt_prob2 = test_prob._probability_jump(1)
	exp_prob2 = 1./3.

	np.testing.assert_almost_equal(obt_prob1,exp_prob1)
	np.testing.assert_almost_equal(obt_prob2,exp_prob2)
예제 #13
0
def test_sum_lindblad():

	CQstate = lib.CQState(np.matrix([[1.],[1.]]),0,0)

	L0 = np.matrix([[0.,1.],[0.,0.]])
	L1 = np.matrix([[0.,0.],[1j,0.]])

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_lindblad = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, 0, 0, 0, 0, 0)

	obt1 = test_lindblad.double_lindblad_ops[0]
	obt2 = test_lindblad.double_lindblad_ops[1]
	obt3 = test_lindblad.sum_lindblad_ops

	exp1 = np.matrix([[0.,0.],[0.,1.]])
	exp2 = np.matrix([[1.,0.],[0.,0.]])
	exp3 = np.matrix([[1.,0.],[0.,1.]])

	np.testing.assert_allclose( np.asarray(obt1), np.asarray(exp1) )
	np.testing.assert_allclose( np.asarray(obt2), np.asarray(exp2) )
	np.testing.assert_allclose( np.asarray(obt3), np.asarray(exp3) )
예제 #14
0
def test_choose_evo_continuous():

	CQstate = lib.CQState(np.matrix([[1./sqrt(2)],[1./sqrt(2)]]),0,0)
	L0 = np.matrix([[0.,0.],[1.,0.]])
	L1 = np.matrix([[0.,1.],[0.,0.]])
	delta_time = 1.
	tau = 2.
	seed = 1
	rn.seed(seed)

	QHamlitonian = lambda q,p : q * np.matrix([[1.,0.],[0.,-1.]])

	test_evo = lib.Unravelling(CQstate, [L0,L1], 0, 0, QHamlitonian, 0, 0, tau, delta_time, 0, seed, 0)
	obt_type, obt_norm = test_evo._choose_evolution()
	obt_randomness = test_evo.random_list[0]

	exp_type = -1
	exp_norm = 0.5
	exp_randomness = 0.13436424411240122

	assert_equal( obt_type, exp_type, "Different type returned." )
	np.testing.assert_almost_equal( obt_norm, exp_norm )
	np.testing.assert_almost_equal( obt_randomness, exp_randomness )
예제 #15
0
def test_jump_classical_degrees_of_freedom():

	CQstate = lib.CQState(np.matrix([[sqrt(2)/sqrt(3)],[1j*1./sqrt(3)]]),1./4.,2./3.)
	L0 = np.matrix([[1.,0.],[0.,0.]])
	L1 = np.matrix([[0.,0.],[0.,1.]])
	delta_time = 2.
	tau = 4.

	pos_derivs = [lambda q,p : - 1./3. * p, lambda q,p : 1./6. * p]
	mom_derivs = [lambda q,p : 1./8. * q, lambda q,p : - 1./4. * q]

	QHamlitonian = lambda q,p : q * np.matrix([[0.,1.],[1.,0.]])

	test_cont = lib.Unravelling(CQstate, [L0,L1], pos_derivs, mom_derivs, QHamlitonian, 0, 0, tau, delta_time, 0, 0, 0)
	test_cont._evolution_one_step(0, 1.)

	obt_position = test_cont.CQstate.position
	obt_momentum = test_cont.CQstate.momentum

	exp_position = 3./8.
	exp_momentum = 14./9.

	np.testing.assert_almost_equal( obt_position, exp_position )
	np.testing.assert_almost_equal( obt_momentum, exp_momentum )
예제 #16
0
qu_mom_derivs = [lambda q, p: 0., lambda q, p: 0.]

clas_pos_derivs = lambda q, p: 0.
clas_mom_derivs = lambda q, p: p

# Measure time before simulation
tstart = datetime.now()

for iteration in range(iterations):

    # Check if directory exists, otherwise create it
    output_directory = Path('./output/')
    output_directory.mkdir(parents=True, exist_ok=True)

    # Filename for output
    filename = './output/trajectory_{0}.dat'.format(str(iteration))

    # Create unravelling and evolve
    stern_gerlach = lib.Unravelling(copy(CQstate), [L0, L1], qu_pos_derivs,
                                    qu_mom_derivs, QHamlitonian,
                                    clas_pos_derivs, clas_mom_derivs, tau,
                                    delta_time, final_time, seed, filename)
    stern_gerlach.evolution()
    del stern_gerlach

# Measure time after simulation
tfinal = datetime.now()

# Print time for loading and for averaging
tsim = tfinal - tstart
print('Simulation time is {}\n'.format(tsim))