Esempio n. 1
0
 def test_spherical_commutator(self):
     # Define Spin Basis Operators
     s0 = la.SphericalSpinOperator((0, 0, 0, 0))
     si = la.SphericalSpinOperator((1, 0, 0, 0))
     sx = la.SphericalSpinOperator((0, 1, np.pi / 2, 0))
     sy = la.SphericalSpinOperator((0, 1, np.pi / 2, np.pi / 2))
     sz = la.SphericalSpinOperator((0, 1, 0, 0))
     self.assertEqual(s0, la.commutator(si, sx))
     self.assertEqual(la.commutator(sx, sy), -1 * la.commutator(sy, sx))
     self.assertEqual(2j * sz, la.commutator(sx, sy))
Esempio n. 2
0
 def setUp(self):
     self.i = (1., 0., 0., 0.)
     self.x = (0., 1., np.pi / 2, 0.)
     self.y = (0., 1., np.pi / 2, np.pi / 2)
     self.z = (0., 1., 0., 0.)
     self.si = la.SphericalSpinOperator(self.i)
     self.sx = la.SphericalSpinOperator(self.x)
     self.sy = la.SphericalSpinOperator(self.y)
     self.sz = la.SphericalSpinOperator(self.z)
     pass
Esempio n. 3
0
 def test_vector_grid_init_from_spherical_operator_mesh(self):
     ops = []
     for xx in r:
         for yy in t:
             for zz in p:
                 ops.append(la.SphericalSpinOperator((0, xx, yy, zz)))
     ops = np.reshape(ops, s_grid.shape)
     vector_grid = gr.VectorGrid(ops, s_grid)
     self.assertIs(vector_grid._operator_type, la.SphericalSpinOperator)
     self.assertIs(vector_grid._container_type, tuple)
     self.assertEqual(vector_grid._operator_dim, 4)
     self.assertTrue(np.array_equal(ops, vector_grid.data))
     self.assertEqual(vector_grid[0, 0, 0], (la.SphericalSpinOperator(
         (0, 0, 0, 0)), (0, 0, 0)))
Esempio n. 4
0
 def test_vector_grid_init_from_spherical_coordinate_mesh(self):
     ops_e = []
     for xx in r:
         for yy in t:
             for zz in p:
                 ops_e.append(la.SphericalSpinOperator((0, xx, yy, zz)))
     ops_e = np.reshape(ops_e, s_grid.shape)
     vector_grid = gr.VectorGrid(list(s_grid.mesh),
                                 s_grid,
                                 operator_type=la.SphericalSpinOperator)
     self.assertIs(vector_grid._operator_type, la.SphericalSpinOperator)
     self.assertIs(vector_grid._container_type, list)
     self.assertEqual(vector_grid._operator_dim, 4)
     self.assertTrue(np.array_equal(ops_e, vector_grid.data))
     self.assertEqual(vector_grid[0, 0, 0], (la.SphericalSpinOperator(
         (0, 0, 0, 0)), (0, 0, 0)))
Esempio n. 5
0
 def test_mixed_commutator(self):
     # Define Spin Basis Operators
     s0c = la.CartesianSpinOperator((0, 0, 0, 0))
     sic = la.CartesianSpinOperator((1, 0, 0, 0))
     sxc = la.CartesianSpinOperator((0, 1, 0, 0))
     syc = la.CartesianSpinOperator((0, 0, 1, 0))
     szc = la.CartesianSpinOperator((0, 0, 0, 1))
     # Define Spin Basis Operators
     s0s = la.SphericalSpinOperator((0, 0, 0, 0))
     sis = la.SphericalSpinOperator((1, 0, 0, 0))
     sxs = la.SphericalSpinOperator((0, 1, np.pi / 2, 0))
     sys = la.SphericalSpinOperator((0, 1, np.pi / 2, np.pi / 2))
     szs = la.SphericalSpinOperator((0, 1, 0, 0))
     self.assertAlmostEqual(s0c, la.commutator(sis, sxc))
     self.assertAlmostEqual(la.commutator(sxs, syc),
                            -1 * la.commutator(sys, sxc))
     self.assertAlmostEqual(2j * szs, la.commutator(sxc, sys))
Esempio n. 6
0
    def test_vectorize_spherical(self):
        si = la.SphericalSpinOperator((1, 0, 0, 0))
        sx = la.SphericalSpinOperator((0, 1, pi / 2, 0))
        sy = la.SphericalSpinOperator((0, 1, pi / 2, pi / 2))
        sz = la.SphericalSpinOperator((0, 1, 0, 0))
        ops = np.array([[si, sx], [sy, sz]])
        expected = (np.array([[1, 0], [0, 0]]), np.array([[0, 1], [0, 0]]),
                    np.array([[0, 0], [1, 0]]), np.array([[0, 0], [0, 1]]))

        x1 = (0, 1)
        x2 = (0, 1)
        grid = gr.CartesianGrid((x1, x2))

        op_grid = gr.GridData(ops, grid)
        expected = gr.GridData(expected, grid)
        calculated = gr.vectorize_operator_grid(op_grid)

        self.assertAlmostEqual(expected, calculated)
