Coder Social home page Coder Social logo

deepsolid's Introduction

DeepSolid

An implementation of the algorithm given in "Ab initio calculation of real solids via neural network ansatz". A periodic neural network is proposed as wavefunction ansatz for solid quantum Monte Carlo and achieves unprecedented accuracy compared with other state-of-the-art methods. This repository is developed upon FermiNet and PyQMC.

Installation

DeepSolid can be installed via the supplied setup.py file.

pip3 install -e.

If GPU is available, we recommend you to install jax and jaxlib with cuda 11.4+. Our experiments were carried out with jax==0.2.26 and jaxlib==0.1.75.

Usage

Ml_collection package is used for system definition. Below is a simple example of H10 in PBC:

deepsolid --config=PATH/TO/DeepSolid/config/two_hydrogen_cell.py:H,5,1,1,2.0,0,ccpvdz --config.batch_size 4096

Customize your system

Simulation system can be customized in config.py file, such as

import numpy as np
from pyscf.pbc import gto
from DeepSolid import base_config
from DeepSolid import supercell


def get_config(input_str):
    symbol, S = input_str.split(',')
    cfg = base_config.default()

    # Set up cell.
    cell = gto.Cell()
    
    # Define the atoms in the primitive cell.
    cell.atom = f"""
    {symbol} 0.000000000000   0.000000000000   0.000000000000
    """
    
    # Define the pretrain basis.
    cell.basis = "ccpvdz"
    
    # Define the lattice vectors of the primitive cell.
    # In this example it's a simple cubic.
    cell.a = np.array([[3.0, 0.0, 0.0],
                       [0.0, 3.0, 0.0],
                       [0.0, 0.0, 3.0]])
    
    # Define the unit used in cell definition, only support Bohr now. 
    cell.unit = "B"
    cell.verbose = 5
    
    # Define the threshold to discard gaussian basis used in pretrain.
    cell.exp_to_discard = 0.1
    cell.build()
    
    # Define the supercell for QMC, S specifies how to tile the primitive cell.
    S = np.eye(3) * int(S)
    simulation_cell = supercell.get_supercell(cell, S)
    
    # Assign the defined supercell to cfg.
    cfg.system.pyscf_cell = simulation_cell

    return cfg

After defining the config file, simply use the following command to launch the simulation:

deepsolid --config=PATH/TO/config.py:He,1 --config.batch_size 4096

Read structure from poscar file

We also support reading structure from poscar file, which is commonly used. Simply use the following command

deepsolid --config=DeepSolid/config/read_poscar.py:PATH/TO/POSCAR/bcc_li.vasp,1,ccpvdz

Distributed training

Present released code doesn't support multi-node training. See this link for help.

Tricks to accelerate

The bottleneck of DeepSolid is the laplacian evaluation of the neural network. We recommend the users to use partition mode instead, simply adding two more flags:

deepsolid --config=PATH/TO/config.py --config.optim.laplacian_mode=partition --config.optim.partition_number=3

Partition mode will try to parallelize the calculation of laplacian and partition number must be a factor of (electron number * 3). Note that partition mode will require a lot of GPU memory.

Precision

DeepSolid supports both FP32 and FP64. However, we recommend the users turn off the TF32 mode which is automatically adopted in A100 if FP32 is chosen. TF32 can be turned off using the following command:

NVIDIA_TF32_OVERRIDE=0 deepsolid --config.use_x64=False

Giving Credit

If you use this code in your work, please cite the associated paper.

@article{li2022ab,
  title={Ab initio calculation of real solids via neural network ansatz},
  author={Li, Xiang and Li, Zhe and Chen, Ji},
  journal={Nature Communications},
  volume={13},
  number={1},
  pages={7895},
  year={2022},
  publisher={Nature Publishing Group UK London}
}

deepsolid's People

Contributors

giantelephant123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

deepsolid's Issues

Question on ee part of ewaldsum

Thank you for making this code open-source.

One question comes to me when I read the ewaldsum. When the electron distances are calculated the same way as the ion distances, does it imply that the electrons are sampled from one cell and mirrored periodically instead of sampled independently from each supercell? Would there be a problem doing so?

errors when run example from "Customize your system".

Hi,

When I try a example in README, an error occurs:

$ python ../bin/deepsolid --config=./config.py:He,1 --config.batch_size 4096

"jax.host_id has been renamed to jax.process_index. This alias "
I0209 11:46:10.033802 140551624116032 process.py:150] Pretrain using Net distribution.
Traceback (most recent call last):
File "../bin/deepsolid", line 37, in
app.run(main)
File "/anaconda3/envs/Pmg/lib/python3.7/site-packages/absl/app.py", line 308, in run
_run_main(main, args)
File "
/anaconda3/envs/Pmg/lib/python3.7/site-packages/absl/app.py", line 254, in _run_main
sys.exit(main(argv))
File "../bin/deepsolid", line 33, in main
process.process(cfg)
File "/envs/apps/DeepSolid/DeepSolid/process.py", line 161, in process
full_det=cfg.network.detnet.full_det,
File "
/apps/DeepSolid/DeepSolid/pretrain.py", line 152, in pretrain_hartree_fock
target = scf_approx.eval_orb_mat(np.array(data.reshape([-1, cell.nelectron, 3]), dtype=np.float64))
File "/apps/DeepSolid/DeepSolid/hf.py", line 143, in eval_orb_mat
aos = self.eval_orbitals_pbc(coord)
File "
/apps/DeepSolid/DeepSolid/hf.py", line 113, in eval_orbitals_pbc
prim_coord, wrap = distance.np_enforce_pbc(self.primitive_cell.a, coord.reshape([coord.shape[0], -1]))
File "~/apps/DeepSolid/DeepSolid/distance.py", line 178, in np_enforce_pbc
dim = latvec.shape[-1]
AttributeError: 'str' object has no attribute 'shape'

Here the code in np_enforce_pbc funcion:

$ vi /data/chenp/apps/DeepSolid/DeepSolid/distance.py +178
line 178 dim = latvec.shape[-1]
line 179 epos = epos.reshape(-1, dim)
line 180 recpvecs = np.linalg.inv(latvec)

I try to change latvec format to numpy, but it does not work. Have I used wrong configures?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.