コード例 #1
0
ファイル: MPS_MC.py プロジェクト: lcauser/KMC
    def excitation_density_sq(self):
        # Get the number of sites
        num_sites = self.num_sites

        # Define local operators
        I = np.zeros((1, 2, 2, 1))
        I[0, :, :, 0] = np.identity(2)
        n = np.zeros((1, 2, 2, 1))
        n[0, :, :, 0] = np.array([[0, 0], [0, 1]])

        # Set the excitation to zero
        excitation = 0

        # Loop through each site
        for site in range(num_sites):
            # Construct an MPO with n at site and I everywhere else
            MPO = mp.mpo(2, num_sites, 1, I)
            MPO.edit_structure(site, n)

            # Find the expection wrt psi
            excitation += mp.expectation(MPO, self.psi)**2

        # Divide by the number of sites
        excitation = excitation / num_sites

        # Return excitation
        return excitation
コード例 #2
0
ファイル: spin_mps.py プロジェクト: lcauser/KMC
def correlation(MPS, distance=1):
    # Get the number of sites
    sites = MPS.length

    # Operators
    I = np.array([[1, 0], [0, 1]])
    n = np.array([[0, 0], [0, 1]])

    # Find the amount of pairs
    pairs = sites - distance

    # Store correlation
    correlation = 0

    # Loop through each pair
    for site in range(pairs):
        # Create an MPO
        local = np.zeros((1, 2, 2, 1))
        local[0, :, :, 0] = I
        mpo = mp.mpo(2, sites, 1, local)

        # Add the n operator to the correct sites
        nlocal = np.zeros((1, 2, 2, 1))
        nlocal[0, :, :, 0] = n
        mpo.edit_structure(site, nlocal)
        mpo.edit_structure(site + distance, nlocal)

        # Calculate the expectation
        correlation += mp.expectation(mpo, MPS)

    return correlation / pairs
コード例 #3
0
ファイル: spin_mps.py プロジェクト: lcauser/KMC
def excitation(MPS):
    #Get the number of sites
    sites = MPS.length

    # Create the MPO
    I = np.array([[1, 0], [0, 1]])
    n = np.array([[0, 0], [0, 1]])
    local = np.zeros((2, 2, 2, 2))
    local[0, :, :, 0] = I
    local[1, :, :, 0] = n
    local[1, :, :, 1] = I
    ni = mp.mpo(2, sites, 2, local)

    # Calculate excitation
    excitation = mp.expectation(ni, MPS) / sites

    return excitation / mp.dot(MPS, MPS)
コード例 #4
0
ファイル: spin_mps.py プロジェクト: lcauser/KMC
def occupation(MPS):
    # Get the number of sites
    sites = MPS.length

    # Store occupations
    occupations = np.zeros(sites)

    # Loop through each site
    for site in range(sites):
        # Create the MPO
        I = np.array([[1, 0], [0, 1]])
        n = np.array([[0, 0], [0, 1]])
        local = np.zeros((1, 2, 2, 1))
        local[0, :, :, 0] = I
        ni = mp.mpo(2, sites, 1, local)
        nlocal = np.zeros((1, 2, 2, 1))
        nlocal[0, :, :, 0] = n
        ni.edit_structure(site, nlocal)

        # Calculate occupation
        occupations[site] = mp.expectation(ni, MPS)

    return occupations / mp.dot(MPS, MPS)
コード例 #5
0
ファイル: doob.py プロジェクト: lcauser/KMC
    def __init__(self, N, c, s, psi):
        """ Creates a model for N two-level systems.
        
        Parameters:
            N (int): The number of spins
            c (double): The bias for up spins, must be between 0 and 1
                        (default = 0.5)
        """

        # Validate inputs
        if not isinstance(N, int):
            print("N must be an integer.")
            return None

        # Construct left vector
        Qdag_local = np.zeros((1, 2, 2, 1))
        Qdag_local[0, :, :, 0] = np.array([[np.sqrt(1 - c)**-1, 0],
                                           [0, np.sqrt(c)**-1]])
        Qdag = mp.mpo(2, N, 1, Qdag_local)
        left = mp.apply_operator(copy.deepcopy(psi), Qdag, conjugate=True)

        # Store the state of the system
        self.size = N
        self.c = c
        self.s = s
        self.psi = psi
        self.left = left
        self.state = np.zeros(N, dtype=np.bool_)
        self.transition_rates = np.zeros(N)
        self.original_transition_rates = np.zeros(N)

        # Tensor blocks
        self.left_blocks = [[] for i in range(N)]
        self.right_blocks = [[] for i in range(N)]

        return None
