qmctorch.sampler package
Submodules
qmctorch.sampler.generalized_metropolis module
- class qmctorch.sampler.generalized_metropolis.GeneralizedMetropolis(nwalkers: int = 100, nstep: int = 1000, step_size: float = 3, ntherm: int = -1, ndecor: int = 1, nelec: int = 1, ndim: int = 1, init: Dict[str, Any] = {'max': 5, 'min': -5, 'type': 'uniform'}, cuda: bool = False)[source]
Bases:
SamplerBaseGeneralized Metropolis Hasting sampler
- Parameters:
nwalkers (int, optional) – number of walkers. Defaults to 100.
nstep (int, optional) – number of steps. Defaults to 1000.
step_size (float, optional) – size of the steps. Defaults to 3.
ntherm (int, optional) – number of steps for thermalization. Defaults to -1.
ndecor (int, optional) – number of steps for decorelation. Defaults to 1.
nelec (int, optional) – number of electron. Defaults to 1.
ndim (int, optional) – number of dimensions. Defaults to 1.
init (dict, optional) – method to initialize the walkers. Defaults to {‘type’: ‘uniform’, ‘min’: -5, ‘max’: 5}.
cuda (bool, optional) – use cuda. Defaults to False.
- Returns:
None
- move(drift: torch.Tensor) torch.Tensor[source]
Move electron one at a time in a vectorized way.
- Parameters:
drift (torch.Tensor) – drift velocity of the walkers
- Returns:
new positions of the walkers
- Return type:
- trans(xf: torch.Tensor, xi: torch.Tensor, drifti: torch.Tensor) torch.Tensor[source]
Transform the positions
- Parameters:
xf (torch.Tensor) – Final positions
xi (torch.Tensor) – Initial positions
drifti (torch.Tensor) – Drift velocity
- Returns:
Transition probabilities
- Return type:
- get_drift(pdf: Callable[[torch.Tensor], torch.Tensor], x: torch.Tensor) torch.Tensor[source]
Compute the drift velocity
- Parameters:
pdf (callable) – function that returns the density
x (torch.tensor) – positions of the walkers
- Returns:
drift velocity
- Return type:
torch.tensor
qmctorch.sampler.hamiltonian module
- class qmctorch.sampler.hamiltonian.Hamiltonian(nwalkers: int = 100, nstep: int = 100, step_size: float = 0.2, L: int = 10, ntherm: int = -1, ndecor: int = 1, nelec: int = 1, ndim: int = 3, init: Dict = {'max': 5, 'min': -5}, cuda: bool = False)[source]
Bases:
SamplerBaseHamiltonian Monte Carlo Sampler.
- Parameters:
nwalkers (int, optional) – Number of walkers. Defaults to 100.
nstep (int, optional) – Number of steps. Defaults to 100.
step_size (int, optional) – length of the step. Defaults to 0.2.
L (int, optional) – length of the trajectory . Defaults to 10.
nelec (int, optional) – total number of electrons. Defaults to 1.
ntherm (int, optional) – number of mc step to thermalize. Defaults to -1, i.e. keep only last position
ndecor (int, optional) – number of mc step for decorrelation. Defaults to 1.
ndim (int, optional) – total number of dimension. Defaults to 3.
init (dict, optional) – method to init the positions of the walkers. See Molecule.domain()
cuda (bool, optional) – turn CUDA ON/OFF. Defaults to False.
- static get_grad(func: Callable[[torch.Tensor], torch.Tensor], inp: torch.Tensor) torch.Tensor[source]
get the gradient of the pdf using autograd
- Parameters:
func – function to compute the pdf
inp – input of the function
- Returns:
gradient of the wavefunction
- static log_func(func: Callable[[torch.Tensor], torch.Tensor])[source]
Compute the negative log of a function
- Parameters:
func (callable) – input function
- Returns:
negative log of the function
- Return type:
callable
qmctorch.sampler.metropolis module
- class qmctorch.sampler.metropolis.Metropolis(nwalkers: int = 100, nstep: int = 1000, step_size: float = 0.2, ntherm: int = -1, ndecor: int = 1, nelec: int = 1, ndim: int = 3, init: Dict = {'max': 5, 'min': -5}, move: Dict = {'proba': 'normal', 'type': 'all-elec'}, logspace: bool = False, symmetry=None, cuda: bool = False)[source]
Bases:
SamplerBaseMetropolis Hasting generator
- Parameters:
nwalkers (int, optional) – Number of walkers. Defaults to 100.
nstep (int, optional) – Number of steps. Defaults to 1000.
step_size (int, optional) – length of the step. Defaults to 0.2.
nelec (int, optional) – total number of electrons. Defaults to 1.
ntherm (int, optional) – number of mc step to thermalize. Defaults to -1, i.e. keep only the last position
ndecor (int, optional) – number of mc step for decorelation. Defauts to 1.
ndim (int, optional) – total number of dimension. Defaults to 3.
init (dict, optional) – method to init the positions of the walkers. See Molecule.domain()
move (dict, optional) –
method to move the electrons. default(‘all-elec’,’normal’)
- ’type’:
’one-elec’: move a single electron per iteration
’all-elec’: move all electrons at the same time
’all-elec-iter’: move all electrons by iterating through single elec moves
- ’proba’ :
’uniform’: uniform in a cube
’normal’: gussian in a sphere
cuda (bool, optional) – turn CUDA ON/OFF. Defaults to False.
- Examples::
>>> mol = Molecule('h2.xyz') >>> wf = SlaterJastrow(mol) >>> sampler = Metropolis(nwalkers=100, nelec=wf.nelec) >>> pos = sampler(wf.pdf)
- static log_func(func)[source]
Compute the negative log of a function
- Parameters:
func (callable) – input function
- Returns:
negative log of the function
- Return type:
callable
- configure_move(move: Dict) None[source]
Configure the electron moves
- Parameters:
move (dict, optional) –
method to move the electrons. default(‘all-elec’,’normal’)
- ’type’:
’one-elec’: move a single electron per iteration
’all-elec’: move all electrons at the same time
’all-elec-iter’: move all electrons by iterating through single elec moves
- ’proba’ :
’uniform’: uniform ina cube
’normal’: gussian in a sphere
- Raises:
ValueError – If moves are not recognized
qmctorch.sampler.metropolis_hasting module
qmctorch.sampler.pints_sampler module
qmctorch.sampler.sampler_base module
- class qmctorch.sampler.sampler_base.SamplerBase(nwalkers: int, nstep: int, step_size: float, ntherm: int, ndecor: int, nelec: int, ndim: int, init: Dict, cuda: bool)[source]
Bases:
objectBase class for the sampler
- Parameters:
nwalkers (int) – number of walkers
nstep (int) – number of MC steps
step_size (float) – size of the steps in bohr
ntherm (int) – number of MC steps to thermalize
ndecor (int) – number of MC steps to decorellate
nelec (int) – number of electrons in the system
ndim (int) – number of cartesian dimension
init (dict) – method to initialize the walkers
cuda (bool) – turn CUDA ON/OFF
qmctorch.sampler.symmetry module
qmctorch.sampler.walkers module
- class qmctorch.sampler.walkers.Walkers(nwalkers: int = 100, nelec: int = 1, ndim: int = 3, init: Dict | None = None, cuda: bool = False)[source]
Bases:
objectCreates Walkers for the sampler.
- Parameters:
nwalkers (int, optional) – Number of walkers. Defaults to 100.
nelec (int, optional) – number of electron. Defaults to 1.
ndim (int, optional) – Number of dimensions. Defaults to 3.
init (dict, optional) – method to initialize the walkers. Defaults to None. (see Molecule.domain())
cuda (bool, optional) – turn cuda ON/OFF. Defaults to False
- initialize(pos: None | torch.Tensor = None) None[source]
Initalize the position of the walkers
- Parameters:
- Raises:
ValueError – if the method is not recognized