def test_metropolis(self): """Test Metropolis sampling.""" sampler = Metropolis(nwalkers=10, nstep=20, step_size=0.5, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal')) for m in ['one-elec', 'all-elec', 'all-elec-iter']: for p in ['normal', 'uniform']: sampler.configure_move({'type': m, 'proba': p}) pos = sampler(self.wf.pdf)
def setUp(self): torch.manual_seed(0) np.random.seed(0) # optimal parameters self.opt_r = 0.69 # the two h are at +0.69 and -0.69 self.opt_sigma = 1.24 # molecule self.mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g') # wave function self.wf = Orbital(self.mol, kinetic='auto', configs='single(2,2)', use_jastrow=True) # sampler self.sampler = Metropolis(nwalkers=1000, nstep=2000, step_size=0.5, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) self.hmc_sampler = Hamiltonian(nwalkers=100, nstep=200, step_size=0.1, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal')) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # ground state energy self.ground_state_energy = -1.16 # ground state pos self.ground_state_pos = 0.69
def setUp(self): torch.manual_seed(0) np.random.seed(0) set_torch_double_precision() # molecule self.mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g') # wave function self.wf = SlaterJastrowBackFlow(self.mol, kinetic='jacobi', configs='single_double(2,2)', backflow_kernel=BackFlowKernelPowerSum, orbital_dependent_backflow=False, include_all_mo=True) # fc weights self.wf.fc.weight.data = torch.rand(self.wf.fc.weight.shape) # jastrow weights self.wf.jastrow.jastrow_kernel.weight.data = torch.rand( self.wf.jastrow.jastrow_kernel.weight.shape) # sampler self.sampler = Metropolis(nwalkers=500, nstep=200, step_size=0.05, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # artificial pos self.nbatch = 10 self.pos = torch.as_tensor( np.random.rand(self.nbatch, self.wf.nelec * 3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(0) np.random.seed(0) set_torch_double_precision() # optimal parameters self.opt_r = 0.69 # the two h are at +0.69 and -0.69 self.opt_sigma = 1.24 # molecule self.mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g') # wave function self.wf = CorrelatedOrbital( self.mol, kinetic='auto', configs='cas(2,2)', jastrow_type=FullyConnectedJastrow, # jastrow_type='pade_jastrow', include_all_mo=True) # sampler self.sampler = Metropolis(nwalkers=1000, nstep=2000, step_size=0.5, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # ground state energy self.ground_state_energy = -1.16 # ground state pos self.ground_state_pos = 0.69
def setUp(self): hvd.init() torch.manual_seed(0) np.random.seed(0) set_torch_double_precision() # optimal parameters self.opt_r = 0.69 # the two h are at +0.69 and -0.69 self.opt_sigma = 1.24 # molecule self.mol = Molecule( atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g', rank=hvd.local_rank()) # wave function self.wf = SlaterJastrow(self.mol, kinetic='jacobi', configs='cas(2,2)', cuda=False) # sampler self.sampler = Metropolis( nwalkers=200, nstep=200, step_size=0.2, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('atomic'), move={ 'type': 'all-elec', 'proba': 'normal'}) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverSlaterJastrowHorovod(wf=self.wf, sampler=self.sampler, optimizer=self.opt, rank=hvd.rank()) # ground state energy self.ground_state_energy = -1.16 # ground state pos self.ground_state_pos = 0.69
def setUp(self): torch.manual_seed(0) np.random.seed(0) set_torch_double_precision() # molecule path_hdf5 = (PATH_TEST / 'hdf5/LiH_adf_dz.hdf5').absolute().as_posix() self.mol = Molecule(load=path_hdf5) # wave function self.wf = SlaterOrbitalDependentJastrow(self.mol, kinetic='jacobi', configs='cas(2,2)', include_all_mo=True) # fc weights self.wf.fc.weight.data = torch.rand(self.wf.fc.weight.shape) # jastrow weights for ker in self.wf.jastrow.jastrow_kernel.jastrow_functions: ker.weight.data = torch.rand(1) # sampler self.sampler = Metropolis(nwalkers=500, nstep=200, step_size=0.05, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # artificial pos self.nbatch = 10 self.pos = torch.as_tensor( np.random.rand(self.nbatch, self.wf.nelec * 3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(0) np.random.seed(0) # optimal parameters self.opt_r = 0.69 # the two h are at +0.69 and -0.69 self.opt_sigma = 1.24 # molecule self.mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g') # wave function self.wf = SlaterJastrow(self.mol, kinetic='jacobi', configs='single(2,2)') # sampler self.sampler = Metropolis(nwalkers=100, nstep=500, step_size=0.5, ndim=self.wf.ndim, nelec=self.wf.nelec, ntherm=0, ndecor=1, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler, optimizer=self.opt)
def setUp(self): torch.manual_seed(0) # molecule path_hdf5 = (PATH_TEST / 'hdf5/H2_adf_dzp.hdf5').absolute().as_posix() self.mol = Molecule(load=path_hdf5) # wave function self.wf = Orbital(self.mol, kinetic='auto', configs='single(2,2)', use_jastrow=True) # sampler self.sampler = Metropolis(nwalkers=1000, nstep=2000, step_size=0.5, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # ground state energy self.ground_state_energy = -1.16 # ground state pos self.ground_state_pos = 0.69
def setUp(self): torch.manual_seed(0) np.random.seed(0) # molecule self.mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g') # wave function self.wf = Orbital(self.mol, kinetic='jacobi', configs='single(2,2)', use_jastrow=True, include_all_mo=False) # sampler self.sampler = Metropolis(nwalkers=500, nstep=200, step_size=0.05, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer self.opt = optim.Adam(self.wf.parameters(), lr=0.01) # solver self.solver = SolverOrbital(wf=self.wf, sampler=self.sampler, optimizer=self.opt)
mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', calculator='pyscf', basis='sto-3g', unit='bohr', rank=hvd.local_rank()) # define the wave function wf = SlaterJastrow(mol, kinetic='jacobi', configs='cas(2,2)', cuda=False) # sampler sampler = Metropolis(nwalkers=200, nstep=200, step_size=0.2, ntherm=-1, ndecor=100, nelec=wf.nelec, init=mol.domain('atomic'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer lr_dict = [{ 'params': wf.jastrow.parameters(), 'lr': 3E-3 }, { 'params': wf.ao.parameters(), 'lr': 1E-6 }, { 'params': wf.mo.parameters(),
# define the molecule mol = Molecule(atom='water.xyz', unit='angs', calculator='pyscf', basis='sto-3g', name='water') # define the wave function wf = SlaterJastrow(mol, kinetic='jacobi', configs='ground_state') # sampler sampler = Metropolis(nwalkers=100, nstep=500, step_size=0.25, nelec=wf.nelec, ndim=wf.ndim, init=mol.domain('atomic'), move={ 'type': 'one-elec', 'proba': 'normal' }) # solver solver = SolverSlaterJastrow(wf=wf, sampler=sampler) # single point obs = solver.single_point() # reconfigure sampler solver.sampler.ntherm = 0 solver.sampler.ndecor = 5
def setUp(self): set_torch_double_precision() reset_generator() # molecule self.mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g') # molecule self.mol_ref = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g') # backflow wave function self.wf = SlaterJastrowBackFlow(self.mol, kinetic='jacobi', configs='single_double(2,2)', include_all_mo=True) self.wf.ao.backflow_trans.backflow_kernel.weight.data *= 0. self.wf.ao.backflow_trans.backflow_kernel.weight.requires_grad = False # normal wave function self.wf_ref = SlaterJastrow(self.mol_ref, kinetic='jacobi', include_all_mo=True, configs='single_double(2,2)') # fc weights self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight.clone() self.wf_ref.fc.weight.data = self.random_fc_weight.clone() # jastrow weights self.random_jastrow_weight = torch.rand( self.wf.jastrow.jastrow_kernel.weight.shape) self.wf.jastrow.jastrow_kernel.weight.data = self.random_jastrow_weight.clone( ) self.wf_ref.jastrow.jastrow_kernel.weight.data = self.random_jastrow_weight.clone( ) reset_generator() # sampler self.sampler = Metropolis(nwalkers=5, nstep=200, step_size=0.05, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) reset_generator() self.sampler_ref = Metropolis(nwalkers=5, nstep=200, step_size=0.05, ndim=self.wf.ndim, nelec=self.wf.nelec, init=self.mol.domain('normal'), move={ 'type': 'all-elec', 'proba': 'normal' }) # optimizer reset_generator() self.opt = optim.Adam(self.wf.parameters(), lr=0.01) reset_generator() self.opt_ref = optim.Adam(self.wf_ref.parameters(), lr=0.01) # solver self.solver_ref = SolverSlaterJastrow(wf=self.wf_ref, sampler=self.sampler_ref, optimizer=self.opt_ref) self.solver = SolverSlaterJastrow(wf=self.wf, sampler=self.sampler, optimizer=self.opt) # artificial pos self.nbatch = 10 self.pos = torch.as_tensor( np.random.rand(self.nbatch, self.wf.nelec * 3)) self.pos.requires_grad = True