コード例 #6
0
ファイル: spin_mps.py プロジェクト: lcauser/KMC
def DW_correlation_disconnected(MPS, distance=1):
    # Get the number of sites
    sites = MPS.length

    norm = mp.dot(MPS, MPS)

    # Operators
    I = np.array([[1, 0], [0, 1]])
    n = np.array([[0, 0], [0, 1]])

    # Find the amount of pairs
    pairs = sites + 1 - distance

    # Store correlation
    correlation = 0

    # Get occupations
    occupations = DW_occupation(MPS)

    # Loop through each pair
    for site in range(pairs):
        if distance == 1:
            if site == 0:
                # Create an MPO to measure
                local = np.zeros((1, 2, 2, 1))
                local[0, :, :, 0] = I
                mpo = mp.mpo(2, sites, 1, local)

                site1 = np.zeros((1, 2, 2, 1))
                site1[0, :, :, 0] = n

                site2 = np.zeros((1, 2, 2, 1))
                site2[0, :, :, 0] = I - n

                mpo.edit_structure(site, site1)
                mpo.edit_structure(site + 1, site2)
            elif site == sites - distance:
                # Create an MPO to measure
                local = np.zeros((1, 2, 2, 1))
                local[0, :, :, 0] = I
                mpo = mp.mpo(2, sites, 1, local)

                site1 = np.zeros((1, 2, 2, 1))
                site1[0, :, :, 0] = I - n

                site2 = np.zeros((1, 2, 2, 1))
                site2[0, :, :, 0] = n

                mpo.edit_structure(site - 1, site1)
                mpo.edit_structure(site, site2)
            else:
                # Create an MPO to measure
                local = np.zeros((2, 2, 2, 2))
                local[0, :, :, 0] = I
                local[1, :, :, 1] = I
                mpo = mp.mpo(2, sites, 2, local)

                if site == 1:
                    site1 = np.zeros((1, 2, 2, 2))
                    site1[0, :, :, 0] = n
                    site1[0, :, :, 1] = I - n
                else:
                    site1 = np.zeros((2, 2, 2, 2))
                    site1[0, :, :, 0] = n
                    site1[1, :, :, 1] = I - n

                site2 = np.zeros((2, 2, 2, 2))
                site2[0, :, :, 0] = I - n
                site2[1, :, :, 1] = n

                if site == sites - 1 - distance:
                    site3 = np.zeros((2, 2, 2, 1))
                    site3[0, :, :, 0] = n
                    site3[1, :, :, 0] = I - n
                else:
                    site3 = np.zeros((2, 2, 2, 2))
                    site3[0, :, :, 0] = n
                    site3[1, :, :, 1] = I - n

                if site != 1:
                    local = np.zeros((1, 2, 2, 2))
                    local[0, :, :, 0] = I
                    local[0, :, :, 1] = I
                    mpo.edit_structure(0, local)
                if site != sites - 1 - distance:
                    local = np.zeros((2, 2, 2, 1))
                    local[0, :, :, 0] = I
                    local[1, :, :, 0] = I
                    mpo.edit_structure(sites - 1, local)

                mpo.edit_structure(site - 1, site1)
                mpo.edit_structure(site, site2)
                mpo.edit_structure(site + 1, site3)

        else:
            if site == 0:
                # Create an MPO to measure
                local = np.zeros((2, 2, 2, 2))
                local[0, :, :, 0] = I
                local[1, :, :, 1] = I
                mpo = mp.mpo(2, sites, 2, local)

                site1 = np.zeros((1, 2, 2, 2))
                site1[0, :, :, 0] = n
                site1[0, :, :, 1] = n

                site2 = np.zeros((2, 2, 2, 2))
                site2[0, :, :, 0] = I - n
                site2[1, :, :, 1] = n

                site3 = np.zeros((2, 2, 2, 2))
                site3[0, :, :, 0] = n
                site3[1, :, :, 1] = I - n

                site4 = np.zeros((2, 2, 2, 1))
                site4[0, :, :, 0] = I
                site4[1, :, :, 0] = I

                mpo.edit_structure(site, site1)
                mpo.edit_structure(site + distance - 1, site2)
                mpo.edit_structure(site + distance, site3)
                mpo.edit_structure(sites - 1, site4)
            elif site == sites - distance:
                # Create an MPO to measure
                local = np.zeros((2, 2, 2, 2))
                local[0, :, :, 0] = I
                local[1, :, :, 1] = I
                mpo = mp.mpo(2, sites, 2, local)

                site1 = np.zeros((2, 2, 2, 2))
                site1[0, :, :, 0] = n
                site1[1, :, :, 1] = I - n

                site2 = np.zeros((2, 2, 2, 2))
                site2[0, :, :, 0] = I - n
                site2[1, :, :, 1] = n

                site3 = np.zeros((2, 2, 2, 1))
                site3[0, :, :, 0] = n
                site3[1, :, :, 0] = n

                site4 = np.zeros((1, 2, 2, 2))
                site4[0, :, :, 0] = I
                site4[0, :, :, 1] = I

                mpo.edit_structure(0, site4)
                mpo.edit_structure(site - 1, site1)
                mpo.edit_structure(site, site2)
                mpo.edit_structure(site - 1 + distance, site3)
            else:
                # Create an MPO to measure
                local = np.zeros((4, 2, 2, 4))
                local[0, :, :, 0] = I
                local[1, :, :, 1] = I
                local[2, :, :, 2] = I
                local[3, :, :, 3] = I
                mpo = mp.mpo(2, sites, 4, local)

                if site == 1:
                    site1 = np.zeros((1, 2, 2, 4))
                    site1[0, :, :, 0] = n
                    site1[0, :, :, 1] = I - n
                    site1[0, :, :, 2] = n
                    site1[0, :, :, 3] = I - n
                else:
                    site1 = np.zeros((4, 2, 2, 4))
                    site1[0, :, :, 0] = n
                    site1[1, :, :, 1] = I - n
                    site1[2, :, :, 2] = n
                    site1[3, :, :, 3] = I - n

                site2 = np.zeros((4, 2, 2, 4))
                site2[0, :, :, 0] = I - n
                site2[1, :, :, 1] = n
                site2[2, :, :, 2] = I - n
                site2[3, :, :, 3] = n

                site3 = np.zeros((4, 2, 2, 4))
                site3[0, :, :, 0] = n
                site3[1, :, :, 1] = I - n
                site3[2, :, :, 2] = I - n
                site3[3, :, :, 3] = n

                if site == sites - 1 - distance:
                    site4 = np.zeros((4, 2, 2, 1))
                    site4[0, :, :, 0] = I - n
                    site4[1, :, :, 0] = n
                    site4[2, :, :, 0] = n
                    site4[3, :, :, 0] = I - n
                else:
                    site4 = np.zeros((4, 2, 2, 4))
                    site4[0, :, :, 0] = I - n
                    site4[1, :, :, 1] = n
                    site4[2, :, :, 2] = n
                    site4[3, :, :, 3] = I - n

                if site != 1:
                    local = np.zeros((1, 2, 2, 4))
                    local[0, :, :, 0] = I
                    local[0, :, :, 1] = I
                    local[0, :, :, 2] = I
                    local[0, :, :, 3] = I
                    mpo.edit_structure(0, local)
                if site != sites - 1 - distance:
                    local = np.zeros((4, 2, 2, 1))
                    local[0, :, :, 0] = I
                    local[1, :, :, 0] = I
                    local[2, :, :, 0] = I
                    local[3, :, :, 0] = I
                    mpo.edit_structure(sites - 1, local)

                mpo.edit_structure(site - 1, site1)
                mpo.edit_structure(site, site2)
                mpo.edit_structure(site - 1 + distance, site3)
                mpo.edit_structure(site + distance, site4)

        correl = mp.expectation(mpo, MPS) / norm
        correlation += correl - occupations[site] * occupations[site +
                                                                distance]
    return correlation / pairs
