Exemplo n.º 1
0
    def __init__(self, H, dt):
        self.size = H.size

        H = np.array(H.matrix.data, dtype=np.complex128)

        self.data = np.matrix(lg.expm(-1j * H * dt), dtype=np.complex128)
        self.matrix = Matrix(self.size, self.size, dtype=np.complex128)
        self.matrix.data = self.data
Exemplo n.º 2
0
    def __init__(self, capacity, cavity):
        self.cavity = cavity
        self.g = cavity.g

        self.D = {}
        self.count = 0

        M = capacity
        self.n = n = cavity.n
        wc = cavity.wc
        wa = cavity.wa
        g = cavity.g

        _min = min(M, n)

        dime = (_min + 1)**2
        # print("dime:", dime)
        H = np.array([np.zeros(dime) for i in range(0, dime)])

        self.matrix = Matrix(dime, dime, dtype=np.complex128)

        i = 1

        self.states = states = {}

        count = 0

        for i1 in range(0, _min + 1):
            for i2 in range(0, min(n, M - i1) + 1):
                j = 1

                states[count] = [i1, i2]

                count += 1
                # D[count] = [I-i1-i2, i1, i2]

                for j1 in range(0, _min + 1):
                    for j2 in range(0, min(n, M - j1) + 1):
                        if i1 != j1:
                            p = [i1, j1]
                        elif i2 != j2:
                            p = [i2, j2]
                        else:
                            p = [1, 2]

                        mi = min(p[0], p[1])

                        kappa = sqrt((n - mi) * (mi + 1))

                        if abs(i1 - j1) + abs(i2 - j2) == 1:
                            _max = max(M - i1 - i2, M - j1 - j2)
                            self.matrix.data[i - 1, j - 1] = g * sqrt(
                                max(M - i1 - i2, M - j1 - j2)) * kappa
                            # print(i1, j1, i2, j2, "H[", i-1, j-1, "] = ", H[i-1][j-1], ": g *
                            # sqrt(", max(M - i1 - i2, M - j1 - j2), ") * sqrt(", (n - mi) * (mi + 1),
                            # ")")

                        elif abs(i1 - j1) + abs(i2 - j2) == 0:
                            self.matrix.data[
                                i - 1,
                                j - 1] = (M - (i1 + i2)) * wc + (i1 + i2) * wa

                            # print("H[",i-1,",",j-1,"]=", self.matrix.data[i-1, j-1])
                            # print(i1, j1, i2, j2, "H[", i-1, j-1, "] = ", H[i-1][j-1], ": wc *", (M - (i1 + i2)), " + wa * ", (i1 + i2))
                        else:
                            self.matrix.data[i - 1, j - 1] = 0

                        j += 1

                i += 1
        self.data = np.matrix(H)
        self.size = np.shape(self.data)[0]
Exemplo n.º 3
0
    def __init__(self, capacity, cavity):
        self.cavity = cavity

        self.states = {}

        count = 0

        self.capacity = capacity
        M = capacity
        self.n = n = cavity.n
        wc = cavity.wc
        wa = cavity.wa
        g = cavity.g

        self.DIME = []

        self.H_dims = {}

        # ---------------------------------------
        for I in range(M, -1, -1):
            _min = min(I, n)

            dime = (_min + 1)**2

            self.DIME.append(dime)

        # for I in range(M, -1, -1):
        #     _min = min(I, n)

        #     count = 0

        #     for i1 in range(0, _min + 1):
        #         for i2 in range(0, min(n, I - i1) + 1):
        #             count += 1

        #     self.DIME.append(count)

        self.size = np.sum(self.DIME)
        self.matrix = Matrix(self.size, self.size, dtype=np.complex128)

        d = 0

        for I in range(M, -1, -1):
            i = 1

            COUNT = count

            for i1 in range(0, min(I, n) + 1):
                for i2 in range(0, min(n, I - i1) + 1):
                    j = 1

                    self.states[count] = [I - i1 - i2, i1, i2]

                    for j1 in range(0, min(I, n) + 1):
                        for j2 in range(0, min(n, I - j1) + 1):
                            if i1 != j1:
                                p = [i1, j1]
                            elif i2 != j2:
                                p = [i2, j2]
                            else:
                                p = [1, 2]

                            mi = min(p[0], p[1])

                            kappa = sqrt((n - mi) * (mi + 1))

                            count += (i == j)

                            if abs(i1 - j1) + abs(i2 - j2) == 1:
                                self.matrix.data[
                                    COUNT + i - 1, COUNT + j - 1] = g * sqrt(
                                        max(I - i1 - i2, I - j1 - j2)) * kappa
                            elif abs(i1 - j1) + abs(i2 - j2) == 0:
                                self.matrix.data[
                                    COUNT + i - 1, COUNT + j -
                                    1] = (I - (i1 + i2)) * wc + (i1 + i2) * wa
                            else:
                                self.matrix.data[COUNT + i - 1,
                                                 COUNT + j - 1] = 0

                            j += 1

                    i += 1

        self.matrix.data = self.matrix.data[0:count, 0:count]
        self.data = self.matrix.data
        self.size = np.shape(self.matrix.data)[0]
        self.matrix.m = self.matrix.n = self.size
