def pconfig(config, rbm): ''' Config a problem and optimizer. ''' # hamiltonian hconfig = config['hamiltonian'] hamiltonian = load_hamiltonian(**hconfig) # cgen cgenconfig = config['cgen'] cgen=SpinConfigGenerator(initial_config=random_config(num_spin=hamiltonian.nsite, mag=cgenconfig['mag']), \ nflip=cgenconfig['num_flip'], inverse_rate=cgenconfig['inverse_rate']) # vmc vmcconfig = config['vmc'] vmc=VMC(cgen, nbath=vmcconfig['num_bath_sweep']*hamiltonian.nsite, \ measure_step=vmcconfig['num_sweep_per_sample']*hamiltonian.nsite,\ sampling_method=vmcconfig['accept_method'], iprint=vmcconfig['iprint']) # sr srconfig = config['sr'] reg_method = srconfig['reg_method'] lambda0 = srconfig['lambda'] if reg_method == 'delta': reg_params = ('delta', {'lambda0': lambda0}) elif reg_method == 'trunc': reg_params = ('trunc', { 'lambda0': lambda0, 'eps_trunc': srconfig['eps_trunc'] }) elif reg_method == 'carleo': raise NotImplementedError() reg_params = ('carleo', {'lambda0': lambda0, 'b': 0.9}) elif reg_method == 'sd': reg_params = ('sd', {}) elif reg_method == 'pinv': reg_params = ('pinv', {}) else: raise ValueError('Can not load predefined regulation method %s' % reg_method) sr=SR(hamiltonian, reg_params=reg_params, state=rbm, \ rtheta_training_ratio=srconfig['rtheta_training_ratio'],\ layer_wise=srconfig['sr_layerwise']) # optimize optimizeconfig = config['optimize'] prob = ProbDef(hamiltonian, rbm, vmc, sr, \ num_vmc_run=vmcconfig['num_vmc_run'], num_vmc_sample=vmcconfig['num_sample'], redistribute_samples=vmcconfig['redistribute_samples']) optimizer = get_optimizer(rbm.get_variables(), prob.compute_gradient, **optimizeconfig) return optimizer, prob
def __init__(self, hamiltonian, rbm, reg_method, num_vmc_run=1, num_vmc_sample=1000, sr_layerwise=True): self.reg_method = reg_method #Create a VMC sampling engine. cgen=SpinConfigGenerator(initial_config=[-1,1]*(hamiltonian.nsite//2)+\ [1]*(hamiltonian.nsite%2),nflip=2 if hamiltonian.mag is not None else 1, inverse_rate=0.05) vmc = VMC(cgen, nbath=200 * hamiltonian.nsite, measure_step=hamiltonian.nsite, sampling_method='metropolis', iprint=0) ##################### choose an regulation method ############################## if reg_method == 'delta': reg_params = ('delta', {'lambda0': 1e-4}) elif reg_method == 'trunc': reg_params = ('trunc', {'lambda0': 0.2, 'eps_trunc': 1e-3}) elif reg_method == 'carleo': reg_params = ('carleo', {'lambda0': 100, 'b': 0.9}) elif reg_method == 'sd': reg_params = ('sd', {}) elif reg_method == 'pinv': reg_params = ('pinv', {}) else: raise ValueError('Can not load predefined regulation method %s' % reg_method) sr = SR(hamiltonian, reg_params=reg_params, state=rbm, rtheta_training_ratio=[1., 30.], layer_wise=sr_layerwise) super(ModelProbDef, self).__init__(hamiltonian, rbm, vmc, sr, num_vmc_run=num_vmc_run, num_vmc_sample=num_vmc_sample)