©️ Copyright 2024 @ Authors
作者:John Yan (AISI电子结构团队实习生) 📨
日期:2024-9-26
共享协议:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
快速开始:点击上方的 开始连接 按钮,选择 deepks-abacus:3.7.5v1 镜像及 c2_m4_cpu 节点配置,并在连接后点击右上方的切换内核,选择Python (ipykernel)内核稍等片刻即可运行。
目录:
0. 写在前边
1. 多标签训练数据的准备
2. 进行多标签训练需要修改的参数
3. 多标签训练过程
4. 多标签训练结果
0. 写在前边
DeePKS模型训练有两条难度线,一条是算例体系的泛化,即从单一元素体系和单一元素组合体系到多元素组合和原子数不同的复杂体系;另一条是标签的扩展,从最简单的能量标签训练出发,到引入力、应力和能带等多标签训练。
本节基于上一节实现的单一元素体系的能量标签训练,将训练的标签扩展到能量、力、应力和能带等多个标签。
1. 多标签训练数据的准备
参考附录教程DeePKS实战(附录)|使用DeePKS init功能进行训练数据的生产里的方案,使用ABACUS批量生产hse06标签。
. ├── group.04 │ ├── ABACUS │ ├── atom.npy │ ├── box.npy │ ├── energy.npy │ ├── force.npy │ ├── orbital.npy │ └── stress.npy ├── group.05 │ ├── ABACUS │ ├── atom.npy │ ├── box.npy │ ├── energy.npy │ ├── force.npy │ ├── orbital.npy │ └── stress.npy ├── group.06 │ ├── ABACUS │ ├── atom.npy │ ├── box.npy │ ├── energy.npy │ ├── force.npy │ ├── orbital.npy │ └── stress.npy ├── rm_chg.py └── stats.py 6 directories, 20 files
2. 进行多标签训练需要修改的参数
2.1 scf_abacus.yaml
需要修改abacus计算input参数,使其能够正常输出力、应力和轨道文件
cal_force: 1 #输出力结果
cal_stress: 1 #输出应力结果
deepks_bandgap: 1 #输出轨道(能带)结果
完整的参数:
scf_abacus:
#INPUT args
# ntype: 3
ecutwfc: 100
scf_thr: 1e-7
scf_nmax: 50
dft_functional: "pbe"
gamma_only: 0
kspacing: 0.1
cal_force: 1 #输出力结果
cal_stress: 1 #输出应力结果
deepks_bandgap: 1 #输出轨道(能带)结果
#STRU args ( Here are default STRU args, you can set for each group in ../systems/group.xx/stru_abacus.yaml )
orb_files: ["Cs_gga_10au_100Ry_4s2p1d.orb","Pb_gga_7au_100Ry_2s2p2d1f.orb","I_gga_7au_100Ry_2s2p2d1f.orb"]
pp_files: ["Cs_ONCV_PBE-1.0.upf","Pb_ONCV_PBE-1.0.upf","I_ONCV_PBE-1.0.upf"]
proj_file: ["jle.orb"]
lattice_constant: 1.88972613
lattice_vector: [[28, 0, 0], [0, 28, 0], [0, 0, 28]]
coord_type: "Cartesian"
#cmd args
run_cmd : "mpirun"
abacus_path: "abacus"
注意,为了使得模型更容易收敛,第一轮init时不训练力、应力和轨道标签,相应的init_scf_abacus部分为:
init_scf_abacus:
orb_files: ["Cs_gga_10au_100Ry_4s2p1d.orb","Pb_gga_7au_100Ry_2s2p2d1f.orb","I_gga_7au_100Ry_2s2p2d1f.orb"]
pp_files: ["Cs_ONCV_PBE-1.0.upf","Pb_ONCV_PBE-1.0.upf","I_ONCV_PBE-1.0.upf"]
proj_file: ["jle.orb"]
# ntype: 3
ecutwfc: 100
scf_thr: 1e-7
scf_nmax: 50
dft_functional: "pbe"
gamma_only: 0
kspacing: 0.1
cal_force: 0 #init不输出力
cal_stress: 0 #init不输出应力
deepks_bandgap: 0 #init不输出轨道(能带)
lattice_constant: 1.88972613
lattice_vector: [[28, 0, 0], [0, 28, 0], [0, 0, 28]]
coord_type: "Cartesian"
#cmd args
run_cmd : "mpirun"
abacus_path: "abacus"
2.2 params.yaml
需要修改params.yaml
中的参数使得其他标签可以加入到训练中,
extra_label
为true
时打开多标签训练
extra_label: true #set to true if force/stress/energy gap labels are required
force_factor
stress_factor
和orbital_factor
决定其在Loss函数中的占比
force_factor: 1 #for force training; otherwise set to 0.
stress_factor: 0.1 #for stress training; otherwise set to 0.
orbital_factor: 0.1 #set to non-zero value (e.g. 0.001) for orbital training.
3. 多标签训练过程
填写提交bohrium服务器运行的账户信息
--------------------------------------------------------------------------- KeyboardInterrupt Traceback (most recent call last) Cell In[15], line 9 6 with open(file_path) as f: 7 j = yaml.load(f.read(), Loader=yaml.FullLoader) ----> 9 email = input('Please enter your Bohrium account: ') 10 password = getpass.getpass('Please enter your password: ') 11 program_id = int(input('Please enter your Bohrium Program ID: ')) File /opt/miniconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1191, in Kernel.raw_input(self, prompt) 1189 msg = "raw_input was called, but this frontend does not support input requests." 1190 raise StdinNotImplementedError(msg) -> 1191 return self._input_request( 1192 str(prompt), 1193 self._parent_ident["shell"], 1194 self.get_parent("shell"), 1195 password=False, 1196 ) File /opt/miniconda3/lib/python3.9/site-packages/ipykernel/kernelbase.py:1234, in Kernel._input_request(self, prompt, ident, parent, password) 1231 except KeyboardInterrupt: 1232 # re-raise KeyboardInterrupt, to truncate traceback 1233 msg = "Interrupted by user" -> 1234 raise KeyboardInterrupt(msg) from None 1235 except Exception: 1236 self.log.warning("Invalid Message:", exc_info=True) KeyboardInterrupt: Interrupted by user
取消以下代码的注释并运行可进行计算,大约会产生60-80元机时费用。
4. 多标签训练结果
多标签训练每一轮的log.data如下:
iter.00
Training:
Convergence:
30 / 30 = 1.00000
Energy:
ME: 0.0036325675616694754
MAE: 0.0036325675616694754
MARE: 0.0006202088155676696
Force:
MAE: 0.00031047197788019787
Stress:
MAE: 0.00509711461234655
Band gap:
ME: 0.0217763592973436
MAE: 0.0217763592973436
Testing:
Convergence:
37 / 37 = 1.00000
Energy:
ME: 0.00432524858408485
MAE: 0.00432524858408485
MARE: 0.0008778410702938025
Force:
MAE: 0.00037751705637948437
Stress:
MAE: 0.008439109417934182
Band gap:
ME: 0.021472271924102487
MAE: 0.021472271924102487
iter.01
Training:
Convergence:
30 / 30 = 1.00000
Energy:
ME: 0.008357217276113715
MAE: 0.008357217276113715
MARE: 0.0015358664115448543
Force:
MAE: 0.0004249036064122422
Stress:
MAE: 0.015347465219679106
Band gap:
ME: 0.006760373705103745
MAE: 0.006760373705103745
Testing:
Convergence:
37 / 37 = 1.00000
Energy:
ME: 0.007583024722567348
MAE: 0.007583024722567348
MARE: 0.0013684131109182483
Force:
MAE: 0.00044004924622762263
Stress:
MAE: 0.014461125805247648
Band gap:
ME: 0.006600627478013085
MAE: 0.006600627478013085
iter.02
Training:
Convergence:
30 / 30 = 1.00000
Energy:
ME: 0.0006353705590716648
MAE: 0.0009276039754505897
MARE: 0.0008527887952216891
Force:
MAE: 0.00035674037672368846
Stress:
MAE: 0.0087785683650925
Band gap:
ME: 0.0038443141246316307
MAE: 0.0038443141246316307
Testing:
Convergence:
37 / 37 = 1.00000
Energy:
ME: -0.00016738497028986662
MAE: 0.0010452550887207876
MARE: 0.0011611679875557516
Force:
MAE: 0.00041020894030708855
Stress:
MAE: 0.007606386995156406
Band gap:
ME: 0.003620361175074024
MAE: 0.003620361175074024
iter.03
Training:
Convergence:
30 / 30 = 1.00000
Energy:
ME: 0.001077702114158304
MAE: 0.0011860366540342208
MARE: 0.0008605049311823778
Force:
MAE: 0.0003129899115989905
Stress:
MAE: 0.0055061639932380375
Band gap:
ME: 0.0029869254451397953
MAE: 0.0029869254451397953
Testing:
Convergence:
37 / 37 = 1.00000
Energy:
ME: 0.0007973178436640336
MAE: 0.0012508888721087616
MARE: 0.0010596540751692432
Force:
MAE: 0.0003814934209592415
Stress:
MAE: 0.005787238208981942
Band gap:
ME: 0.0027956571819744767
MAE: 0.0027956571819744767
以上是运行了4轮训练的结果,可以看到使用ABACUS标签训练的模型在每一轮次中都展现出100%的收敛比例。教程中为了演示iter只设置为4,在真实环境下可能需要更多的循环次数以获得更精确的结果。