Exemplo n.º 4
0
 def write_to_file(self, filename):
     U = Matrix(self.size, self.size)
     print(U.m)
     U.data = self.data
     U.write_to_file(filename)
Exemplo n.º 5
0
    def __init__(self, capacity, cavity, mu):
        Assert(isinstance(capacity, int), "capacity is not integer", cf())
        Assert(capacity > 0, "capacity <= 0", cf())

        Assert(isinstance(cavity, list), "capacity is not list", cf())

        for _ in range(len(cavity)):
            Assert(isinstance(cavity[_], Cavity), "is not cavity", cf())

        self.capacity = capacity

        self.cavity = cavity

        self.n = []

        self.wc = []
        self.wa = []

        self.g = []

        for i in range(len(cavity)):
            self.n.append(cavity[i].n)

            self.wc.append(cavity[i].wc)
            self.wa.append(cavity[i].wa)

            self.g.append(cavity[i].g)

        self.mu = mu

        self.states = self.get_states()
        self.get_states_bin()
        # print(self.states)
        # exit(1)

        self.size = len(self.states)

        self.matrix = Matrix(self.size, self.size, dtype=np.complex128)

        for i in range(self.size):
            i_state = self.states[i]

            i_ph = []
            i_at = []

            i_ph.append(i_state[0][0])
            i_at.append(i_state[0][1])

            i_ph.append(i_state[1][0])
            i_at.append(i_state[1][1])

            for j in range(self.size):
                j_state = self.states[j]

                j_ph = []
                j_at = []

                j_ph.append(j_state[0][0])
                j_at.append(j_state[0][1])

                j_ph.append(j_state[1][0])
                j_at.append(j_state[1][1])

                if i_state == j_state:
                    for _ in range(len(cavity)):
                        self.matrix.data[i, j] += self.wc[_] * i_ph[_]

                        for n_ in range(self.n[_]):
                            self.matrix.data[i,
                                             j] += self.wa[_][n_] * i_at[_][n_]
                else:
                    diff_cv = 0

                    for cv_ in range(2):
                        if i_state[cv_] != j_state[cv_]:
                            diff_cv += 1
                            cv = cv_

                    if diff_cv == 1:
                        d_ph = j_ph[cv] - i_ph[cv]

                        if abs(d_ph) == 1:
                            diff_at_cnt = 0

                            for n_ in range(len(i_at[cv])):
                                d_at = j_at[cv][n_] - i_at[cv][n_]

                                if d_ph + d_at == 0:
                                    diff_at_cnt += 1
                                    diff_at_num = n_
                                elif d_at != 0:
                                    diff_at_cnt = 0
                                    break

                                if diff_at_cnt > 1:
                                    break

                            if diff_at_cnt == 1:
                                self.matrix.data[i, j] = self.g[cv][diff_at_num] * \
                                    sqrt(max(i_ph[cv], j_ph[cv]))

                                # print(self.states[i], '->', self.states[j], self.matrix.data[i, j])

                    else:
                        d_ph_0 = j_ph[0] - i_ph[0]
                        d_ph_1 = j_ph[1] - i_ph[1]

                        if abs(d_ph_0) == 1 and (d_ph_1 + d_ph_0 == 0):
                            if i_at[0] == j_at[0] and i_at[1] == j_at[1]:
                                if j_ph[0] > i_ph[0]:
                                    self.matrix.data[i, j] += mu * \
                                        a_plus(i_ph[0]) * a_minus(i_ph[1])
                                else:
                                    self.matrix.data[i, j] += mu * \
                                        a_plus(i_ph[1]) * a_minus(i_ph[0])

                                # print(self.states[i], '->', self.states[j], self.matrix.data[i, j])

        # for i in range(self.size):
        #     for j in range(self.size):
        #         if self.matrix.data[i, j] != self.matrix.data[j, i]:
        #             print(self.states[i], self.states[j], self.matrix.data[i, j], self.matrix.data[j, i])

        self.matrix.check_hermiticity()

        return