コード例 #7
0
ファイル: spin_mps.py プロジェクト: lcauser/KMC
def DW_occupation(MPS):
    # Get the number of sites
    sites = MPS.length

    # Store occupations
    occupations = np.zeros(sites + 1)

    norm = mp.dot(MPS, MPS)

    # Local operators
    I = np.array([[1, 0], [0, 1]])
    n = np.array([[0, 0], [0, 1]])

    # Loop through each site
    for site in range(sites + 1):
        if site == 0:
            # Create local identity operator
            local = np.zeros((1, 2, 2, 1))
            local[0, :, :, 0] = I

            # Create local n operator
            nlocal1 = np.zeros((1, 2, 2, 1))
            nlocal1[0, :, :, 0] = n

            # Create MPO
            ni = mp.mpo(2, sites, 1, local)
            ni.edit_structure(site, nlocal1)

            # Calculate occupation
            occupations[site] = mp.expectation(ni, MPS)
        elif site == sites:
            # Create local identity operator
            local = np.zeros((1, 2, 2, 1))
            local[0, :, :, 0] = I

            # Create local n operator
            nlocal1 = np.zeros((1, 2, 2, 1))
            nlocal1[0, :, :, 0] = n

            # Create MPO
            ni = mp.mpo(2, sites, 1, local)
            ni.edit_structure(site - 1, nlocal1)

            # Calculate occupation
            occupations[site] = mp.expectation(ni, MPS)
        else:
            # Create local identity operator
            local = np.zeros((1, 2, 2, 1))
            local[0, :, :, 0] = I

            # Create local n operator
            nlocal1 = np.zeros((1, 2, 2, 1))
            nlocal1[0, :, :, 0] = n

            # Create local 1-n operator
            nlocal2 = np.zeros((1, 2, 2, 1))
            nlocal2[0, :, :, 0] = I - n

            # Create MPO
            ni1 = mp.mpo(2, sites, 1, local)
            ni1.edit_structure(site - 1, nlocal1)
            ni1.edit_structure(site, nlocal2)

            ni2 = mp.mpo(2, sites, 1, local)
            ni2.edit_structure(site - 1, nlocal2)
            ni2.edit_structure(site, nlocal1)

            # Calculate occupation
            occupations[site] += mp.expectation(ni1, MPS)
            occupations[site] += mp.expectation(ni2, MPS)

    return occupations / norm
