Skip to content

Commit

Permalink
Merge pull request #141 from NLESC-JCER/paper
Browse files Browse the repository at this point in the history
Paper
  • Loading branch information
NicoRenaud authored Apr 26, 2023
2 parents 129d7d9 + b64dc6a commit c7f3ac2
Show file tree
Hide file tree
Showing 115 changed files with 3,898 additions and 1,322 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper/paper.md
- name: Upload
uses: actions/upload-artifact@v1
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper/paper.pdf
2 changes: 1 addition & 1 deletion bin/qmctorch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os
import argparse


dist_solvers = ['SolverSlaterJastrowHorovod']
dist_solvers = ['SolverMPI']


def check_file(fname):
Expand Down
8 changes: 5 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode'
'sphinx.ext.viewcode',
'nbsphinx'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -139,7 +140,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -165,7 +166,7 @@
# html_theme = 'classic'

html_theme = 'sphinx_rtd_theme'
html_logo = "qmctorch_white.png"
html_logo = "./pics/qmctorch_white.png"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -261,3 +262,4 @@

autoclass_content = 'init'
autodoc_member_order = 'bysource'
nbsphinx_allow_errors = True
File renamed without changes.
1 change: 1 addition & 0 deletions docs/example/colab/google_collab.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"attachments":{},"cell_type":"markdown","metadata":{"colab_type":"text","id":"PA9WOB4zJfCu"},"source":["# Installation on Google Collab\n","To install `QMCTorch` copy the code from one of the 3 text cells below in a code cell and run that cell. "]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"6KLOhN_dGQ11"},"source":["## Install QMCTorch from Pypi Package manager\n","\n","```\n","! pip install qmctorch\n","```\n","\n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"Eb9wI3eOGfz1"},"source":["## Install QMCTorch from GitHub\n","```\n","from google.colab import drive\n","drive.mount('/content/gdrive')\n","% cd gdrive/My Drive/\n","! git clone https://github.com/NLESC-JCER/QMCTorch\n","% cd QMCTorch\n","! pip install -e .\n","% cd ../\n","```"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"_VNw5sAeHC7M"},"source":["## Pull latest code from Github\n","```\n","from google.colab import drive\n","drive.mount('/content/gdrive')\n","% cd gdrive/My Drive/QMCTorch\n","! git pull origin master\n","! pip install -e .\n","% cd ../\n","```"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":671},"colab_type":"code","executionInfo":{"elapsed":9770,"status":"ok","timestamp":1588617088336,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"},"user_tz":-120},"id":"khGd1-ewHZWF","outputId":"674fbe9e-7817-4e11-cc91-cd508bda8107","vscode":{"languageId":"python"}},"outputs":[],"source":["# from google.colab import drive\n","# drive.mount('/content/gdrive')\n","# % cd gdrive/My Drive/QMCTorch\n","# ! git pull origin master\n","# ! pip install -e .\n","# % cd .."]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"MGNu_L-OJ-7u"},"source":["# Using QMCTorch"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":52},"colab_type":"code","executionInfo":{"elapsed":11632,"status":"ok","timestamp":1588617090211,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"},"user_tz":-120},"id":"p7qEQTV2HB4h","outputId":"52c2bbce-3775-442c-95de-d18bd432c2e3","vscode":{"languageId":"python"}},"outputs":[],"source":["import torch\n","from torch import optim\n","from qmctorch.scf import Molecule\n","from qmctorch.wavefunction import SlaterJastrow\n","from qmctorch.solver import Solver\n","from qmctorch.sampler import Metropolis\n","from qmctorch.utils import set_torch_double_precision\n","from qmctorch.utils import plot_energy, plot_data"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"x-s06JyaHUdN","vscode":{"languageId":"python"}},"outputs":[],"source":["use_gpu = torch.cuda.is_available()\n","set_torch_double_precision()"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":52},"colab_type":"code","executionInfo":{"elapsed":11608,"status":"ok","timestamp":1588617090213,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"},"user_tz":-120},"id":"7HO4cNaAID-F","outputId":"a1f652aa-9bcb-4e9b-c038-833b29da2eae","vscode":{"languageId":"python"}},"outputs":[],"source":["mol = Molecule(atom='H 0 0 0.69; H 0 0 -0.69', unit='bohr', \\\n"," calculator='pyscf', basis='sto-3g')"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"hFZg-XanIOeY","vscode":{"languageId":"python"}},"outputs":[],"source":["wf = SlaterJastrow(mol, configs='cas(2,2)', cuda=use_gpu)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"Mqlk1N3tIVXN","vscode":{"languageId":"python"}},"outputs":[],"source":["sampler = Metropolis(nwalkers=2000, nstep=2000, step_size=0.2, \\\n"," ntherm=-1, ndecor=100, nelec=wf.nelec, \\\n"," init=mol.domain('atomic'), \\\n"," move={'type':'all-elec', 'proba':'normal'},\n"," cuda=use_gpu)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"5-I7abLxI5qG","vscode":{"languageId":"python"}},"outputs":[],"source":["lr_dict = [{'params': wf.jastrow.parameters(), 'lr': 3E-3},\n"," {'params': wf.ao.parameters(), 'lr': 1E-6},\n"," {'params': wf.mo.parameters(), 'lr': 1E-3},\n"," {'params': wf.fc.parameters(), 'lr': 2E-3}]\n","opt = optim.Adam(lr_dict, lr=1E-3)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"xgXSp8JwJIr9","vscode":{"languageId":"python"}},"outputs":[],"source":["scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"g6TE--nNJL1H","vscode":{"languageId":"python"}},"outputs":[],"source":["solver = Solver(wf=wf, sampler=sampler,\n"," optimizer=opt, scheduler=scheduler)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":87},"colab_type":"code","executionInfo":{"elapsed":26805,"status":"ok","timestamp":1588617105475,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"},"user_tz":-120},"id":"Y5MPLiv2JTCy","outputId":"ef067f86-11b3-48e0-9dac-dc8ff5784905","vscode":{"languageId":"python"}},"outputs":[],"source":["# obs = solver.single_point()"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{},"colab_type":"code","id":"yfx4g1Luz9Z-","vscode":{"languageId":"python"}},"outputs":[],"source":["# solver.configure(freeze=['ao', 'mo'], loss='energy', grad='manual')\n","# solver.track_observable(['local_energy'])\n","\n","# solver.configure_resampling(mode='update',\n","# resample_every=1,\n","# nstep_update=50)\n","# solver.ortho_mo = False"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000},"colab_type":"code","executionInfo":{"elapsed":52595,"status":"ok","timestamp":1588617131289,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"},"user_tz":-120},"id":"VtrVSk620A1A","outputId":"32ad9904-40e5-4efa-bcee-27145e04cfd4","vscode":{"languageId":"python"}},"outputs":[],"source":["# obs = solver.run(50)"]}],"metadata":{"accelerator":"GPU","colab":{"authorship_tag":"ABX9TyMr6DKmNBGlyg+0pzpuupgz","name":"qmctorch.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"}},"nbformat":4,"nbformat_minor":0}
4 changes: 0 additions & 4 deletions docs/example/example_gpu.rst

This file was deleted.

4 changes: 0 additions & 4 deletions docs/example/example_horovod.rst

This file was deleted.

4 changes: 0 additions & 4 deletions docs/example/example_opt.rst

This file was deleted.

4 changes: 0 additions & 4 deletions docs/example/example_sp.rst

This file was deleted.

4 changes: 2 additions & 2 deletions example/gpu/h2.py → docs/example/gpu/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.solver import Solver
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)
Expand Down Expand Up @@ -45,7 +45,7 @@
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)

