def test_no_operators(): n = 4 l = 10 dim = 3 spas = SpatialOrbitalSystem(n, RandomBasisSet(l, dim)) gos = GeneralOrbitalSystem(n, RandomBasisSet(l, dim)) assert not spas.has_one_body_time_evolution_operator assert not gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator np.testing.assert_allclose(spas.h_t(10), spas.h) np.testing.assert_allclose(spas.u_t(10), spas.u) np.testing.assert_allclose(gos.h_t(10), gos.h) np.testing.assert_allclose(gos.u_t(10), gos.u) spas.set_time_evolution_operator( [], add_h_0=False, add_u_0=False, ) gos.set_time_evolution_operator([], add_h_0=False, add_u_0=False) assert not spas.has_one_body_time_evolution_operator assert not gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator np.testing.assert_allclose(spas.h_t(0), np.zeros_like(spas.h)) np.testing.assert_allclose(spas.u_t(0), np.zeros_like(spas.u)) np.testing.assert_allclose(gos.h_t(0), np.zeros_like(gos.h)) np.testing.assert_allclose(gos.u_t(0), np.zeros_like(gos.u))
def construct_general_orbital_system(self, a=[1, 0], b=[0, 1], anti_symmetrize=True): r"""Function constructing a ``GeneralOrbitalSystem`` by duplicating every basis element of current system. That is, .. math:: \psi(\mathbf{r}, t) \to \psi(x, t) = \psi(\mathbf{r}, t) \sigma(m_2), where :math:`x = (\mathbf{r}, m_s)` is a generalized coordinate of both position :math:`\mathbf{r}` and spin :math:`m_s`, with :math:`\sigma(m_s)` one of the two spin-functions. Note that this function creates a copy of the basis set. Parameters ---------- a : list, np.array The :math:`\alpha` (up) spin basis vector. Default is :math:`\alpha = (1, 0)^T`. b : list, np.array The :math:`\beta` (down) spin basis vector. Default is :math:`\beta = (0, 1)^T`. Note that ``a`` and ``b`` are assumed orthonormal. anti_symmetrize : bool Whether or not to create the anti-symmetrized two-body elements. Default is ``True``. Returns ------- GeneralOrbitalSystem The doubly degenerate general spin-orbital system. See Also ------- BasisSet.change_to_general_orbital_basis """ gos = GeneralOrbitalSystem( self.n * 2, self._basis_set.copy_basis(), a=a, b=b, anti_symmetrize=anti_symmetrize, ) import copy if not self._time_evolution_operator is None: gos.set_time_evolution_operator( copy.deepcopy(self._time_evolution_operator)) return gos
def test_multiple_time_evolution_operators(): n = 4 l = 10 dim = 3 spas = SpatialOrbitalSystem(n, RandomBasisSet(l, dim)) gos = GeneralOrbitalSystem(n, RandomBasisSet(l, dim)) assert not spas.has_one_body_time_evolution_operator assert not gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator spas.set_time_evolution_operator( [ CustomOneBodyOperator(2, spas.h), CustomOneBodyOperator(3, spas.s), AdiabaticSwitching(2), ], add_u_0=False, ) gos.set_time_evolution_operator( ( CustomOneBodyOperator(1, gos.h), CustomOneBodyOperator(3, gos.s), CustomOneBodyOperator(-2, gos.position[0]), ), add_h_0=False, ) assert spas.has_one_body_time_evolution_operator assert gos.has_one_body_time_evolution_operator assert spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator np.testing.assert_allclose( spas.h_t(0), spas.h + spas.h * 2 + spas.s * 3, ) np.testing.assert_allclose(spas.u_t(0), 2 * spas.u) np.testing.assert_allclose( gos.h_t(0), gos.h + gos.s * 3 - gos.position[0] * 2, ) np.testing.assert_allclose(gos.u_t(0), gos.u)
def test_single_dipole_time_evolution_operator(): n = 4 l = 10 dim = 3 omega = 0.25 spas = SpatialOrbitalSystem(n, RandomBasisSet(l, dim)) gos = GeneralOrbitalSystem(n, RandomBasisSet(l, dim)) field = lambda t: np.sin(omega * 2) polarization = np.zeros(dim) polarization[0] = 1 spas.set_time_evolution_operator( DipoleFieldInteraction( field, polarization, )) gos.set_time_evolution_operator( DipoleFieldInteraction( field, polarization, )) assert spas.has_one_body_time_evolution_operator assert gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator for t in [0, 0.1, 0.5, 1.3]: np.testing.assert_allclose( spas.h_t(t), spas.h - field(t) * spas.dipole_moment[0], ) np.testing.assert_allclose( gos.h_t(t), gos.h - field(t) * gos.dipole_moment[0], ) np.testing.assert_allclose(spas.u_t(t), spas.u) np.testing.assert_allclose(gos.u_t(t), gos.u)
def test_single_time_evolution_operator(): n = 4 l = 10 dim = 3 spas = SpatialOrbitalSystem(n, RandomBasisSet(l, dim)) gos = GeneralOrbitalSystem(n, RandomBasisSet(l, dim)) assert not spas.has_one_body_time_evolution_operator assert not gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator np.testing.assert_allclose(spas.h_t(10), spas.h) np.testing.assert_allclose(spas.u_t(10), spas.u) np.testing.assert_allclose(gos.h_t(10), gos.h) np.testing.assert_allclose(gos.u_t(10), gos.u) spas.set_time_evolution_operator(CustomOneBodyOperator(2, spas.h), add_h_0=False) gos.set_time_evolution_operator(CustomOneBodyOperator(3, gos.h), add_u_0=False) assert spas.has_one_body_time_evolution_operator assert gos.has_one_body_time_evolution_operator assert not spas.has_two_body_time_evolution_operator assert not gos.has_two_body_time_evolution_operator np.testing.assert_allclose( spas.h_t(0), spas.h * 2, ) np.testing.assert_allclose(spas.u_t(0), spas.u) np.testing.assert_allclose( gos.h_t(0), gos.h + gos.h * 3, ) np.testing.assert_allclose(gos.u_t(0), np.zeros_like(gos.u))