Skip to content

Code quality improvements#7001

Merged
mohanchen merged 13 commits intodeepmodeling:developfrom
mohanchen:2026-03-07
Mar 9, 2026
Merged

Code quality improvements#7001
mohanchen merged 13 commits intodeepmodeling:developfrom
mohanchen:2026-03-07

Conversation

@mohanchen
Copy link
Collaborator

Reminder

  • Have you linked an issue with this pull request?
  • Have you added adequate unit tests and/or case tests for your pull request?
  • Have you noticed possible changes of behavior below or in the linked issue?
  • Have you explained the changes of codes in core modules of ESolver, HSolver, ElecState, Hamilt, Operator or Psi? (ignore if not applicable)

Linked Issue

Fix #...

Unit Tests and/or Case Tests for my changes

  • A unit test is added for each new feature or bug fix.

What's changed?

  • Example: My changes might affect the performance of the application under certain conditions, and I have tested the impact on various scenarios...

Any changes of core modules? (ignore if not applicable)

  • Example: I have added a new virtual function in the esolver base class in order to ...

abacus_fixer added 9 commits March 7, 2026 20:13
Replace standard exception handling with project-specific error handling
in cell_index.cpp to comply with ABACUS code style guidelines.

Changes:
- Replace 3 instances of 'throw std::out_of_range' with ModuleBase::WARNING_QUIT
  in functions: iw2l(), iw2z(), iw2m()
- Remove unnecessary #include <stdexcept>
- Fix incorrect error message strings in iw2z() and iw2m() (was 'iw2l')

This change follows the cpp-code-style skill rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions for
error handling in the ABACUS project.
Add const qualifier to all getter and helper member functions in
CellIndex class to improve const-correctness according to cpp-code-style
skill guidelines.

Changes in cell_index.h:
- Add const to all public getter functions: get_nat(), get_ntype(),
  get_nw(), get_iwt(), get_maxL(), get_nchi(), get_atom_label()
- Add const to write_orb_info() and change parameter to const reference
- Add const to private helper functions: iat2it(), iat2ia(), iw2l(),
  iw2z(), iw2m()

Changes in cell_index.cpp:
- Update all function definitions to match header declarations
- Change write_orb_info parameter from std::string to const std::string&

This follows the ABACUS code style rule that getter functions and
functions that do not modify member state should be marked const.
- 在density_matrix.cpp中添加了tool_quit.h头文件
- 将第616行的throw std::string替换为ModuleBase::WARNING_QUIT
- 统一了项目的错误处理方式,符合ABACUS代码规范

修改文件:
- source/source_estate/module_dm/density_matrix.cpp

影响范围:错误处理流程
- 将泛型lambda [](auto x) 改为 [](double x)
- 符合ABACUS项目只支持C++11标准的要求
- Matrix3的元素类型为double,无需泛型

修改文件:
- source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp
Replace standard exception handling with project-specific error handling
in restart.cpp to comply with cpp-code-style skill guidelines.

Changes:
- Replace 4 instances of 'throw std::runtime_error' with ModuleBase::WARNING_QUIT
  in functions: write_file2() and read_file2()
- Remove unnecessary #include <stdexcept>
- Add #include "source_base/tool_quit.h"

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.
Replace standard exception handling with project-specific error handling
in write_libxc_r.cpp to comply with cpp-code-style skill guidelines.

Changes:
- Replace 9 instances of throw with ModuleBase::WARNING_QUIT
  - throw std::domain_error -> WARNING_QUIT
  - throw std::invalid_argument -> WARNING_QUIT
- Remove #include <stdexcept>
- Add #include "source_base/tool_quit.h"

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.
- Replace tabs with 4 spaces in md_func.cpp (lines 198-209)
- Replace tabs with 4 spaces in md_base.cpp (line 65)
- Replace tabs with 4 spaces in run_md.cpp (lines 59-61)
Replace standard exception handling with project-specific error handling
in source_io directory to comply with cpp-code-style skill guidelines.

Changes:
- Replace all instances of throw with ModuleBase::WARNING_QUIT
  - throw std::runtime_error -> WARNING_QUIT
  - throw std::logic_error -> WARNING_QUIT
  - throw std::invalid_argument -> WARNING_QUIT
  - throw std::domain_error -> WARNING_QUIT
- Remove unnecessary #include <stdexcept>
- Add #include "source_base/tool_quit.h" where needed

Files modified:
- module_restart/restart.cpp (4 instances)
- module_chgpot/write_libxc_r.cpp (9 instances)
- module_wannier/to_wannier90_lcao.h (1 instance)
- module_wannier/to_wannier90_lcao_in_pw.h (1 instance)
- module_wannier/to_wannier90_pw.h (1 instance)
- module_wannier/to_wannier90.cpp (1 instance)
- module_unk/berryphase.h (1 instance)
- module_parameter/read_input_tool.h (1 instance)
- module_parameter/input_conv.cpp (1 instance)

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.
@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Mar 7, 2026
abacus_fixer added 4 commits March 8, 2026 21:37
- 恢复Vector3的operator==为直接比较
- 移除之前添加的eps精度比较逻辑

修改文件:
- source/source_base/vector3.h
Copy link
Collaborator

@Cstandardlib Cstandardlib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mohanchen mohanchen merged commit 4c61a5b into deepmodeling:develop Mar 9, 2026
15 checks passed
@mohanchen mohanchen deleted the 2026-03-07 branch March 12, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants