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 )
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 )
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 )
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 )
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 )
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 )
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)
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)
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)
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)
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)
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)
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) )
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 )
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 )
from math import sqrt from copy import copy """ Stern Gerlach with diagonal Lindblad operators. This main file, together with the ipython notebook in this repository, is an example created for helping the user familiarise with the code. In this main, the trajectories of a CQ system representing a qubit particle interacting with its own position degrees of freedom are created. In the python notebook, these trajectories are processed and visualised. """ """ The initial CQ state is: - quantum state : \ket{+}, eigenstate of Pauli X with eigenvalue 1 - position : 0, start with zero position - momentum : 0, start with zero momentum """ CQstate = lib.CQState( np.matrix([[1. / sqrt(2.) + 0.j], [1. / sqrt(2.) + 0.j]]), 0., 0.) """ The time scale: - tau : rate of jump - delta_time : time interval for single evolution - final time : final time we are interested in """ tau = 1e-2 delta_time = 2.5e-5 final_time = 5e-2 # Random seed seed = 1424 rn.seed(seed) # Number of iterations iterations = 200