Exemple #1
0
def CoulombFactory(site0,
                   site1,
                   *,
                   spin0=0,
                   spin1=0,
                   orbit0=0,
                   orbit1=0,
                   coeff=1.0):
    """
    Generate Coulomb interaction term: '$U n_i n_j$'.

    These parameters suffixed with '0' are for the 1st operator and '1' for
    2nd operator.

    Parameters
    ----------
    site0, site1 : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        `site0` and `site1` should be 1D array with length 1, 2 or 3.
    spin0, spin1 : int, optional, keyword-only
        The spin index of the single-particle state.
        Default: 0.
    orbit0, orbit1 : int, optional, keyword-only
        The orbit index of the single-particle state.
        Default: 0.
    coeff : int or float, optional, keyword-only
        The coefficient of this term.
        Default: 1.0.

    Returns
    -------
    term : ParticleTerm
        The corresponding Coulomb interaction term.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import CoulombFactory
    >>> term = CoulombFactory((0, 0), (1, 1), spin0=0, spin1=1)
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=CREATION, site=(1, 1), spin=1, orbit=0)
        AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0)
    """

    c0 = AoC(CREATION, site=site0, spin=spin0, orbit=orbit0)
    a0 = AoC(ANNIHILATION, site=site0, spin=spin0, orbit=orbit0)
    c1 = AoC(CREATION, site=site1, spin=spin1, orbit=orbit1)
    a1 = AoC(ANNIHILATION, site=site1, spin=spin1, orbit=orbit1)
    return ParticleTerm((c0, a0, c1, a1),
                        coeff=coeff,
                        classification="Coulomb")
def test_MultiKrylov():
    import logging
    import sys
    logging.basicConfig(stream=sys.stdout, level=logging.INFO)

    site_num = 12
    sites = np.arange(site_num).reshape((-1, 1))
    state_indices_table = IndexTable(StateID(site=site) for site in sites)
    bases = np.arange(1 << site_num, dtype=np.uint64)

    HM = 0.0
    for i in range(site_num):
        C = AoC(CREATION, site=sites[i])
        A = AoC(ANNIHILATION, site=sites[(i + 1) % site_num])
        HM += ParticleTerm([C, A]).matrix_repr(state_indices_table, bases)
    HM += HM.getH()
    (GE, ), GS = eigsh(HM, k=1, which="SA")

    excited_states = {}
    i, j = np.random.randint(0, site_num, 2)
    keys = ["Ci", "Cj", "Ai", "Aj"]
    otypes = [CREATION, CREATION, ANNIHILATION, ANNIHILATION]
    indices = [i, j, i, j]
    for key, otype, index in zip(keys, otypes, indices):
        excited_states[key] = AoC(otype, site=sites[i]).matrix_repr(
            state_indices_table, bases
        ).dot(GS)


    krylovs_matrix, krylovs_vectors = lanczos.MultiKrylov(HM, excited_states)
    omega = np.random.random() + 0.01j

    pairs = [("Ci", "Cj"), ("Ai", "Aj")]
    for coeff, (key0, key1) in zip([-1, 1], pairs):
        HMProjected = krylovs_matrix[key1]
        krylov_space_dim = HMProjected.shape[0]
        I = np.identity(krylov_space_dim)
        bra = krylovs_vectors[key1][key0]
        ket = krylovs_vectors[key1][key1]
        gf = np.vdot(
            bra, np.linalg.solve(
                (omega + coeff * GE) * I + coeff * HMProjected, ket
            )
        )
        I = np.identity(len(bases))
        gf_ref = np.vdot(
            excited_states[key0],
            np.linalg.solve(
                (omega + coeff * GE) * I + coeff * HM.toarray(),
                excited_states[key1]
            )
        )
        assert np.allclose(gf, gf_ref)
Exemple #3
0
def Annihilator(site, spin=0, orbit=0):
    """
    Generate annihilation operator: $c_i$.

    Parameters
    ----------
    site : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        The `site` parameter should be 1D array with length 1,2 or 3.
    spin : int, optional
        The spin index of the single-particle state.
        Default: 0.
    orbit : int, optional
        The orbit index of the single-particle state.
        Default: 0.

    Returns
    -------
    operator : AoC
        The corresponding annihilation operator.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import Annihilator
    >>> Annihilator((0, 0), spin=0)
    AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0)
    """

    return AoC(ANNIHILATION, site=site, spin=spin, orbit=orbit)
