Esempio n. 1
0
def run():
	"""Main FCIQMC function."""
	
	# Initialization.
	
	bit_num = integrals.para_list[0]
	chunk_num = integrals.para_list[1]
	
	change_shift_crit_num = ctrl_panel.change_shift_crit_num
	init_walker_num = ctrl_panel.init_walker_num
	max_iter_num = ctrl_panel.max_iter_num
	
	damping = ctrl_panel.damping
	ref_key = ctrl_panel.ref_key
	shift = ctrl_panel.init_shift
	tau = ctrl_panel.tau
	
	change_shift_step = ctrl_panel.change_shift_step
	update_plots_step = ctrl_panel.update_plots_step
	
	exact_corr = ctrl_panel.exact_corr
	
	aver_flag = False
	change_shift_flag = False
	
	aver_numer = 0
	aver_denom = 1
	aver_shift = 0
	aver_times = 0
	
	old_w_num = change_shift_crit_num
	old_shift = shift
	w_num = init_walker_num
	
	dets_p = dict({ref_key : det.Det(w_num, True)})
	dets_p[ref_key].diag_entry = 0
	dets_p_old = {}
	for key in dets_p:
		dets_p_old[key] = det.Det(dets_p[key].value, True)
	key_list = test.gen_key_list()
	
	aver_iter_num_list = []
	aver_proj_list = []
	aver_shift_list = []
	shift_list = []
	init_w_num_list = []
	iter_num_list = []
	log_init_w_num_list = []
	log_w_num_list = []
	proj_list = []
	w_num_list = []
	
	# Figure 0: walker number in log.
	init_figure(0, [0, 20] + ctrl_panel.y_axis_log_w_num_plot, 'Iteration', 'Log of walker number')
	
	# Figure 1: walker number.
	init_figure(1, [0, 20, 0, w_num*1.2], 'Iteration', 'Walker number')
	
	# Figure 2: energy.
	init_figure(2, [0, 20] + ctrl_panel.y_axis_energy_plot, 'Iteration', 'Energy')
	
	# Figure 3: |Psi(t)>.
	init_figure(3, [0, len(key_list)] + ctrl_panel.y_axis_eig_vec_plot, 'Dimension', 'Value')
	
	for iter_num in range(1, max_iter_num+1):
		det_ops.single_step(dets_p, tau, shift)
		w_num = det_ops.count_u_num(dets_p)
		init_w_num = abs(dets_p[ref_key].value)
		
		if iter_num % update_plots_step == 0:
			
			iter_num_list.append(iter_num)
			
			log_w_num_list.append(math.log(w_num))
			log_init_w_num_list.append(math.log(init_w_num))
			# Figure 0: walker number.
			plt.figure(0)
			plt.clf()
			plt.axis([0, iter_num] + ctrl_panel.y_axis_log_w_num_plot)
			# Draws log of walker number.
			draw_curve(iter_num_list, log_w_num_list, 'b')
			draw_curve(iter_num_list, log_init_w_num_list, 'r')
			plt.xlabel('Iteration')
			plt.ylabel('Log of walker number')
			plt.pause(0.01)
			
			w_num_list.append(w_num)
			init_w_num_list.append(init_w_num)
			# Figure 1: walker number.
			plt.figure(1)
			plt.clf()
			plt.axis([0, iter_num, 0, w_num*1.2])
			# Draws walker number.
			draw_curve(iter_num_list, w_num_list, 'b')
			draw_curve(iter_num_list, init_w_num_list, 'r')
			plt.xlabel('Iteration')
			plt.ylabel('Walker number')
			plt.pause(0.01)
			
			shift_list.append(shift)
			numer, denom = det_ops.corr_by_proj(dets_p, ref_key)
			proj_energy = numer / denom
			proj_list.append(proj_energy)
			if aver_flag:
				aver_iter_num_list.append(iter_num)
				aver_shift_list.append(aver_shift)
				aver_proj_list.append(aver_proj)
			# Figure 2: correlation energy.
			plt.figure(2)
			plt.clf()
			plt.axis([0, iter_num] + ctrl_panel.y_axis_energy_plot)
			# Draws shift.
			draw_curve([0, max_iter_num], [exact_corr, exact_corr], 'k')
			draw_curve(iter_num_list, shift_list, 'b')
			draw_curve(iter_num_list, proj_list, 'r')
			draw_curve(aver_iter_num_list, aver_shift_list, 'c')
			draw_curve(aver_iter_num_list, aver_proj_list, 'm')
			plt.xlabel('Iteration')
			plt.ylabel('Energy')
			plt.pause(0.01)
			
			vec = det_ops.dets_2_vec(key_list, dets_p)
			# Figure 3: |Psi(t)>.
			plt.figure(3)
			plt.clf()
			plt.axis([0, len(key_list)] + ctrl_panel.y_axis_eig_vec_plot)
			# Draws eigenvector.
			draw_curve(range(1, len(vec)+1), vec, 'b')
			plt.xlabel('Dimension')
			plt.ylabel('Value')
			plt.pause(0.01)
			
			# ref_key_cand = det_ops.find_ref(dets_p);
			
			print iter_num, w_num, dets_p[ref_key].value, shift, proj_energy
			
		if (not change_shift_flag) and w_num > change_shift_crit_num:
			change_shift_flag = True
			shift = proj_energy
			crit_iter_num = iter_num
		if change_shift_flag:
			if iter_num % change_shift_step == 0:
				correction = -damping / change_shift_step / tau \
					* math.log(w_num / float(old_w_num))
				shift += correction
				old_w_num = w_num
				if (not aver_flag) and (iter_num - crit_iter_num) > ctrl_panel.wait_for_aver_num:
					if abs(shift - old_shift) < 0.02:
						aver_flag = True
				if aver_flag:
					aver_shift = (aver_shift*aver_times+shift) / (aver_times+1)
					aver_numer = (aver_numer*aver_times+numer) / (aver_times+1)
					aver_denom = (aver_denom*aver_times+denom) / (aver_times+1)
					aver_proj = aver_numer / aver_denom
					aver_times += 1
				old_shift = shift
	
	"""
	# Figure 3: Derivative of log(w_num).
	s_log_w_num_list = smooth(log_w_num_list, 2)
	d_log_w_num_list = derivative(s_log_w_num_list, 2)
	f3 = plt.figure(3)
	plt.axis([0, max_iter_num, -0.1, 0.2])
	plt.ion()
	plt.clf()
	draw_curve(iter_num_list[:len(s_log_w_num_list)], s_log_w_num_list, 'b')
	draw_curve(iter_num_list[:len(d_log_w_num_list)], d_log_w_num_list, 'r')
	plt.xlabel('Iteration')
	plt.ylabel('Derivative of log(w_num)')
	plt.show()
	"""
	
	return aver_shift, aver_proj, dets_p, vec