# QMC solver
solver = SolverSlaterJastrow(wf=wf, sampler=sampler,
solver = Solver(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)

# perform a single point calculation
Expand Down
12 changes: 7 additions & 5 deletions example/horovod/h2.py → docs/example/horovod/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverSlaterJastrowHorovod
from qmctorch.solver import SolverMPI
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)
Expand All @@ -15,7 +15,8 @@
# bond dissociation energy 4.478 eV -> 0.16 hartree

hvd.init()
if torch.cuda.is_available():
use_cuda = torch.cuda.is_available()
if use_cuda:
torch.cuda.set_device(hvd.rank())

set_torch_double_precision()
Expand All @@ -29,14 +30,15 @@
# define the wave function
wf = SlaterJastrow(mol, kinetic='jacobi',
configs='cas(2,2)',
cuda=False)
cuda=use_cuda)

# 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'})
move={'type': 'all-elec', 'proba': 'normal'},
cuda=use_cuda)


# optimizer
Expand All @@ -50,7 +52,7 @@
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)

# QMC solver
solver = SolverSlaterJastrowHorovod(wf=wf, sampler=sampler,
solver = SolverMPI(wf=wf, sampler=sampler,
optimizer=opt, scheduler=scheduler,
rank=hvd.rank())

Expand Down
34 changes: 17 additions & 17 deletions example/optimization/h2.py → docs/example/optimization/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.sampler import Metropolis, Hamiltonian
from qmctorch.solver import Solver
from qmctorch.sampler import Metropolis
from qmctorch.utils import set_torch_double_precision
from qmctorch.utils import (plot_energy, plot_data)

Expand All @@ -26,43 +26,43 @@
# define the wave function
wf = SlaterJastrow(mol, kinetic='jacobi',
configs='single_double(2,2)',
jastrow_kernel=PadeJastrowKernel)
jastrow_kernel=PadeJastrowKernel).gto2sto()