Exemplo n.º 6
0
    def __init__(self, capacity, cavity):
        Assert(isinstance(capacity, int), "capacity is not integer", cf())
        Assert(capacity > 0, "capacity <= 0", cf())

        # Assert(isinstance(cavity, "BipartiteGeneral.Cavity.Cavity"), "capacity is not integer", cf())

        self.capacity = capacity
        self.cavity = cavity

        self.n = cavity.n

        self.wc = cavity.wc
        self.wa = cavity.wa
        self.g = cavity.g

        self.states = self.get_states()
        self.get_states_bin()
        # self.print_states()

        self.size = len(self.states)

        self.matrix = Matrix(self.size, self.size, dtype=np.complex128)
        # self.matrix_html = np.empty([self.size, self.size], dtype=">U900")

        for i in range(self.size):
            i_state = self.states[i]

            i_ph = i_state[0]
            i_at = i_state[1]

            for j in range(self.size):
                j_state = self.states[j]

                j_ph = j_state[0]
                j_at = j_state[1]

                # self.matrix_html[i, j] = ""

                if i_state == j_state:
                    self.matrix.data[i, j] = self.wc * i_ph
                    # if(self.matrix_html[i][j] != ""):
                    # self.matrix_html[i][j] += "+"
                    # self.matrix_html[i][j] += "wc" + DOT() + str(i_ph) + " "

                    for n_ in range(len(i_at)):
                        if i_at[n_] != 0:
                            self.matrix.data[i, j] += self.wa[n_] * i_at[n_]

                            # if(self.matrix_html[i][j] != ""):
                            # self.matrix_html[i][j] += "+"
                            # self.matrix_html[i][j] += "wa" + SUB(n_) + DOT() + str(i_at[n_]) + " "
                else:
                    d_ph = j_ph - i_ph

                    if abs(d_ph) == 1:
                        diff_at_cnt = 0

                        for n_ in range(len(i_at)):
                            d_at = j_at[n_] - i_at[n_]

                            if d_ph + d_at == 0:
                                diff_at_cnt += 1
                                diff_at_num = n_
                            elif d_at != 0:
                                diff_at_cnt = 0
                                break

                            if diff_at_cnt > 1:
                                break

                        if diff_at_cnt == 1:
                            if d_ph > 0:
                                k = a_cross(i_ph) * i_at[diff_at_num]

                                self.matrix.data[i,
                                                 j] = self.g[diff_at_num] * k
                                # self.matrix_html[i][j] = "g" + SUB(diff_at_num) + DOT() + A_CROSS(i_ph) + \
                                # """<math display="block"><mrow><msqrt><mn> &middot; """ + \
                                # A_CROSS(i_ph) + """</mn></msqrt><mo>=</mo></mrow></math>"""
                            else:
                                k = a_cross(j_ph) * j_at[diff_at_num]

                                self.matrix.data[i,
                                                 j] = self.g[diff_at_num] * k
                                # self.matrix_html[i][j] = "g" + SUB(diff_at_num) + DOT() + A_CROSS(j_ph)

        self.matrix.check_hermiticity()

        return
