示例#1
0
    def __init__(self, states, init_state, amplitude=1):
        # Assert(isinstance(states, dict), "states is not dict")
        Assert(isinstance(init_state, list), "init_state is not list")

        Assert(len(states) > 1, "w_0 is not set")

        self.states = states
        self.init_state = init_state
        self.amplitude = amplitude

        k_found = None

        for k, v in enumerate(states):
            if init_state == v:
                k_found = k

                break

        Assert(k_found is not None, "w_0 is not set")

        super(WaveFunction, self).__init__(m=len(states),
                                           n=1,
                                           dtype=np.complex128)

        self.data[k_found, 0] = amplitude
示例#2
0
    def __init__(self, m, n, dtype):
        Assert(m > 0, "m <= 0")
        Assert(n > 0, "n <= 0")

        self.m = m
        self.n = n

        self.dtype = dtype

        self.data = lil_matrix((m, n), dtype=dtype)
示例#3
0
    def __init__(self, args):
        for i in [
                'title',
                'x_title',
                'y_title',
                'z_title',
                'x_range',
                'y_range',
                'x_data',
                'y_data',
                'z_data',
                'width',
                'height',
                'ticks',
        ]:
            Assert(i in args, i + ' not in args')

            self.title = args['title']

            self.x_title = args['x_title']
            self.y_title = args['y_title']
            self.z_title = args['z_title']

            # self.x_axis = args['x_axis']
            # self.y_axis = args['y_axis']
            # self.z_axis = args['z_axis']

            self.width = args['width']
            self.height = args['height']

            self.x_data = args['x_data']
            self.y_data = args['y_data']
            self.z_data = args['z_data']

            self.x_range = args['x_range']
            self.y_range = args['y_range']

            self.x_ticktext = args['x_ticktext']
            self.x_tickvals = args['x_tickvals']

            self.y_ticktext = args['y_ticktext']
            self.y_tickvals = args['y_tickvals']
            # self.z_range = args['z_range']

            self.t_coeff = 1

            self.ticks = args['ticks']

            self.to_file = args['to_file'] if 'to_file' in args else None

            if 'scale' in args:
                self.scale = args['scale']
            else:
                self.scale = {
                    'x': 1,
                    'y': 1,
                    'z': 1,
                }
示例#4
0
    def set_ampl(self, state, amplitude=1):
        k_found = None

        for k, v in enumerate(self.states):
            if state == v:
                print("k_found =", k_found)
                break

        Assert(k_found is not None, "w_0 is not set")
        self.data[k_found, 0] = amplitude
示例#5
0
    def check_states(self):
        try:
            # print(self.capacity)
            # print(self.states)
            Assert(len(self.states) > 0, "len(states) <= 0", FILE(), LINE())

            for state in self.states.values():
                ph = state[0]
                at = state[1]

                Assert(0 <= ph <= self.capacity, "incorrect state " + str(state), FILE(), LINE())
                Assert(ph + np.sum(at) == self.capacity, "incorrect state " + str(state), FILE(), LINE())
                for n_ in range(len(at)):
                    Assert(0 <= at[n_] <= self.n_levels, "incorrect state " + str(state), FILE(), LINE())
        except:
            print_error("incorrect states generation", FILE(), LINE())
            exit(1)

        return
示例#6
0
    def set_ampl(self, state, amplitude=1):
        k_found = None

        for k, v in self.states.items():
            print(state, v)
            if state == v:
                k_found = k

                break

        Assert(k_found is not None, "w_0 is not set", cf())
        self.data[k_found] = amplitude
示例#7
0
    def check_unitarity(self):
        data = self.data
        data_H = self.data.getH()

        I = np.eye(len(data))

        Assert(
            np.all(abs(data.dot(data_H) - I) < eps)
            and np.all(abs(data_H.dot(data) - I) < eps),
            "matrix is not unitary")

        return
示例#8
0
def frequency_unit(frequency):
    Assert(frequency >= 1, 'frequency < 1 Hz')

    if frequency >= 1e9:
        unit = 'GHz'
    elif frequency >= 1e6:
        unit = 'MHz'
    elif frequency >= 1e3:
        unit = 'KHz'
    else:
        unit = 'Hz'

    return unit
示例#9
0
def time_unit(time):
    Assert(time >= 1e-9, 'time < 1 ns', FILE(), LINE())

    if time >= 1:
        unit = 's'
    elif time >= 1e-3:
        unit = 'ms'
    elif time >= 1e-6:
        unit = 'mks'
    elif time >= 1e-9:
        unit = 'ns'

    return unit
示例#10
0
    def __init__(self, states, init_state, amplitude=1):
        Assert(isinstance(states, dict), "states is not dict", FILE(), LINE())
        Assert(isinstance(init_state, list),
               "init_state is not list", FILE(), LINE())

        Assert(len(states) > 1, "w_0 is not set", FILE(), LINE())

        self.states = states

        k_found = None

        for k, v in states.items():
            if init_state == v:
                k_found = k

                break

        Assert(k_found, "w_0 is not set", FILE(), LINE())

        super(WaveFunction, self).__init__(
            m=len(states), n=1, dtype=np.complex128)

        self.data[k_found] = amplitude