# sampler
sampler = Hamiltonian(nwalkers=100, nstep=100, nelec=wf.nelec,
step_size=0.1, L=30,
ntherm=-1, ndecor=10,
init=mol.domain('atomic'))

sampler = Metropolis(nwalkers=5000,
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},
lr_dict = [{'params': wf.jastrow.parameters(), 'lr': 1E-2},
{'params': wf.ao.parameters(), 'lr': 1E-6},
{'params': wf.mo.parameters(), 'lr': 1E-3},
{'params': wf.mo.parameters(), 'lr': 2E-3},
{'params': wf.fc.parameters(), 'lr': 2E-3}]
opt = optim.Adam(lr_dict, lr=1E-3)

# scheduler
scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)
scheduler = optim.lr_scheduler.StepLR(opt, step_size=10, gamma=0.90)

# QMC solver
solver = SolverSlaterJastrow(wf=wf, sampler=sampler,
solver = Solver(wf=wf, sampler=sampler,
optimizer=opt, scheduler=None)

# perform a single point calculation
obs = solver.single_point()

# configure the solver
solver.configure(track=['local_energy'], freeze=['ao', 'mo'],
loss='energy', grad='auto',
solver.configure(track=['local_energy', 'parameters'], freeze=['ao'],
loss='energy', grad='manual',
ortho_mo=False, clip_loss=False,
resampling={'mode': 'update',
'resample_every': 1,
'nstep_update': 50})
'nstep_update': 25})

# optimize the wave function
obs = solver.run(250)
obs = solver.run(50)

# plot
plot_energy(obs.local_energy, e0=-1.1645, show_variance=True)
plot_data(solver.observable, obsname='jastrow.weight')
plot_data(solver.observable, obsname='jastrow.jastrow_kernel.weight')
23 changes: 23 additions & 0 deletions docs/example/scf/scf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from qmctorch.scf import Molecule

# Select the SCF calculator
calc = ['pyscf', # pyscf
'adf', # adf 2019
'adf2019' # adf 2020+
][1]

# select an appropriate basis
basis = {
'pyscf' : 'sto-6g',
'adf' : 'VB1',
'adf2019': 'dz'
}[calc]

# do the scf calculation
mol = Molecule(atom='H 0 0 -0.69; H 0 0 0.69',
calculator=calc,
basis=basis,
unit='bohr')



Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qmctorch.scf import Molecule
from qmctorch.wavefunction import SlaterJastrow
from qmctorch.sampler import Metropolis
from qmctorch.solver import SolverSlaterJastrow
from qmctorch.solver import Solver
from qmctorch.utils import plot_walkers_traj

# define the molecule
Expand All @@ -16,10 +16,10 @@
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'})
move={'type': 'all-elec', 'proba': 'normal'})

# solver
solver = SolverSlaterJastrow(wf=wf, sampler=sampler)
solver = Solver(wf=wf, sampler=sampler)

# single point
obs = solver.single_point()
Expand Down
File renamed without changes.
35 changes: 15 additions & 20 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,30 @@ Quantum Monte Carlo with Pytorch
:maxdepth: 1
:caption: QMCTorch

intro
qmc
qmctorch/molecule
qmctorch/wavefunction
qmctorch/sampler
qmctorch/optimizer
qmctorch/solver
rst/install
rst/qmc
rst/qmctorch
rst/hdf5

.. toctree::
:maxdepth: 1
:caption: Tutorial

tutorial/tutorial_sampling_traj
tutorial/tutorial_correlation
tutorial/tutorial_wf_opt
tutorial/tutorial_jastrow
tutorial/tutorial_backflow
# tutorial/tutorial_geo_opt
tutorial/tutorial_gpus
tutorial/tutorial_hdf5
notebooks/molecule
notebooks/sampling
notebooks/wfopt
notebooks/geoopt
notebooks/gpu

.. toctree::
:maxdepth: 1
:caption: Examples
:caption: Advanced Tutorial

notebooks/correlation
notebooks/create_jastrow
notebooks/create_backflow
notebooks/horovod

example/example_sp
example/example_opt
example/example_gpu
example/example_horovod

.. toctree::
:maxdepth: 1
Expand Down
Loading

0 comments on commit c7f3ac2

Please sign in to comment.