def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule( atom='Li 0 0 0; H 0 0 3.14', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterCombinedJastrow(mol, kinetic='auto', include_all_mo=False, configs='single_double(2,2)', jastrow_kernel={ 'ee': PadeJastrowKernelElecElec, 'en': PadeJastrowKernelElecNuc, 'een': BoysHandyJastrowKernel}, jastrow_kernel_kwargs={ 'ee': {'w': 1.}, 'en': {'w': 1.}, 'een': {}}) self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.nbatch = 11 self.pos = torch.Tensor(np.random.rand( self.nbatch, self.wf.nelec*3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterJastrowBackFlow(mol, kinetic='jacobi', jastrow_kernel=PadeJastrowKernel, include_all_mo=True, configs='single_double(2,2)', backflow_kernel=BackFlowKernelInverse, orbital_dependent_backflow=False) self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.nbatch = 5 self.pos = torch.Tensor(np.random.rand(self.nbatch, self.wf.nelec * 3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = CorrelatedOrbital(mol, kinetic='auto', jastrow_type='pade_jastrow', configs='single_double(2,4)', include_all_mo=True) self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.wf.jastrow.weight.data = torch.rand(self.wf.jastrow.weight.shape) self.nbatch = 3 self.pos = torch.tensor(np.random.rand(self.nbatch, self.wf.nelec * 3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule( atom='Li 0 0 0; H 0 0 1.', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterJastrow(mol, kinetic='auto', configs='ground_state', jastrow_kernel=FullyConnectedJastrowKernel) self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.nbatch = 10 self.pos = 1E-2 * torch.as_tensor(np.random.rand( self.nbatch, self.wf.nelec*3)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='Li 0 0 0; H 0 0 3.015', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterOrbitalDependentJastrow( mol, kinetic='auto', jastrow_kernel=FullyConnectedJastrowKernel, configs='single_double(2,4)', include_all_mo=True) self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.nbatch = 3 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(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule( atom='Li 0 0 0; H 0 0 1.', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterJastrow(mol, kinetic='auto', include_all_mo=True, configs='cas(2,2)') self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.nbatch = 10 self.pos = torch.Tensor( np.random.rand(self.nbatch, mol.nelec*3)) self.pos.requires_grad = True
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): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g') self.orb_conf = OrbitalConfigurations(mol)
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(101) np.random.seed(101) set_torch_double_precision() # molecule self.mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69', unit='bohr', calculator='pyscf', basis='sto-3g') # orbital self.wf = SlaterJastrow(self.mol)
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(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='C 0 0 0', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = Orbital(mol, kinetic='auto', configs='ground_state').gto2sto() self.pos = -0.25 + 0.5 * torch.tensor(np.random.rand(10, 18)) self.pos.requires_grad = True
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='He 0.5 0 0; He -0.5 0 0', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = SlaterJastrow(mol, jastrow_kernel=FullyConnectedJastrowKernel, kinetic='jacobi', include_all_mo=True, configs='ground_state') self.nbatch = 100
def setUp(self): torch.manual_seed(101) np.random.seed(101) set_torch_double_precision() # molecule mol = Molecule(atom='H 0 0 0; H 0 0 1.', unit='bohr', calculator='pyscf', basis='sto-3g', redo_scf=True) self.wf = Orbital(mol, kinetic='auto', include_all_mo=False, configs='single_double(2,2)') self.random_fc_weight = torch.rand(self.wf.fc.weight.shape) self.wf.fc.weight.data = self.random_fc_weight self.pos = torch.tensor(np.random.rand(10, self.wf.nelec * 3)) self.pos.requires_grad = True
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
from qmctorch.wavefunction import SlaterJastrow from qmctorch.solver import SolverSlaterJastrowHorovod from qmctorch.sampler import Metropolis from qmctorch.utils import set_torch_double_precision from qmctorch.utils import (plot_energy, plot_data) # bond distance : 0.74 A -> 1.38 a # optimal H positions +0.69 and -0.69 # ground state energy : -31.688 eV -> -1.16 hartree # bond dissociation energy 4.478 eV -> 0.16 hartree hvd.init() if torch.cuda.is_available(): torch.cuda.set_device(hvd.rank()) set_torch_double_precision() # define the molecule 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,