Exemplo n.º 7
0
    def __init__(self, capacity, cavity_1, cavity_2, mu):
        self.cavity_1 = cavity_1

        self.capacity = capacity

        self.cavity_1 = cavity_1
        self.cavity_2 = cavity_2

        self.n_1 = n_1 = cavity_1.n
        self.n_2 = n_2 = cavity_2.n

        wc_1 = cavity_1.wc
        wc_2 = cavity_2.wc

        wa_1 = cavity_1.wa
        wa_2 = cavity_2.wa

        g_1 = cavity_1.g
        g_2 = cavity_2.g

        self.init_states()
        self.init_bin_states()
        # ---------------------------------------
        # ---------------------------------------
        self.matrix = Matrix(self.size, self.size, dtype=np.complex128)

        cnk = Cnk(capacity)

        for i in range(self.size):
            st_i = self.states[i]

            ph_i = [st_i[0][0], st_i[1][0]]
            at_i = np.array([st_i[0][1], st_i[1][1]])

            for j in range(0, self.size):
                st_j = self.states[j]

                ph_j = [st_j[0][0], st_j[1][0]]
                at_j = np.array([st_j[0][1], st_j[1][1]])

                if i == j:
                    self.matrix.data[i, j] = wc_1 * \
                        ph_i[0] + wc_2 * ph_i[1] + wa_1 * \
                        at_i[0][0] + wa_2 * at_i[1][0]

                    # print(self.states[i], '->',
                    # self.states[j], self.matrix.data[i, j])
                elif abs(ph_j[0] - ph_i[0]) == 1 and (
                        ph_j[0] - ph_i[0]) == -(ph_j[1] - ph_i[1]) and np.all(
                            at_i == at_j):
                    d_ph_0 = ph_j[0] - ph_i[0]
                    d_ph_1 = ph_j[1] - ph_i[1]

                    if abs(d_ph_0) == 1 and (d_ph_1 + d_ph_0 == 0):
                        if at_i[0] == at_j[0] and at_i[1] == at_j[1]:
                            a_1 = min(at_i[0][0], at_j[0][0])
                            a_2 = min(at_i[1][0], at_j[1][0])

                            if ph_j[0] > ph_i[0]:
                                self.matrix.data[i, j] += mu * \
                                    a_plus(ph_i[0]) * a_minus(ph_i[1]
                                                              )  # * cnk.get(n_1, a_1+1)
                                # * C_n_k(n_2, at_j[0])
                            else:
                                self.matrix.data[i, j] += mu * \
                                    a_plus(ph_i[1]) * a_minus(ph_i[0]
                                                              )  # * cnk.get(n_2, a_2+1)
                                # * C_n_k(n_2, at_j[0])

                            # self.matrix.data[i, j] *= cnk.get(n_1, a_1) * cnk.get(n_2, a_2)
                    # self.matrix.data[i, j] = mu * sqrt(max(ph_j[0], ph_j[1]))

                    # print(self.states[i], '->',
                    # self.states[j], self.matrix.data[i, j])
                else:
                    if np.all(st_i[1] == st_j[1]):
                        if abs(at_i[0][0] - at_j[0][0]) == 1:
                            p = min(ph_i[0], ph_j[0])
                            a = min(at_i[0][0], at_j[0][0])

                            self.matrix.data[i, j] = g_1 * (n_1 - a) * sqrt(
                                (p + 1) * cnk.get(n_1, a) /
                                cnk.get(n_1, a + 1))

                            # print(
                            # self.states[i], '->', self.states[j], self.matrix.data[i, j])
                    elif np.all(st_i[0] == st_j[0]):
                        if abs(at_i[1][0] - at_j[1][0]) == 1:
                            p = min(ph_i[1], ph_j[1])
                            a = min(at_i[1][0], at_j[1][0])

                            self.matrix.data[i, j] = g_2 * (n_2 - a) * sqrt(
                                (p + 1) * cnk.get(n_2, a) /
                                cnk.get(n_2, a + 1))