示例#11
0
    def __init__(self, wc, wa, g, n_atoms, n_levels=2):
        Assert(isinstance(wc, (int, float)),
               "wc is not numeric", FILE(), LINE())
        Assert(isinstance(wa, (int, float)),
               "wa is not numeric", FILE(), LINE())
        Assert(isinstance(g, (int, float)), "g is not numeric", FILE(), LINE())
        Assert(isinstance(n_atoms, int),
               "n_atoms is not integer", FILE(), LINE())

        Assert(wc > 0, "wc <= 0", FILE(), LINE())
        Assert(wa > 0, "wa <= 0", FILE(), LINE())
        Assert(g > 0, "g <= 0", FILE(), LINE())
        Assert(n_atoms > 0, "n <= 0", FILE(), LINE())

        self.wc = wc
        self.wa = wa

        self.g = g

        self.n_atoms = n_atoms
        self.n_levels = n_levels
示例#12
0
 def check_hermiticity(ro):
     Assert(self.is_hermitian(), "not hermitian")
示例#13
0
 def check_hermiticity(self):
     Assert(np.all(abs(self.data - self.data.getH()) < eps),
            "matrix is not hermitian")
示例#14
0
    def normalize(self):
        nnorm = norm(self.data)
        Assert(nnorm > 0, "norm <= 0")

        self.data /= nnorm