Esempio n. 7
0
 def test_vector_grid_cartesian_vectors(self):
     ops = []
     for xx in r:
         for yy in t:
             for zz in p:
                 ops.append(la.SphericalSpinOperator((0, xx, yy, zz)))
     ops = np.reshape(ops, s_grid.shape)
     vector_grid = gr.VectorGrid(ops, s_grid)
     vectors = vector_grid.cartesian_vectors
     self.assertTrue(np.array_equal(vectors, s_grid.cartesian))
Esempio n. 8
0
 def test_spherical_gradient(self):
     funct = s_grid.mesh[0]
     data_grid = gr.DataGrid(funct, s_grid)
     ops = []
     for xx in r:
         for yy in t:
             for zz in p:
                 ops.append(la.SphericalSpinOperator((0, 1, 0, 0)))
     ops = np.reshape(ops, s_grid.shape)
     vector_grid = gr.VectorGrid(ops, s_grid)
     self.assertAlmostEqual(
         vector_grid, data_grid.gradient(la.SphericalSpinOperator, tuple))
Esempio n. 9
0
 def test_nonzero_unitary_dynamics_mixed_spin_operator(self):
     rhox = la.CartesianSpinOperator((0.5, 0.5, 0., 0.))
     rhoy = la.CartesianSpinOperator((0.5, 0., 0.5, 0.))
     rhoxy = la.CartesianSpinOperator((0.5, 0.5, 0.5, 0.))
     rhoxdot_expected = la.CartesianSpinOperator((0., 0., 1., 0.))
     rhoydot_expected = la.CartesianSpinOperator((0., -1., 0., 0.))
     rhoxydot_expected = la.CartesianSpinOperator((0., -1., 1., 0.))
     ham = la.SphericalSpinOperator((0, 1, 0, 0))
     rhoxdot_calc = hbar * unitary_derivative(rhox, ham)
     rhoydot_calc = hbar * unitary_derivative(rhoy, ham)
     rhoxydot_calc = hbar * unitary_derivative(rhoxy, ham)
     self.assertAlmostEqual(rhoxdot_calc, rhoxdot_expected)
     self.assertAlmostEqual(rhoydot_calc, rhoydot_expected)
     self.assertAlmostEqual(rhoxydot_calc, rhoxydot_expected)
Esempio n. 10
0
 def test_nonzero_unitary_dynamics_spherical_spin_operator(self):
     rhox = la.SphericalSpinOperator((0.5, 0.5, np.pi/2, 0.))
     rhoy = la.SphericalSpinOperator((0.5, 0.5, np.pi/2, np.pi/2))
     rhoxy = la.SphericalSpinOperator((0.5, 0.5, np.pi/2, np.pi/4))
     rhoxdot_expected = 1 / hbar * la.SphericalSpinOperator((0., 1., np.pi/2, np.pi/2))
     rhoydot_expected = 1 / hbar * la.SphericalSpinOperator((0., 1., np.pi/2, np.pi))
     rhoxydot_expected = 1 / hbar * la.SphericalSpinOperator((0., 1., np.pi/2, 3*np.pi/4))
     ham = la.SphericalSpinOperator((0, 1, 0, 0))
     rhoxdot_calc = unitary_derivative(rhox, ham)
     rhoydot_calc = unitary_derivative(rhoy, ham)
     rhoxydot_calc = unitary_derivative(rhoxy, ham)
     self.assertEqual(rhoxdot_calc, rhoxdot_expected)
     self.assertEqual(rhoydot_calc, rhoydot_expected)
     self.assertEqual(rhoxydot_calc, rhoxydot_expected)
Esempio n. 11
0
 def test_steady_state_unitary_dynamics_mixed_spin_operator(self):
     rho0 = la.SphericalSpinOperator((1 / 2, 0, 0, 0))
     rhodot_expected = la.SphericalSpinOperator((0, 0, 0, 0))
     ham = la.CartesianSpinOperator((0, 0, 0, 1))
     self.assertEqual(unitary_derivative(rho0, ham), rhodot_expected)
Esempio n. 12
0
 def test_init_length_assertion(self):
     """ Tests that the constructor correctly raises initialization error if the wrong length input provided """
     with self.assertRaises(AssertionError):
         la.SphericalSpinOperator((1., 0., 0.))
     with self.assertRaises(AssertionError):
         la.SphericalSpinOperator((1., 0., 0., 0., 0., 0.))