Esempio n. 2
0
def run():
    """Main FCIQMC function."""

    # Initialization.

    bit_num = integrals.para_list[0]
    chunk_num = integrals.para_list[1]
    dim = len(ctrl_panel.key_list)

    change_shift_crit_num = ctrl_panel.change_shift_crit_num
    w_num = ctrl_panel.init_walker_num
    init_w_num = w_num
    max_iter_num = ctrl_panel.max_iter_num

    damping = ctrl_panel.damping
    ref_key = ctrl_panel.ref_key
    shift = ctrl_panel.init_shift
    tau = ctrl_panel.tau

    change_shift_step = ctrl_panel.change_shift_step
    update_plots_step = ctrl_panel.update_plots_step

    exact_corr = ctrl_panel.exact_corr

    aver_flag = False
    change_shift_flag = False

    aver_numer = 0
    aver_denom = 1
    aver_shift = 0
    aver_times = 0

    old_w_num = change_shift_crit_num
    old_shift = shift

    dets_p = dict({ref_key: det.Det(w_num, True)})
    dets_p[ref_key].diag_entry = 0
    dets_p_old = {}
    for key in dets_p:
        dets_p_old[key] = det.Det(dets_p[key].value, True)

    aver_iter_num_list = []
    aver_proj_list = []
    aver_shift_list = []
    shift_list = []
    init_w_num_list = []
    iter_num_list = []
    log_init_w_num_list = []
    log_w_num_list = []
    proj_list = []
    w_num_list = []

    spawn_map = visual.new_spawn_map(dim)

    for iter_num in range(0, max_iter_num + 1):

        if iter_num % update_plots_step == 0:

            iter_num_list.append(iter_num)

            # Figure 4: 2D spawning map.
            visual.plot_update_2D(dim, spawn_map)

            # Figure 0: log of walker number.
            log_w_num_list.append(math.log(w_num))
            log_init_w_num_list.append(math.log(init_w_num))
            data = (iter_num_list, log_w_num_list, log_init_w_num_list)
            color = ("b", "r")
            ax_range = [0, iter_num] + ctrl_panel.y_axis_log_w_num_plot
            label = ("Iteration", "Log of walker number")
            visual.plot_update_1D(0, data, color, ax_range, label)

            # Figure 1: walker number.
            w_num_list.append(w_num)
            init_w_num_list.append(init_w_num)
            data = (iter_num_list, w_num_list, init_w_num_list)
            color = ("b", "r")
            ax_range = [0, iter_num, 0, w_num * 1.2]
            label = ("Iteration", "Walker number")
            visual.plot_update_1D(1, data, color, ax_range, label)

            # Figure 2: correlation energy.
            shift_list.append(shift)
            numer, denom = det_ops.corr_by_proj(dets_p, ref_key)
            proj_energy = numer / denom
            proj_list.append(proj_energy)
            if aver_flag:
                aver_iter_num_list.append(iter_num)
                aver_shift_list.append(aver_shift)
                aver_proj_list.append(aver_proj)
            data = (iter_num_list, shift_list, proj_list, [exact_corr] * len(iter_num_list))
            color = ("b", "g", "r")
            label = ("Iteration", "Energy")
            ax_range = [0, iter_num] + ctrl_panel.y_axis_energy_plot
            visual.plot_update_1D(2, data, color, ax_range, label)

            # Figure 3: |Psi(t)>.
            vec = det_ops.dets_2_vec(dets_p)
            data = (range(len(vec)), vec)
            color = ("b",)
            label = ("Dimension", "Value")
            ax_range = [0, dim] + ctrl_panel.y_axis_eig_vec_plot
            visual.plot_update_1D(3, data, color, ax_range, label)

            # ref_key_cand = det_ops.find_ref(dets_p);

            print iter_num, w_num, dets_p[ref_key].value, shift, proj_energy

        if (not change_shift_flag) and w_num > change_shift_crit_num:
            change_shift_flag = True
            shift = proj_energy
            crit_iter_num = iter_num
        if change_shift_flag:
            if iter_num % change_shift_step == 0:
                correction = -damping / change_shift_step / tau * math.log(w_num / float(old_w_num))
                shift += correction
                old_w_num = w_num
                if (not aver_flag) and (iter_num - crit_iter_num) > ctrl_panel.wait_for_aver_num:
                    if abs(shift - old_shift) < 0.02:
                        aver_flag = True
                if aver_flag:
                    aver_shift = (aver_shift * aver_times + shift) / (aver_times + 1)
                    aver_numer = (aver_numer * aver_times + numer) / (aver_times + 1)
                    aver_denom = (aver_denom * aver_times + denom) / (aver_times + 1)
                    aver_proj = aver_numer / aver_denom
                    aver_times += 1
                old_shift = shift

        det_ops.single_step(dets_p, spawn_map, tau, shift, True)
        w_num = det_ops.count_u_num(dets_p)
        init_w_num = abs(dets_p[ref_key].value)