コード例 #8
0
ファイル: MPS_MC.py プロジェクト: lcauser/KMC
    def __init__(self,
                 c,
                 s,
                 psi,
                 num_sites,
                 tmax,
                 activity=True,
                 occupations=True,
                 AC=False,
                 AC_low=-2,
                 AC_points=1000,
                 timescale=False,
                 AC_int=False,
                 AC_int_timescale=False,
                 correlations=True,
                 correlations_range=10):
        # Set parameters
        self.c = c
        self.num_sites = psi.length
        self.s = s

        # Probability distribtion
        self.psi = psi

        # Left vectors
        Qdag_local = np.zeros((1, 2, 2, 1))
        Qdag_local[0, :, :, 0] = np.array([[np.sqrt(1 - c)**-1, 0],
                                           [0, np.sqrt(c)**-1]])
        Qdag = mp.mpo(2, self.num_sites, 1, Qdag_local)
        self.left = mp.apply_operator(copy.deepcopy(self.psi),
                                      Qdag,
                                      conjugate=True)

        # Store the number of sites time for each trajectory
        self.num_sites = num_sites
        self.tmax = tmax

        # Create relevent storage
        self.num_sims = 0

        # Count the activity
        self.count_activity = activity
        self.activity = 0

        # Count the occupations
        self.count_occupations = occupations
        self.occupations = 0

        # Count the correlations
        self.count_correlations = correlations
        self.correlations = np.zeros(correlations_range)
        self.correlations_range = correlations_range

        # Count the AC
        self.count_AC = AC
        self.AC_times = np.zeros(AC_points)
        self.AC_times[1:] = np.logspace(AC_low, np.log10(tmax), AC_points - 1)
        self.AC = np.zeros(AC_points)

        # Count the TI AC
        self.count_timescale = timescale
        self.timescale = 0

        # Count the AC int
        self.count_AC_int = AC_int
        self.AC_int = np.zeros(AC_points)

        # Count the TI AC
        self.count_AC_int_timescale = AC_int_timescale
        self.AC_int_timescale = 0

        self.configs = []
        self.escaperates = []
        self.original_escaperates = []