Exemple #4
0
def HubbardFactory(site, *, orbit=0, coeff=1.0):
    """
    Generate Hubbard term: '$U n_{i\\uparrow} n_{i\\downarrow}$'.

    This function is valid only for spin-1/2 system.

    Parameters
    ----------
    site : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        `site` should be 1D array with length 1,2 or 3.
    orbit : int, optional, keyword-only
        The orbit index of the single-particle state.
        Default: 0.
    coeff : int or float, optional, keyword-only
        The coefficient of this term.
        Default: 1.0.

    Returns
    -------
    term : ParticleTerm
        The corresponding Hubbard term.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import HubbardFactory
    >>> term = HubbardFactory(site=(0, 0))
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=1, orbit=0)
        AoC(otype=ANNIHILATION, site=(0, 0), spin=1, orbit=0)
        AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0)
    """

    c_up = AoC(CREATION, site=site, spin=SPIN_UP, orbit=orbit)
    c_down = AoC(CREATION, site=site, spin=SPIN_DOWN, orbit=orbit)
    a_up = AoC(ANNIHILATION, site=site, spin=SPIN_UP, orbit=orbit)
    a_down = AoC(ANNIHILATION, site=site, spin=SPIN_DOWN, orbit=orbit)
    return ParticleTerm((c_up, a_up, c_down, a_down),
                        coeff=coeff,
                        classification="Coulomb")
Exemple #5
0
    def Schwinger(self):
        """
        Return the Schwinger Fermion representation of this spin operator.
        """

        coordinate = self.coordinate
        C_UP = AoC(otype=CREATION, site=coordinate, spin=SPIN_UP)
        C_DOWN = AoC(otype=CREATION, site=coordinate, spin=SPIN_DOWN)
        A_UP = AoC(otype=ANNIHILATION, site=coordinate, spin=SPIN_UP)
        A_DOWN = AoC(otype=ANNIHILATION, site=coordinate, spin=SPIN_DOWN)

        terms = []
        SMatrix = self.matrix()
        for row_index, row_aoc in enumerate((C_UP, C_DOWN)):
            for col_index, col_aoc in enumerate((A_UP, A_DOWN)):
                coeff = SMatrix[row_index, col_index]
                if coeff != 0.0:
                    terms.append(ParticleTerm([row_aoc, col_aoc], coeff=coeff))
        return terms
Exemple #6
0
    def test_Schwinger(self):
        site = np.random.random(3)
        sx = SpinOperator("x", site=site)
        sy = SpinOperator("y", site=site)
        sz = SpinOperator("z", site=site)
        sp = SpinOperator("p", site=site)
        sm = SpinOperator("m", site=site)
        C_UP = AoC(CREATION, site=site, spin=SPIN_UP)
        C_DOWN = AoC(CREATION, site=site, spin=SPIN_DOWN)
        A_UP = AoC(ANNIHILATION, site=site, spin=SPIN_UP)
        A_DOWN = AoC(ANNIHILATION, site=site, spin=SPIN_DOWN)

        terms = sx.Schwinger()
        assert len(terms) == 2
        assert terms[0].coeff == 0.5
        assert terms[1].coeff == 0.5
        assert terms[0].components == (C_UP, A_DOWN)
        assert terms[1].components == (C_DOWN, A_UP)

        terms = sy.Schwinger()
        assert len(terms) == 2
        assert terms[0].coeff == -0.5j
        assert terms[1].coeff == 0.5j
        assert terms[0].components == (C_UP, A_DOWN)
        assert terms[1].components == (C_DOWN, A_UP)

        terms = sz.Schwinger()
        assert len(terms) == 2
        assert terms[0].coeff == 0.5
        assert terms[1].coeff == -0.5
        assert terms[0].components == (C_UP, A_UP)
        assert terms[1].components == (C_DOWN, A_DOWN)

        terms = sp.Schwinger()
        assert len(terms) == 1
        assert terms[0].coeff == 1
        assert terms[0].components == (C_UP, A_DOWN)

        terms = sm.Schwinger()
        assert len(terms) == 1
        assert terms[0].coeff == 1
        assert terms[0].components == (C_DOWN, A_UP)