Esempio n. 3
0
def run(old_vec = []):
	"""Main FCIQMC function."""
	
	### Initialization.
	
	# Intializes walker distribution as D0 and puts 10 walkers on it.
	ref_key = (8, 10, 6, 4)
	
	tau = gl_consts.tau
	shift = gl_consts.shift
	max_iter_num = gl_consts.max_iter_num
	bit_num = gl_consts.para_list[0]
	chunk_num = gl_consts.para_list[1]
	
	shift = -6
	old_shift = shift
	gl_consts.init_crit_w_num = 0
	change_shift_step = 5
	update_plots_step = 20
	damping = 0.05
	change_shift_flag = False
	aver_flag = False
	change_shift_crit_num = 50000
	old_w_num = change_shift_crit_num
	tau = 0.002
	exact_gnd = -8.892162249
	
	aver_times = 0
	aver_shift = 0
	aver_numer = 0
	aver_denom = 1
	
	max_iter_num = 100000
	
	init_walker_num = 50
	init_walker = det.Det(init_walker_num, True)
	w_num = init_walker_num
	dets_p = {}
	det_ops.merge(dets_p, dict({ref_key : init_walker}))
	ref_energy = dets_p[ref_key].diag_entry
	
	w_num_list = []
	log_w_num_list = []
	
	iter_num_list = []
	aver_iter_num_list = []
	shift_list = []
	aver_shift_list = []
	proj_list = []
	aver_proj_list = []
	
	dets_p_old = {}
	for key in dets_p:
		dets_p_old[key] = det.Det(dets_p[key].value, True)
	
	# Figure 0: walker number.
	f0 = plt.figure(0)
	# plt.axis([0, max_iter_num, 0, 20000])
	plt.axis([0, max_iter_num, 3, 11])
	plt.ion()
	plt.xlabel('Iteration')
	# plt.ylabel('Walker number')
	plt.ylabel('Log of walker number')
	plt.show()
	
	# Figure 1: shift.
	f2 = plt.figure(1)
	plt.axis([0, max_iter_num, -12, 0])
	plt.ion()
	plt.xlabel('Iteration')
	plt.ylabel('Energy')
	plt.show()
	
	""""""
	# Figure 2: |Psi(t)>.
	f2 = plt.figure(2)
	plt.axis([0, (2**bit_num)**chunk_num - 1, -1, 1])
	plt.ion()
	plt.xlabel('Dimension')
	plt.ylabel('Value')
	plt.show()
	""""""
	
	for iter_num in range(1, max_iter_num+1):
		det_ops.single_step(dets_p, tau, shift)
		w_num = det_ops.count_u_num(dets_p)
		
		if iter_num % update_plots_step == 0:
			
			iter_num_list.append(iter_num)
			
			log_w_num_list.append(math.log(w_num))
			# Figure 0: walker number.
			plt.figure(0)
			plt.clf()
			plt.axis([0, max_iter_num, 3, 11])
			# Draws walker number.
			draw_curve(iter_num_list, log_w_num_list, 'b')
			plt.xlabel('Iteration')
			plt.ylabel('Log of walker number')
			plt.pause(0.01)
			
			shift_list.append(shift)
			numer, denom = det_ops.corr_by_proj(dets_p, ref_key)
			proj_energy = numer / denom + ref_energy
			proj_list.append(proj_energy)
			if aver_flag:
				aver_iter_num_list.append(iter_num)
				aver_shift_list.append(aver_shift)
				aver_proj_list.append(aver_proj)
			# Figure 1: shift.
			plt.figure(1)
			plt.clf()
			plt.axis([0, max_iter_num, -12, 0])
			# Draws shift.
			draw_curve([0, max_iter_num], [exact_gnd, exact_gnd], 'k')
			draw_curve(iter_num_list, shift_list, 'b')
			draw_curve(iter_num_list, proj_list, 'r')
			draw_curve(aver_iter_num_list, aver_shift_list, 'c')
			draw_curve(aver_iter_num_list, aver_proj_list, 'm')
			plt.xlabel('Iteration')
			plt.ylabel('Energy')
			plt.pause(0.01)
			
			""""""
			vec = det_ops.dets_2_vec(dets_p)
			# Figure 2: |Psi(t)>.
			plt.figure(2)
			plt.clf()
			plt.axis([0, len(vec)-1, -1, 1])
			# Draws eigenvector.
			if len(old_vec) == len(vec):
				draw_curve(range(len(old_vec)), old_vec, 'r')
			draw_curve(range(len(vec)), vec, 'b')
			plt.xlabel('Dimension')
			plt.ylabel('Value')
			plt.pause(0.01)
			""""""
			
			ref_key_cand = det_ops.find_ref(dets_p);
			
			print iter_num, w_num, dets_p[ref_key].value, shift, proj_energy, ref_key_cand
			
		if (not change_shift_flag) and w_num > change_shift_crit_num:
			change_shift_flag = True
			shift = proj_energy
			crit_iter_num = iter_num
		if change_shift_flag:
			if iter_num % change_shift_step == 0:
				correction = -damping / change_shift_step / tau \
					* math.log(w_num / float(old_w_num))
				shift += correction
				old_w_num = w_num
				if (not aver_flag) and (iter_num - crit_iter_num) > 500:
					if abs(shift - old_shift) < 0.02:
						aver_flag = True
				if aver_flag:
					aver_shift = (aver_shift*aver_times+shift) / (aver_times+1)
					aver_numer = (aver_numer*aver_times+numer) / (aver_times+1)
					aver_denom = (aver_denom*aver_times+denom) / (aver_times+1)
					aver_proj = aver_numer / aver_denom + ref_energy
					aver_times += 1
				old_shift = shift
	
	"""
	# Figure 3: Derivative of log(w_num).
	s_log_w_num_list = smooth(log_w_num_list, 2)
	d_log_w_num_list = derivative(s_log_w_num_list, 2)
	f3 = plt.figure(3)
	plt.axis([0, max_iter_num, -0.1, 0.2])
	plt.ion()
	plt.clf()
	draw_curve(iter_num_list[:len(s_log_w_num_list)], s_log_w_num_list, 'b')
	draw_curve(iter_num_list[:len(d_log_w_num_list)], d_log_w_num_list, 'r')
	plt.xlabel('Iteration')
	plt.ylabel('Derivative of log(w_num)')
	plt.show()
	"""
	
	return aver_shift, dets_p, vec