Esempio n. 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")
Esempio n. 2
0
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)
Esempio n. 3
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")
Esempio n. 4
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
Esempio n. 5
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")
Esempio n. 6
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)
Esempio n. 7
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)