Exemple #7
0
def CPFactory(site, *, spin=0, orbit=0, coeff=1.0):
    """
    Generate chemical potential term: '$\\mu c_i^{\\dagger} c_i$'.

    Parameters
    ----------
    site : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        The `site` parameter should be 1D array with length 1,2 or 3.
    spin : int, optional, keyword-only
        The spin index of the single-particle state.
        Default: 0.
    orbit : int, optional, keyword-only
        The orbit index of the single-particle state.
        Default: 0.
    coeff : int or float, optional, keyword-only
        The coefficient of this term.
        Default: 1.0.

    Returns
    -------
    term : ParticleTerm
        The corresponding chemical potential term.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import CPFactory
    >>> term = CPFactory((0, 0))
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0)
    """

    c = AoC(CREATION, site=site, spin=spin, orbit=orbit)
    a = AoC(ANNIHILATION, site=site, spin=spin, orbit=orbit)
    return ParticleTerm((c, a), coeff=coeff, classification="number")
Exemple #8
0
def PairingFactory(site0,
                   site1,
                   *,
                   spin0=0,
                   spin1=0,
                   orbit0=0,
                   orbit1=0,
                   coeff=1.0,
                   which="h"):
    """
    Generate pairing term: '$p c_i^{\\dagger} c_j^{\\dagger}$' or '$p c_i c_j$'.

    These parameters suffixed with '0' are for the 1st operator and '1' for
    2nd operator.

    Parameters
    ----------
    site0, site1 : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        `site0` and `site1` should be 1D array with length 1, 2 or 3.
    spin0, spin1 : int, optional, keyword-only
        The spin index of the single-particle state.
        Default: 0.
    orbit0, orbit1 : int, optional, keyword-only
        The orbit index of the single-particle state.
        Default: 0.
    coeff : int, float or complex, optional, keyword-only
        The coefficient of this term.
        Default: 1.0.
    which : str, optional, keyword-only
        Determine whether to generate a particle- or hole-pairing term.
        Valid values:
            ["h" | "hole"] for hole-pairing;
            ["p" | "particle"] for particle-pairing.
        Default: "h".

    Returns
    -------
    term : ParticleTerm
        The corresponding pairing term.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import PairingFactory
    >>> term = PairingFactory((0, 0), (1, 1), spin0=0, spin1=1, which="h")
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=ANNIHILATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0)
    >>> term = PairingFactory((0, 0), (1, 1), spin0=0, spin1=1, which="p")
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=CREATION, site=(1, 1), spin=1, orbit=0)
    """

    assert which in ("h", "hole", "p", "particle")

    otype = ANNIHILATION if which in ("h", "hole") else CREATION
    aoc0 = AoC(otype, site=site0, spin=spin0, orbit=orbit0)
    aoc1 = AoC(otype, site=site1, spin=spin1, orbit=orbit1)
    return ParticleTerm((aoc0, aoc1), coeff=coeff)
Exemple #9
0
def HoppingFactory(site0,
                   site1,
                   *,
                   spin0=0,
                   spin1=None,
                   orbit0=0,
                   orbit1=None,
                   coeff=1.0):
    """
    Generate hopping term: '$t c_i^{\\dagger} c_j$'.

    These parameters suffixed with '0' are for the creation operator and '1'
    for annihilation operator.

    Parameters
    ----------
    site0, site1 : list, tuple or 1D np.ndarray
        The coordinates of the localized single-particle state.
        `site0` and `site1` should be 1D array with length 1, 2 or 3.
    spin0, spin1 : int, optional, keyword-only
        The spin index of the single-particle state.
        The default value for `spin0` is 0;
        The default value for `spin1` is None, which implies that `spin1`
        takes the same value as `spin0`.
    orbit0, orbit1 : int, optional, keyword-only
        The orbit index of the single-particle state.
        The default value for `orbit0` is 0;
        The default value for `orbit1` is None, which implies that `orbit1`
        takes the same value as `orbit0`.
    coeff : int, float or complex, optional, keyword-only
        The coefficient of this term.
        Default: 1.0.

    Returns
    -------
    term : ParticleTerm
        The corresponding hopping term.

    Examples
    --------
    >>> from HamiltonianPy.quantumoperator import HoppingFactory
    >>> term = HoppingFactory(site0=(0, 0), site1=(1, 1), spin0=1)
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=1, orbit=0)
        AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0)
    >>> term = HoppingFactory(site0=(0, 0), site1=(1, 1), spin0=0, spin1=1)
    >>> print(term)
    The coefficient of this term: 1.0
    The component operators:
        AoC(otype=CREATION, site=(0, 0), spin=0, orbit=0)
        AoC(otype=ANNIHILATION, site=(1, 1), spin=1, orbit=0)
    """

    if spin1 is None:
        spin1 = spin0
    if orbit1 is None:
        orbit1 = orbit0

    c = AoC(CREATION, site=site0, spin=spin0, orbit=orbit0)
    a = AoC(ANNIHILATION, site=site1, spin=spin1, orbit=orbit1)
    classification = "hopping" if c.state != a.state else "number"
    return ParticleTerm((c, a), coeff=coeff, classification=classification)
