From e65381d2a3a4a18ed55a60af26c3c0d3e4790554 Mon Sep 17 00:00:00 2001 From: Nicolas Renaud Date: Fri, 2 Apr 2021 18:25:05 +0200 Subject: [PATCH] renamed solvers --- bin/qmctorch | 2 +- docs/qmctorch.solver.rst | 2 +- docs/solver.rst | 24 +++++++++---------- docs/tutorial_geo_opt.rst | 4 ++-- docs/tutorial_gpus.rst | 4 ++-- docs/tutorial_sampling_traj.rst | 2 +- docs/tutorial_wf_opt.rst | 4 ++-- example/gpu/h2.py | 6 ++--- example/horovod/h2.py | 8 +++---- example/optimization/h2.py | 6 ++--- example/single_point/h2o_sampling.py | 4 ++-- notebooks/qmctorch.ipynb | 2 +- qmctorch/solver/__init__.py | 7 +++--- qmctorch/solver/solver_base.py | 5 ++++ ...er_orbital.py => solver_slater_jastrow.py} | 2 +- ...od.py => solver_slater_jastrow_horovod.py} | 8 +++---- tests/solver/test_h2.py | 6 ++--- tests/solver/test_h2_adf.py | 6 ++--- tests/solver/test_h2_adf_jacobi.py | 6 ++--- tests/solver/test_h2_correlated.py | 6 ++--- tests/solver/test_h2_stats.py | 6 ++--- tests/solver/test_lih.py | 6 ++--- tests/solver/test_lih_correlated.py | 6 ++--- tests/test_h2.py | 6 ++--- tests/test_h2_adf_jacobi.py | 6 ++--- tests/test_h2_correlated.py | 6 ++--- tests_hvd/test_h2_hvd.py | 6 ++--- 27 files changed, 81 insertions(+), 75 deletions(-) rename qmctorch/solver/{solver_orbital.py => solver_slater_jastrow.py} (99%) rename qmctorch/solver/{solver_orbital_horovod.py => solver_slater_jastrow_horovod.py} (97%) diff --git a/bin/qmctorch b/bin/qmctorch index 9650b4cc..843c9e9f 100755 --- a/bin/qmctorch +++ b/bin/qmctorch @@ -3,7 +3,7 @@ import os import argparse -dist_solvers = ['SolverOrbitalHorovod'] +dist_solvers = ['SolverSlaterJastrowHorovod'] def check_file(fname): diff --git a/docs/qmctorch.solver.rst b/docs/qmctorch.solver.rst index e3d008dd..2bc80f83 100644 --- a/docs/qmctorch.solver.rst +++ b/docs/qmctorch.solver.rst @@ -7,7 +7,7 @@ Solver Solver ---------------------------------------- -.. automodule:: qmctorch.solver.solver_orbital +.. automodule:: qmctorch.solver.solver_slater_jastrow :members: :undoc-members: diff --git a/docs/solver.rst b/docs/solver.rst index 8e8e40dd..a63798ac 100644 --- a/docs/solver.rst +++ b/docs/solver.rst @@ -2,10 +2,10 @@ Solvers ========================= Solvers are responsibe to orchestrate the calculations by combining the different elements, Molecule, QMCNet wave function, samplers and optimizers/schedulers -The main solver is caled `SolverOrbital` and is defined as +The main solver is caled `SolverSlaterJastrow` and is defined as ->>> from qmctorch.solver import SolverOrbital ->>> solver = SolverOrbital(wf=wf, sampler=sampler, +>>> from qmctorch.solver import SolverSlaterJastrow +>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler, >>> optimizer=opt, scheduler=scheduler, output='output.hdf5' As soon as the solver its content is defined the HDF5 file specficied byt `out`. This file will contain all the parameter @@ -14,7 +14,7 @@ of the solver and can be explored using the dedicated `h5x` browser. This solver Single point calculation ---------------------------- -A single point calculation sample the current wave function and computes the energy & variance of the system. +A single point calculation sample the current wave function and computes the energy & variance of the system. It can simply be done by: >>> obs = solver.single_point() @@ -27,14 +27,14 @@ It can simply be done by: * `obs.variance` : variance of the local energy values * `obs.error` : error on the energy -The result of the calculation will also be stored in the hdf5 output file. The energy distribution can be vizualised +The result of the calculation will also be stored in the hdf5 output file. The energy distribution can be vizualised with the matplotlib histogram function. Sampling trajectory ---------------------------- It is possible to compute the local energy during the propagation of the wlakers to assess the convergence of the sampling -To this end the sampler must be configured to output the walker position after each `N` steps. +To this end the sampler must be configured to output the walker position after each `N` steps. For example to start recording the walkers positions after 1000 MC steps and then record their position each 100 MC steps one can use : >>> from qmctorch.utils import plot_walkers_traj @@ -44,7 +44,7 @@ For example to start recording the walkers positions after 1000 MC steps and the >>> obs = solver.sampling_traj(pos) >>> plot_walkers_traj(obs.local_energy) -There as well the results are returned in the `obs` SimpleNamespace and are stored in the hdf5 file. +There as well the results are returned in the `obs` SimpleNamespace and are stored in the hdf5 file. The trajectory can be visualized with the `plot_wakers_traj` routine of QMCTorch Wave function optimization @@ -55,24 +55,24 @@ configured properly. >>> solver.configure(task='wf_opt', freeze=['ao', 'mo']) -To main task are available wave function optimization (`wf_opt`) and geometry optimization (`geo_opt`). +To main task are available wave function optimization (`wf_opt`) and geometry optimization (`geo_opt`). If a wave function optimization is selected the atom coordinate will be frozen while all the other parameters of the QMCNet will be optimized. -If a geometry optimization is selected only the atom coordinates will be optimized. One cal also freeze (i.e. not optimize) certain parameter groups. +If a geometry optimization is selected only the atom coordinates will be optimized. One cal also freeze (i.e. not optimize) certain parameter groups. In the example above the parameters of the atomic orbitals and molecular orbitals will be frozen, -One can specified the observale that needs to be recorded during the optimization. +One can specified the observale that needs to be recorded during the optimization. >>> solver.track_observable(['local_energy']) By default the local energy and all the variational parameters will be recorded. -As the system is optimized, one can resample the wave function by changing the positions of the walkers. +As the system is optimized, one can resample the wave function by changing the positions of the walkers. Several strategies are available to resample the wave function. The preferred one is to update the walkers by performing a small number of MC steps after each optimization step. This can be specified with : >>> solver.configure_resampling(mode='update', resample_every=1, nstep_update=25) -Finally we can now optimize the wave function using the `.run()` method of the solver. +Finally we can now optimize the wave function using the `.run()` method of the solver. This methods takes a few arguments, the number of optimization step, the batchsize, and some parameters to compute the gradients. >>> data = solver.run(5, batchsize=None, diff --git a/docs/tutorial_geo_opt.rst b/docs/tutorial_geo_opt.rst index 07c978c8..a3046f54 100644 --- a/docs/tutorial_geo_opt.rst +++ b/docs/tutorial_geo_opt.rst @@ -7,7 +7,7 @@ As previously the firs task is to import all the modules needed >>> from torch import optim >>> from torch.optim import Adam >>> from qmctorch.wavefunction import SlaterJastrow ->>> from qmctorch.solver import SolverOrbital +>>> from qmctorch.solver import SolverSlaterJastrow >>> from qmctorch.samplerimport Metropolis >>> from qmctorch.wavefunction import Molecule >>> from qmctorch.utils import plot_energy @@ -47,7 +47,7 @@ As an opimizer we use ADAM and define a simple linear scheduler. We can now assemble the solver >>> # solver ->>> solver = SolverOrbital(wf=wf, +>>> solver = SolverSlaterJastrow(wf=wf, >>> sampler=sampler, >>> optimizer=opt, >>> scheduler=scheduler) diff --git a/docs/tutorial_gpus.rst b/docs/tutorial_gpus.rst index 4afeba64..e13e7b2a 100644 --- a/docs/tutorial_gpus.rst +++ b/docs/tutorial_gpus.rst @@ -35,7 +35,7 @@ and use is as the normal solver and only a few modifications are required to use >>> import horovod.torch as hvd ->>> from deepqmc.solver.solver_orbital_horovod import SolverOrbitalHorovod +>>> from deepqmc.solver.solver_slater_jastrow_horovod import SolverSlaterJastrowHorovod >>> >>> hvd.init() >>> if torch.cuda.is_available(): @@ -48,7 +48,7 @@ and use is as the normal solver and only a few modifications are required to use >>> >>> ... >>> ->>> solver = SolverOrbitalHorovod(wf=wf, sampler=sampler, +>>> solver = SolverSlaterJastrowHorovod(wf=wf, sampler=sampler, >>> optimizer=opt, scheduler=scheduler, >>> rank=hvd.rank()) >>> .... diff --git a/docs/tutorial_sampling_traj.rst b/docs/tutorial_sampling_traj.rst index 6a2a02b4..90e7bc25 100644 --- a/docs/tutorial_sampling_traj.rst +++ b/docs/tutorial_sampling_traj.rst @@ -47,7 +47,7 @@ During the MC sampling each walker performs 500 steps of 0.25 atomic units. We h We can now assemble the solver. >>> # solver ->>> solver = SolverOrbital(wf=wf, sampler=sampler) +>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler) We can first perform a single point calculation. In this calculation the solver will sample the wave function and compute the energy of the system. diff --git a/docs/tutorial_wf_opt.rst b/docs/tutorial_wf_opt.rst index c26c4788..01a7bdcf 100644 --- a/docs/tutorial_wf_opt.rst +++ b/docs/tutorial_wf_opt.rst @@ -6,7 +6,7 @@ We first need to import all the relevant modules : >>> from torch import optim >>> from qmctorch.wavefunction import SlaterJastrow, Molecule ->>> from qmctorch.solver import SolverOrbital +>>> from qmctorch.solver import SolverSlaterJastrow >>> from qmctorch.sampler import Metropolis >>> from qmctorch.utils import set_torch_double_precision >>> from qmctorch.utils import (plot_energy, plot_data) @@ -62,7 +62,7 @@ We also define a linear scheduler that will decrease the learning rate after 100 We can now assemble the solver : >>> # QMC solver ->>> solver = SolverOrbital(wf=wf, sampler=sampler, optimizer=opt, scheduler=None) +>>> solver = SolverSlaterJastrow(wf=wf, sampler=sampler, optimizer=opt, scheduler=None) The solver needs to be configured. We set the task to wave function optimization and freeze here the variational parameters of the atomic orbitals and molecular orbitals. Hence only the jastrow factor and the CI coefficients diff --git a/example/gpu/h2.py b/example/gpu/h2.py index 76523969..1d4442a2 100644 --- a/example/gpu/h2.py +++ b/example/gpu/h2.py @@ -2,7 +2,7 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow -from qmctorch.solver import SolverOrbital +from qmctorch.solver import SolverSlaterJastrow from qmctorch.sampler import Metropolis from qmctorch.utils import set_torch_double_precision from qmctorch.utils import (plot_energy, plot_data) @@ -48,8 +48,8 @@ scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90) # QMC solver -solver = SolverOrbital(wf=wf, sampler=sampler, - optimizer=opt, scheduler=None) +solver = SolverSlaterJastrow(wf=wf, sampler=sampler, + optimizer=opt, scheduler=None) # perform a single point calculation obs = solver.single_point() diff --git a/example/horovod/h2.py b/example/horovod/h2.py index ca0808f1..3dfd2937 100644 --- a/example/horovod/h2.py +++ b/example/horovod/h2.py @@ -4,7 +4,7 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow -from qmctorch.solver import SolverOrbitalHorovod +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) @@ -51,9 +51,9 @@ scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90) # QMC solver -solver = SolverOrbitalHorovod(wf=wf, sampler=sampler, - optimizer=opt, scheduler=scheduler, - rank=hvd.rank()) +solver = SolverSlaterJastrowHorovod(wf=wf, sampler=sampler, + optimizer=opt, scheduler=scheduler, + rank=hvd.rank()) # configure the solver solver.configure(track=['local_energy'], freeze=['ao', 'mo'], diff --git a/example/optimization/h2.py b/example/optimization/h2.py index db1deec6..206812e8 100644 --- a/example/optimization/h2.py +++ b/example/optimization/h2.py @@ -2,7 +2,7 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow -from qmctorch.solver import SolverOrbital +from qmctorch.solver import SolverSlaterJastrow from qmctorch.sampler import Metropolis from qmctorch.utils import set_torch_double_precision from qmctorch.utils import (plot_energy, plot_data) @@ -47,8 +47,8 @@ scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90) # QMC solver -solver = SolverOrbital(wf=wf, sampler=sampler, - optimizer=opt, scheduler=None) +solver = SolverSlaterJastrow(wf=wf, sampler=sampler, + optimizer=opt, scheduler=None) # perform a single point calculation obs = solver.single_point() diff --git a/example/single_point/h2o_sampling.py b/example/single_point/h2o_sampling.py index 733f7fad..27c4cf57 100644 --- a/example/single_point/h2o_sampling.py +++ b/example/single_point/h2o_sampling.py @@ -1,7 +1,7 @@ from qmctorch.scf import Molecule from qmctorch.wavefunction import SlaterJastrow from qmctorch.sampler import Metropolis -from qmctorch.solver import SolverOrbital +from qmctorch.solver import SolverSlaterJastrow from qmctorch.utils import plot_walkers_traj # define the molecule @@ -20,7 +20,7 @@ move={'type': 'one-elec', 'proba': 'normal'}) # solver -solver = SolverOrbital(wf=wf, sampler=sampler) +solver = SolverSlaterJastrow(wf=wf, sampler=sampler) # single point obs = solver.single_point() diff --git a/notebooks/qmctorch.ipynb b/notebooks/qmctorch.ipynb index 093fa17a..c07ec364 100644 --- a/notebooks/qmctorch.ipynb +++ b/notebooks/qmctorch.ipynb @@ -1 +1 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"qmctorch.ipynb","provenance":[],"authorship_tag":"ABX9TyMr6DKmNBGlyg+0pzpuupgz"},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"markdown","metadata":{"id":"PA9WOB4zJfCu","colab_type":"text"},"source":["# 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":{"id":"6KLOhN_dGQ11","colab_type":"text"},"source":["## Install QMCTorch from Pypi Package manager\n","\n","```\n","! pip install qmctorch\n","```\n","\n"]},{"cell_type":"markdown","metadata":{"id":"Eb9wI3eOGfz1","colab_type":"text"},"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":{"id":"_VNw5sAeHC7M","colab_type":"text"},"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","metadata":{"id":"khGd1-ewHZWF","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":671},"outputId":"674fbe9e-7817-4e11-cc91-cd508bda8107","executionInfo":{"status":"ok","timestamp":1588617088336,"user_tz":-120,"elapsed":9770,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"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 .."],"execution_count":1,"outputs":[{"output_type":"stream","text":["Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount(\"/content/gdrive\", force_remount=True).\n","/content/gdrive/My Drive/QMCTorch\n","From https://github.com/NLESC-JCER/QMCTorch\n"," * branch master -> FETCH_HEAD\n","Already up to date.\n","Obtaining file:///content/gdrive/My%20Drive/QMCTorch\n","Requirement already satisfied: autograd in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.3)\n","Requirement already satisfied: cython in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.29.17)\n","Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (3.2.1)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.18.3)\n","Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (5.3.1)\n","Requirement already satisfied: schema in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.7.2)\n","Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.4.1)\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (4.38.0)\n","Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.5.0+cu101)\n","Requirement already satisfied: pyscf in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.7.1)\n","Requirement already satisfied: mendeleev in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.6.0)\n","Requirement already satisfied: future>=0.15.2 in /usr/local/lib/python3.6/dist-packages (from autograd->qmctorch==0.1.0) (0.16.0)\n","Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (2.4.7)\n","Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (2.8.1)\n","Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (0.10.0)\n","Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (1.2.0)\n","Requirement already satisfied: contextlib2>=0.5.5 in /usr/local/lib/python3.6/dist-packages (from schema->qmctorch==0.1.0) (0.5.5)\n","Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from pyscf->qmctorch==0.1.0) (2.10.0)\n","Requirement already satisfied: pyfiglet in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (0.8.post1)\n","Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (1.0.3)\n","Requirement already satisfied: sqlalchemy in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (1.3.16)\n","Requirement already satisfied: colorama in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (0.4.3)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib->qmctorch==0.1.0) (1.12.0)\n","Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->mendeleev->qmctorch==0.1.0) (2018.9)\n","Installing collected packages: qmctorch\n"," Found existing installation: qmctorch 0.1.0\n"," Can't uninstall 'qmctorch'. No files were found to uninstall.\n"," Running setup.py develop for qmctorch\n","Successfully installed qmctorch\n","/content/gdrive/My Drive\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"MGNu_L-OJ-7u","colab_type":"text"},"source":["# Using QMCTorch"]},{"cell_type":"code","metadata":{"id":"p7qEQTV2HB4h","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":52},"outputId":"52c2bbce-3775-442c-95de-d18bd432c2e3","executionInfo":{"status":"ok","timestamp":1588617090211,"user_tz":-120,"elapsed":11632,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["from torch import optim\n","from qmctorch.wavefunction import SlaterJastrow, Molecule\n","from qmctorch.solver import SolverOrbital\n","from qmctorch.sampler import Metropolis\n","from qmctorch.utils import set_torch_double_precision\n","from qmctorch.utils import plot_energy, plot_data"],"execution_count":2,"outputs":[{"output_type":"stream","text":["/content/gdrive/My Drive/QMCTorch/qmctorch/wavefunction/calculator/adf.py:12: UserWarning: scm python module not found\n"," warnings.warn('scm python module not found')\n"],"name":"stderr"}]},{"cell_type":"code","metadata":{"id":"x-s06JyaHUdN","colab_type":"code","colab":{}},"source":["set_torch_double_precision()"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"7HO4cNaAID-F","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":52},"outputId":"a1f652aa-9bcb-4e9b-c038-833b29da2eae","executionInfo":{"status":"ok","timestamp":1588617090213,"user_tz":-120,"elapsed":11608,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["mol = Molecule(atom='H 0 0 0.69; H 0 0 -0.69', unit='bohr', \\\n"," calculator='pyscf', basis='sto-3g')"],"execution_count":4,"outputs":[{"output_type":"stream","text":["Running scf calculation\n","converged SCF energy = -1.11718492179418\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"hFZg-XanIOeY","colab_type":"code","colab":{}},"source":["wf = SlaterJastrow(mol, configs='cas(2,2)', cuda=True)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"Mqlk1N3tIVXN","colab_type":"code","colab":{}},"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=True)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"5-I7abLxI5qG","colab_type":"code","colab":{}},"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)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"xgXSp8JwJIr9","colab_type":"code","colab":{}},"source":["scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"g6TE--nNJL1H","colab_type":"code","colab":{}},"source":["solver = SolverOrbital(wf=wf, sampler=sampler,\n"," optimizer=opt, scheduler=scheduler)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"Y5MPLiv2JTCy","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":87},"outputId":"ef067f86-11b3-48e0-9dac-dc8ff5784905","executionInfo":{"status":"ok","timestamp":1588617105475,"user_tz":-120,"elapsed":26805,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["obs = solver.single_point()"],"execution_count":10,"outputs":[{"output_type":"stream","text":["100%|██████████| 2000/2000 [00:08<00:00, 222.80it/s]\n"],"name":"stderr"},{"output_type":"stream","text":["Acceptance rate 67.036 %\n","Energy : -1.141010163098497 +/- 0.015220386836893682\n","Variance : 0.46332035092937285\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"yfx4g1Luz9Z-","colab_type":"code","colab":{}},"source":["solver.configure(task='wf_opt', freeze=['ao', 'mo'])\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"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"VtrVSk620A1A","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"outputId":"32ad9904-40e5-4efa-bcee-27145e04cfd4","executionInfo":{"status":"ok","timestamp":1588617131289,"user_tz":-120,"elapsed":52595,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["obs = solver.run(50, batchsize=None,\n"," loss='energy',\n"," grad='manual',\n"," clip_loss=False)"],"execution_count":12,"outputs":[{"output_type":"stream","text":["100%|██████████| 2000/2000 [00:09<00:00, 220.98it/s]\n"," 0%| | 0/50 [00:00 FETCH_HEAD\n","Already up to date.\n","Obtaining file:///content/gdrive/My%20Drive/QMCTorch\n","Requirement already satisfied: autograd in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.3)\n","Requirement already satisfied: cython in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.29.17)\n","Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (3.2.1)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.18.3)\n","Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (5.3.1)\n","Requirement already satisfied: schema in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.7.2)\n","Requirement already satisfied: scipy in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.4.1)\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (4.38.0)\n","Requirement already satisfied: torch in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.5.0+cu101)\n","Requirement already satisfied: pyscf in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (1.7.1)\n","Requirement already satisfied: mendeleev in /usr/local/lib/python3.6/dist-packages (from qmctorch==0.1.0) (0.6.0)\n","Requirement already satisfied: future>=0.15.2 in /usr/local/lib/python3.6/dist-packages (from autograd->qmctorch==0.1.0) (0.16.0)\n","Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (2.4.7)\n","Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (2.8.1)\n","Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (0.10.0)\n","Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->qmctorch==0.1.0) (1.2.0)\n","Requirement already satisfied: contextlib2>=0.5.5 in /usr/local/lib/python3.6/dist-packages (from schema->qmctorch==0.1.0) (0.5.5)\n","Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from pyscf->qmctorch==0.1.0) (2.10.0)\n","Requirement already satisfied: pyfiglet in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (0.8.post1)\n","Requirement already satisfied: pandas in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (1.0.3)\n","Requirement already satisfied: sqlalchemy in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (1.3.16)\n","Requirement already satisfied: colorama in /usr/local/lib/python3.6/dist-packages (from mendeleev->qmctorch==0.1.0) (0.4.3)\n","Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib->qmctorch==0.1.0) (1.12.0)\n","Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas->mendeleev->qmctorch==0.1.0) (2018.9)\n","Installing collected packages: qmctorch\n"," Found existing installation: qmctorch 0.1.0\n"," Can't uninstall 'qmctorch'. No files were found to uninstall.\n"," Running setup.py develop for qmctorch\n","Successfully installed qmctorch\n","/content/gdrive/My Drive\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"MGNu_L-OJ-7u","colab_type":"text"},"source":["# Using QMCTorch"]},{"cell_type":"code","metadata":{"id":"p7qEQTV2HB4h","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":52},"outputId":"52c2bbce-3775-442c-95de-d18bd432c2e3","executionInfo":{"status":"ok","timestamp":1588617090211,"user_tz":-120,"elapsed":11632,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["from torch import optim\n","from qmctorch.wavefunction import SlaterJastrow, Molecule\n","from qmctorch.solver import SolverSlaterJastrow\n","from qmctorch.sampler import Metropolis\n","from qmctorch.utils import set_torch_double_precision\n","from qmctorch.utils import plot_energy, plot_data"],"execution_count":2,"outputs":[{"output_type":"stream","text":["/content/gdrive/My Drive/QMCTorch/qmctorch/wavefunction/calculator/adf.py:12: UserWarning: scm python module not found\n"," warnings.warn('scm python module not found')\n"],"name":"stderr"}]},{"cell_type":"code","metadata":{"id":"x-s06JyaHUdN","colab_type":"code","colab":{}},"source":["set_torch_double_precision()"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"7HO4cNaAID-F","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":52},"outputId":"a1f652aa-9bcb-4e9b-c038-833b29da2eae","executionInfo":{"status":"ok","timestamp":1588617090213,"user_tz":-120,"elapsed":11608,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["mol = Molecule(atom='H 0 0 0.69; H 0 0 -0.69', unit='bohr', \\\n"," calculator='pyscf', basis='sto-3g')"],"execution_count":4,"outputs":[{"output_type":"stream","text":["Running scf calculation\n","converged SCF energy = -1.11718492179418\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"hFZg-XanIOeY","colab_type":"code","colab":{}},"source":["wf = SlaterJastrow(mol, configs='cas(2,2)', cuda=True)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"Mqlk1N3tIVXN","colab_type":"code","colab":{}},"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=True)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"5-I7abLxI5qG","colab_type":"code","colab":{}},"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)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"xgXSp8JwJIr9","colab_type":"code","colab":{}},"source":["scheduler = optim.lr_scheduler.StepLR(opt, step_size=100, gamma=0.90)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"g6TE--nNJL1H","colab_type":"code","colab":{}},"source":["solver = SolverSlaterJastrow(wf=wf, sampler=sampler,\n"," optimizer=opt, scheduler=scheduler)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"Y5MPLiv2JTCy","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":87},"outputId":"ef067f86-11b3-48e0-9dac-dc8ff5784905","executionInfo":{"status":"ok","timestamp":1588617105475,"user_tz":-120,"elapsed":26805,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["obs = solver.single_point()"],"execution_count":10,"outputs":[{"output_type":"stream","text":["100%|██████████| 2000/2000 [00:08<00:00, 222.80it/s]\n"],"name":"stderr"},{"output_type":"stream","text":["Acceptance rate 67.036 %\n","Energy : -1.141010163098497 +/- 0.015220386836893682\n","Variance : 0.46332035092937285\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"yfx4g1Luz9Z-","colab_type":"code","colab":{}},"source":["solver.configure(task='wf_opt', freeze=['ao', 'mo'])\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"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"VtrVSk620A1A","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"outputId":"32ad9904-40e5-4efa-bcee-27145e04cfd4","executionInfo":{"status":"ok","timestamp":1588617131289,"user_tz":-120,"elapsed":52595,"user":{"displayName":"Nicolas Renaud","photoUrl":"","userId":"07120063468244602126"}}},"source":["obs = solver.run(50, batchsize=None,\n"," loss='energy',\n"," grad='manual',\n"," clip_loss=False)"],"execution_count":12,"outputs":[{"output_type":"stream","text":["100%|██████████| 2000/2000 [00:09<00:00, 220.98it/s]\n"," 0%| | 0/50 [00:00