示例#15
0
        cavity = Cavity(config.wc, config.wa, g, config.n_atoms)

        # print(type(cavity))
        cavity.info()
        # exit(0)
        H = Hamiltonian(config.capacity, cavity)

        if state_type == 't_0':
            w_0 = WaveFunction(states=H.states, init_state=[1, [0, 0]])
        elif state_type == 's_2':
            w_0 = WaveFunction(states=H.states, init_state=[1, [0, 1]], amplitude=1./sqrt(2)) - \
                WaveFunction(states=H.states, init_state=[
                             1, [1, 0]], amplitude=1./sqrt(2))
        else:
            Assert(0 == 1, 'undefined state type')

        config_dt = (0.01 / l)

        z_data_g = []

        ro_0 = DensityMatrix(w_0)

        T_list = []
        sink_list = []

        run({
            "ro_0": ro_0,
            "H": H,
            "dt": config_dt,
            "sink_list": sink_list,
示例#16
0
        print('\tl:', to_Hz(l))
        print()

        cavity = Cavity(config.wc, config.wa, g, config.n_atoms)

        cavity.info()

        H = Hamiltonian(config.capacity, cavity)

        if state_type == 't_0':
            w_0 = WaveFunction(states=H.states, init_state=[1, [0, 0]])
        elif state_type == 's_2':
            w_0 = WaveFunction(states=H.states, init_state=[1, [0, 1]], amplitude=1./sqrt(2)) - \
                WaveFunction(states=H.states, init_state=[1, [1, 0]], amplitude=1./sqrt(2))
        else:
            Assert(0 == 1, 'undefined state type', FILE(), LINE())

        config_dt = (0.01 / l)

        z_data_g = []

        ro_0 = DensityMatrix(w_0)

        T_list = []
        sink_list = []

        run_in_out({
            "ro_0": ro_0,
            "H": H,
            "dt": config_dt,
            "sink_list": sink_list,
    sink_list = pickle_load(path + '/sink_list_' + w_0['name'] + '.pkl')
    # sink_list = list_from_csv('MM/M_' + str(coeff) + '/sink_' + w_0['name'] + '.csv')
    sink_list = np.array(sink_list, dtype=np.float64)

    sink_list /= np.sum(sink_list, dtype=np.float64)

    M = 0

    for i in range(len(T_list)):
        M += sink_list[i] * T_list[i]

    if len(M_list) != 0 and M_list[-1] <= M:
        print(np.sum(sink_list))
        print(sink_list, len(sink_list))
        Assert(
            M_list[-1] >= M,
            str(w_0['name']) + ' ' + str(coeff) + ': ' + str(M_list[-1]) +
            ' < ' + str(M), FILE(), LINE())

    M_list.append(M)
    # gamma.append(coeff)

    M_list = np.array(M_list)

    if max(M_list) > 1e6:
        M_list *= 1e-6
        M_str = '10<sup>6</sup>'
        # M_str = '10<sup>6</sup>'
    elif max(M_list) > 1e3:
        M_list *= 1e-3
        M_str = '10<sup>3</sup>'
        # M_str = '10<sup>3</sup>'
示例#18
0
    def __init__(self, capacity, cavity):
        Assert(isinstance(capacity, int), "capacity is not integer", FILE(), LINE())
        Assert(capacity >= 0, "capacity <= 0", FILE(), LINE())

        print("Hamiltonian", capacity)
        # Assert(isinstance(cavity, "BipartiteGeneral.Cavity.Cavity"), "capacity is not integer", FILE(), LINE())

        self.capacity = capacity
        self.cavity = cavity

        self.n_atoms = cavity.n_atoms

        self.wc = cavity.wc
        self.wa = cavity.wa
        self.g = cavity.g
        self.n_levels = cavity.n_levels
        self.states = self.get_states()
        self.get_states_bin()

        self.size = len(self.states)

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

        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]

                if i_state == j_state:
                    self.matrix.data[i, j] = self.wc * i_ph

                    for n_ in range(len(i_at)):
                        if i_at[n_] != 0:
                            # print(i, j, i_at[n_], self.wa * i_at[n_])
                            self.matrix.data[i, j] += self.wa * i_at[n_]
                            # self.matrix.data[i, j] += self.wa[n_] * 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 * k
                            else:
                                k = a_cross(j_ph) * j_at[diff_at_num]

                                self.matrix.data[i,
                                                 # j] = self.g[diff_at_num] * k
                                                 j] = self.g * k

        # self.matrix.check_hermiticity()

        return
示例#19
0
from PyQuantum.Tools.CSV import *
# ---------------------------------------------------------------------------------------------------------------------
# PyQuantum.Common
from PyQuantum.Common.Quantum.Operators import operator_a
# ---------------------------------------------------------------------------------------------------------------------
# mpi4py
from mpi4py import MPI

comm = MPI.COMM_WORLD

mpirank = comm.Get_rank()
mpisize = comm.Get_size()
# ---------------------------------------------------------------------------------------------------------------------

# BEGIN--------------------------------------------------- CONFIG_IMPORT ----------------------------------------------
Assert(len(sys.argv) > 1, 'len(sys.argv) == 1', FILE(), LINE())
config_path = sys.argv[1]
config = load_pkg(config_path, config_path)

g_list = config.g_list
g_list = np.round(g_list, 4)

l_list = config.l_list
l_list = np.round(l_list, 2)

sink_threshold = config.sink_threshold
# END----------------------------------------------------- CONFIG_IMPORT ----------------------------------------------

g_count = len(g_list)
g_per_node = ceil(g_count / mpisize)
示例#20
0
path = 'T_click/l1g/' + str(dt) + 'ns/'

for w_0 in ['t0', 's2']:
    # for w_0 in ['s2', 't0']:
    # ---------------------------------------------------------------------------------------------
    T_list = []

    for i in range(NP):
        T_ = pickle_load(path + '/' + w_0 + '/' + str(i) + '.pkl')
        # T_ = pickle_load(path+'/'+w_0 + '_' + str(i) + '.pkl')
        T_list += T_

    print(len(T_list))
    # exit(0)
    Assert(len(T_list) == NP * nt_batch, 'len(T_list) != np * 10')

    # T = T_list[-1]

    # T_str = None

    # T_str = time_unit(T)

    # if T >= 1e-3:
    #     T_list = [i * 1e3 for i in T_list]
    # elif T >= 1e-6:
    #     T_list = [i * 1e6 for i in T_list]
    # elif T >= 1e-9:
    #     T_list = [i * 1e9 for i in T_list]
    T_list = [i * 1e9 for i in T_list]
# config.n_atoms = 2

# cavity = Cavity(config.wc, config.wa, config.g, config.n_atoms)

# -----------------------------------------------
l = config.g * cfg.lg

# T = 1 * config.ms

# dt = 0.01 / l
# dt = 10 * config.ns
# dt = 1 * config.ns / 10
nt = int(T / dt)
# dt = (0.001/l)

Assert(dt <= 0.01 / l, 'dt > 0.01/l')

# nt = int(T/dt)

if mpirank == 0:
    # ----------------------------------
    # cavity.info()

    cprint('T:', 'green', end='')
    print(time_unit_full(T))

    cprint('dt:', 'green', end='')
    print(time_unit_full(dt))

    cprint('nt:', 'green', end='')
    print(nt)
示例#22
0
    def normalize(self):
        norm = np.linalg.norm(self.data)

        Assert(norm > 0, "norm <= 0", cf())

        self.data /= norm
示例#23
0
    def __init__(self, capacity, cavity):
        Assert(isinstance(cavity, Cavity), "cavity is not Cavity", FILE(),
               LINE())
        Assert(isinstance(capacity, int), "capacity is not int", FILE(),
               LINE())
        Assert(capacity > 0, "capacity <=0", FILE(), LINE())

        self.cavity = cavity

        self.D = {}

        # ------------
        n = cavity.n_atoms

        wc = cavity.wc
        wa = cavity.wa
        g = cavity.g
        # ------------

        _min = min(capacity, n)

        self.states = {}

        # ---------------------------------------
        self.init_states(capacity, n)
        # ---------------------------------------

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

        i = 1

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

                for j1 in range(0, _min + 1):
                    for j2 in range(0, min(n, capacity - 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(capacity - i1 - i2, capacity - j1 - j2)
                            self.matrix.data[i - 1, j - 1] = g * \
                                sqrt(max(capacity - i1 - i2,
                                         capacity - j1 - j2)) * kappa
                        elif abs(i1 - j1) + abs(i2 - j2) == 0:
                            self.matrix.data[
                                i - 1,
                                j - 1] = (capacity -
                                          (i1 + i2)) * wc + (i1 + i2) * wa
                        else:
                            self.matrix.data[i - 1, j - 1] = 0

                        j += 1

                i += 1