Exemple #10
0
    def test_Schwinger(self):
        sites = np.array([[0, 0], [1, 1]])
        sx0 = SpinOperator("x", site=sites[0])
        sx1 = SpinOperator("x", site=sites[1])
        sy0 = SpinOperator("y", site=sites[0])
        sy1 = SpinOperator("y", site=sites[1])
        sz0 = SpinOperator("z", site=sites[0])
        sz1 = SpinOperator("z", site=sites[1])

        C0_UP = AoC(CREATION, site=sites[0], spin=SPIN_UP)
        C1_UP = AoC(CREATION, site=sites[1], spin=SPIN_UP)
        C0_DOWN = AoC(CREATION, site=sites[0], spin=SPIN_DOWN)
        C1_DOWN = AoC(CREATION, site=sites[1], spin=SPIN_DOWN)
        A0_UP = AoC(ANNIHILATION, site=sites[0], spin=SPIN_UP)
        A1_UP = AoC(ANNIHILATION, site=sites[1], spin=SPIN_UP)
        A0_DOWN = AoC(ANNIHILATION, site=sites[0], spin=SPIN_DOWN)
        A1_DOWN = AoC(ANNIHILATION, site=sites[1], spin=SPIN_DOWN)

        sx0_times_sx1 = SpinInteraction((sx0, sx1))
        sy0_times_sy1 = SpinInteraction((sy0, sy1))
        sz0_times_sz1 = SpinInteraction((sz0, sz1))

        sx0_times_sx1_schwinger = sx0_times_sx1.Schwinger()
        sy0_times_sy1_schwinger = sy0_times_sy1.Schwinger()
        sz0_times_sz1_schwinger = sz0_times_sz1.Schwinger()

        assert sx0_times_sx1_schwinger[0].coeff == 0.25
        assert sx0_times_sx1_schwinger[0].components == (C0_UP, A0_DOWN, C1_UP,
                                                         A1_DOWN)
        assert sx0_times_sx1_schwinger[1].coeff == 0.25
        assert sx0_times_sx1_schwinger[1].components == (C0_UP, A0_DOWN,
                                                         C1_DOWN, A1_UP)
        assert sx0_times_sx1_schwinger[2].coeff == 0.25
        assert sx0_times_sx1_schwinger[2].components == (C0_DOWN, A0_UP, C1_UP,
                                                         A1_DOWN)
        assert sx0_times_sx1_schwinger[3].coeff == 0.25
        assert sx0_times_sx1_schwinger[3].components == (C0_DOWN, A0_UP,
                                                         C1_DOWN, A1_UP)

        assert sy0_times_sy1_schwinger[0].coeff == -0.25
        assert sy0_times_sy1_schwinger[0].components == (C0_UP, A0_DOWN, C1_UP,
                                                         A1_DOWN)
        assert sy0_times_sy1_schwinger[1].coeff == 0.25
        assert sy0_times_sy1_schwinger[1].components == (C0_UP, A0_DOWN,
                                                         C1_DOWN, A1_UP)
        assert sy0_times_sy1_schwinger[2].coeff == 0.25
        assert sy0_times_sy1_schwinger[2].components == (C0_DOWN, A0_UP, C1_UP,
                                                         A1_DOWN)
        assert sy0_times_sy1_schwinger[3].coeff == -0.25
        assert sy0_times_sy1_schwinger[3].components == (C0_DOWN, A0_UP,
                                                         C1_DOWN, A1_UP)

        assert sz0_times_sz1_schwinger[0].coeff == 0.25
        assert sz0_times_sz1_schwinger[0].components == (C0_UP, A0_UP, C1_UP,
                                                         A1_UP)
        assert sz0_times_sz1_schwinger[1].coeff == -0.25
        assert sz0_times_sz1_schwinger[1].components == (C0_UP, A0_UP, C1_DOWN,
                                                         A1_DOWN)
        assert sz0_times_sz1_schwinger[2].coeff == -0.25
        assert sz0_times_sz1_schwinger[2].components == (C0_DOWN, A0_DOWN,
                                                         C1_UP, A1_UP)
        assert sz0_times_sz1_schwinger[3].coeff == 0.25
        assert sz0_times_sz1_schwinger[3].components == (C0_DOWN, A0_DOWN,
                                                         C1_DOWN, A1_DOWN)