예제 #1
0
    print('Train the generative TN')
    a, para_gtn = gtn_one_class(para)
    if var_name is 'which_class':
        b.load_data(data_path='..\\..\\..\\MNIST\\' + para['dataset'] + '\\',
                    file_sample='t10k-images.idx3-ubyte',
                    file_label='t10k-labels.idx1-ubyte',
                    is_normalize=True)
        b.select_samples([para['class']])

    if select_way is 'SequencedMeasure':
        print('Calculate the sequence of the measurements')
        order_file = os.path.join(para['data_path'],
                                  'Order_' + para['save_exp'])
        if (not is_order_calculated) and os.path.isfile(order_file):
            order = load_pr(order_file, 'order')
        else:
            order = a.mps.markov_measurement(if_restore=True)[0]
            save_pr(para['data_path'], 'Order_' + para['save_exp'], [order],
                    ['order'])
        order_now = copy.copy(order.reshape(-1, )[:num_features])
        is_order_calculated = True
    elif select_way is 'MaxSEE':
        if not is_order_calculated:
            ent = a.mps.calculate_onsite_reduced_density_matrix()[0]
            order = np.argsort(ent)[::-1]
            is_order_calculated = True
        order_now = copy.copy(order.reshape(-1, )[:num_features])
    elif select_way is 'Variance':
        if not is_order_calculated:
            variance = b.variance_pixels()
예제 #2
0
    for n in range(0, para['positions_h2'].shape[0]):
        para['coeff2'][n * 3, 0] = para['jxy']
        para['coeff2'][n * 3 + 1, 0] = para['jxy']
        para['coeff2'][n * 3 + 2, 0] = para['jz']
else:
    from library.Parameters import generate_parameters_dmrg
    para = generate_parameters_dmrg()

data_full_name = para['data_path'] + para['data_exp'] + '.pr'
save_pr('.\\para_dmrg\\', '_para.pr', (para,), ('para',))
print('The parameter have been saved as ' + colored('.\\para_dmrg\_para.pr', 'green'))

print_sep('Start DMRG simulation')
if is_load_data and o_path.isfile(data_full_name) and (para['lattice'] in ('chain', 'square')):
    print('The data exists in ' + para['data_path'].rstrip("\\") + '. Load directly...')
    ob, A = load_pr(data_full_name, ('ob', 'A'))
else:
    ob, A, info, para = dmrg_finite_size(para)
    save_pr(para['data_path'], para['data_exp'] + '.pr', (ob, A, info, para), ('ob', 'A', 'info', 'para'))
    print('The data have been saved in ' + colored(para['data_path'].rstrip("\\"), 'green'))

print_sep('DMRG simulation finished')
if is_from_input:
    end_plot = False
    while not end_plot:
        print('Which property are you interested in:')
        options = ('bond energies', 'magnetization', 'entanglement entropy', 'exit')
        print_options(options, list(range(1, options.__len__())) + [0])
        x = input_and_check_value(list(range(1, options.__len__())) + [0], options)
        if x == 0:
            end_plot = True
예제 #3
0
para_dmrg['jz'] = 1
para_dmrg['hx'] = 0.5
para_dmrg['hz'] = 0
para_dmrg = Pm.make_consistent_parameter_dmrg(para_dmrg)

para_dmps = parameters_dmps()
para_dmps['num_layers'] = 5
para_dmps['chi_overlap'] = 64
para_dmps['theta'] = None
para_dmps['num_theta'] = 100

if path.isfile(path.join(para_dmrg['data_path'],
                         para_dmrg['data_exp'] + '.pr')):
    print('Load existing data ...')
    a, ob = load_pr(
        path.join(para_dmrg['data_path'], para_dmrg['data_exp'] + '.pr'),
        ['a', 'ob'])
else:
    ob, a, info, para = dmrg_finite_size(para_dmrg)
    save_pr(para['data_path'], para['data_exp'] + '.pr', (ob, a, info, para),
            ('ob', 'a', 'info', 'para'))
print('Energy per site = ' + str(ob['e_per_site']))
a.calculate_entanglement_spectrum()
a.calculate_entanglement_entropy()

fid, ent, lm_mid, mpo, mps = deep_mps_qubit(a, para_dmps)

lm = [a.lm[round(a.length / 2)].reshape(-1, 1)]
lm_mat = np.ones((lm_mid[-1].size, lm_mid.__len__() + 1))
lm_mat[:a.lm[round(a.length / 2)].size, 0] = a.lm[round(a.length / 2)]
for n in range(lm_mid.__len__()):
예제 #4
0
para_dmps = parameters_dmps()
para_dmps['num_layers'] = 9
para_dmps['chi_overlap'] = 256
para_dmps['theta'] = 0
para_dmps['num_theta'] = 1

for n in range(num_len):
    para_dmrg['chi'] = int(chi[n])
    para_dmrg = Pm.make_consistent_parameter_dmrg(para_dmrg)

    if path.isfile(
            path.join(para_dmrg['data_path'], para_dmrg['data_exp'] + '.pr')):
        print('Load existing MPS data ...')
        a, ob = load_pr(
            path.join(para_dmrg['data_path'], para_dmrg['data_exp'] + '.pr'),
            ['a', 'ob'])
    else:
        ob, a, info, para_dmrg = dmrg_finite_size(para_dmrg)
        save_pr(para_dmrg['data_path'], para_dmrg['data_exp'] + '.pr',
                (ob, a, info, para_dmrg), ('ob', 'a', 'info', 'para'))
    print('Energy per site = ' + str(ob['e_per_site']))

    a.calculate_entanglement_spectrum()
    a.calculate_entanglement_entropy()
    ent0_mid[n] = a.ent[round(a.length / 2)]
    fid_ini[n] = a.fidelity_log_to_product_state()
    # print('Mid entanglement entropy and fid0 = %.12g, %.12g' % (ent0_mid, fid_ini))

    save_path = path.join(para_dmrg['project_path'], 'data_dMPS/')
    save_exp = 'UMPO_layer' + str(