deepmodeling / abacus-develop

An electronic structure package based on either plane wave basis or numerical atomic orbitals.
http://abacus.ustc.edu.cn
GNU Lesser General Public License v3.0
174 stars 136 forks source link

Add --dry-run Option to ABACUS CLI #5074

Closed savebean closed 10 hours ago

savebean commented 2 months ago

Background

The --dry-run option is a common feature in many CLI tools, which serves a critical role in operational safety and testing. This feature enables users to:

1、Preview changes: Users can see what changes a command would make without actually applying them. 2、Verify command syntax and parameters: Ensures that commands and the central input files are constructed correctly without the risk of disruptive impacts. 3、Integrate with scripts and automation: Allows developers to incorporate the CLI tool into larger scripts and workflows safely by testing them in a --dry-run mode first.

Describe the solution you'd like

I propose adding a --dry-run option to the command line interface. This option would allow users to simulate commands without actually making any changes to the system or data. Since INPUT, STRU, and KPT are the central input files for the ABACUS program, it is crucial to ensure that these files are configured correctly and stored in the working directory before executing the program. If there is an incorrect configuration in the INPUT, STRU, or KPT files, the tool should provide detailed error messages to help diagnose and fix the issues.The --dry-run option would be particularly useful for verifying that these files are correctly set up and ready.

Task list only for developers

Notice Possible Changes of Behavior (Reminder only for developers)

No response

Notice any changes of core modules (Reminder only for developers)

No response

Notice Possible Changes of Core Modules (Reminder only for developers)

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

hongriTianqi commented 2 months ago

@savebean Just for your information, currently you can run

abacus --check-input

to avoid errors in INPUT parameters. However, the function to check memory, KPT and STRU files before running is still not yet available.

WHUweiqingzhou commented 1 month ago

I indeed think we need to design a memory-check function recently.

jinzx10 commented 1 month ago

Here's what QE supports: Image

kirk0830 commented 1 month ago

I test nstep = 0 in QE:


     Program PWSCF v.7.3.1 starts on 24Oct2024 at 14:41:45
        Git branch: HEAD
        Last git commit: 7fd60c9bc9fe7a7d1fe6f1049f4afba0eab9aeef
        Last git commit date: Thu Feb 29 10:18:05 2024 +0000
        Last git commit subject: Merge branch 'master_qe_7.3.1' into 'master'

     This program is part of the open-source Quantum ESPRESSO suite
     for quantum simulation of materials; please cite
         "P. Giannozzi et al., J. Phys.:Condens. Matter 21 395502 (2009);
         "P. Giannozzi et al., J. Phys.:Condens. Matter 29 465901 (2017);
         "P. Giannozzi et al., J. Chem. Phys. 152 154105 (2020);
          URL http://www.quantum-espresso.org",
     in publications or presentations arising from this work. More details at
     http://www.quantum-espresso.org/quote

     Parallel version (MPI), running on     1 processors

     MPI processes distributed on     1 nodes
     6879 MiB available memory on the printing compute node when the environment starts

     Waiting for input...
     Reading input from standard input

     Current dimensions of program PWSCF are:
     Max number of different atomic species (ntypx) = 10
     Max number of k-points (npk) =  40000
     Max angular momentum in pseudopotentials (lmaxx) =  4
     Message from routine setup:
     using ibrav=0 with symmetry is DISCOURAGED, use correct ibrav instead

     Subspace diagonalization in iterative solution of the eigenvalue problem:
     a serial algorithm will be used

     G-vector sticks info
     --------------------
     sticks:   dense  smooth     PW     G-vecs:    dense   smooth      PW
     Sum         433     433    139                 5961     5961    1067

     Using Slab Decomposition

     bravais-lattice index     =            0
     lattice parameter (alat)  =       5.1066  a.u.
     unit-cell volume          =      94.1658 (a.u.)^3
     number of atoms/cell      =            1
     number of atomic types    =            1
     number of electrons       =         4.00
     number of Kohn-Sham states=            4
     kinetic-energy cutoff     =      60.0000  Ry
     charge density cutoff     =     240.0000  Ry
     scf convergence threshold =      1.0E-06
     mixing beta               =       0.5000
     number of iterations used =            8  plain     mixing
     Exchange-correlation= PBE
                           (   1   4   3   4   0   0   0)

     celldm(1)=   5.106650  celldm(2)=   0.000000  celldm(3)=   0.000000
     celldm(4)=   0.000000  celldm(5)=   0.000000  celldm(6)=   0.000000

     crystal axes: (cart. coord. in units of alat)
               a(1) = (   1.000000   0.000000   0.000000 )
               a(2) = (   0.500000   0.866025   0.000000 )
               a(3) = (   0.500000   0.288675   0.816497 )

     reciprocal axes: (cart. coord. in units 2 pi/alat)
               b(1) = (  1.000000 -0.577350 -0.408248 )
               b(2) = (  0.000000  1.154701 -0.408248 )
               b(3) = (  0.000000  0.000000  1.224745 )

     PseudoPot. # 1 for Si read from file:
     ./Si_ONCV_PBE-1.0.upf
     MD5 check sum: 2de5a83d12544a9ea852f39b88f19b1f
     Pseudo is Norm-conserving, Zval =  4.0
     Generated using ONCVPSP code by D. R. Hamann
     Using radial grid of  602 points,  4 beta functions with:
                l(1) =   0
                l(2) =   0
                l(3) =   1
                l(4) =   1

     atomic species   valence    mass     pseudopotential
     Si                4.00    28.08550     Si( 1.00)

     12 Sym. Ops., with inversion, found

                                    s                        frac. trans.

      isym =  1     identity

 cryst.   s( 1) = (     1          0          0      )
                  (     0          1          0      )
                  (     0          0          1      )

 cart.    s( 1) = (  1.0000000  0.0000000  0.0000000 )
                  (  0.0000000  1.0000000  0.0000000 )
                  (  0.0000000  0.0000000  1.0000000 )

      isym =  2     180 deg rotation - cart. axis [1,0,0]

 cryst.   s( 2) = (     1          0          0      )
                  (     1         -1          0      )
                  (     1          0         -1      )

 cart.    s( 2) = (  1.0000000  0.0000006  0.0000006 )
                  (  0.0000000 -1.0000000  0.0000000 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym =  3     120 deg rotation - cryst. axis [0,0,1]

 cryst.   s( 3) = (    -1          1          0      )
                  (    -1          0          0      )
                  (    -1          0          1      )

 cart.    s( 3) = ( -0.5000003 -0.8660256 -0.0000004 )
                  (  0.8660252 -0.4999997  0.0000004 )
                  (  0.0000000  0.0000000  1.0000000 )

      isym =  4     120 deg rotation - cryst. axis [0,0,-1]

 cryst.   s( 4) = (     0         -1          0      )
                  (     1         -1          0      )
                  (     0         -1          1      )

 cart.    s( 4) = ( -0.4999997  0.8660256 -0.0000006 )
                  ( -0.8660252 -0.5000003 -0.0000001 )
                  (  0.0000000  0.0000000  1.0000000 )

      isym =  5     180 deg rotation - cryst. axis [0,1,0]

 cryst.   s( 5) = (     0         -1          0      )
                  (    -1          0          0      )
                  (     0          0         -1      )

 cart.    s( 5) = ( -0.4999997 -0.8660259  0.0000002 )
                  ( -0.8660252  0.4999997 -0.0000004 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym =  6     180 deg rotation - cryst. axis [1,1,0]

 cryst.   s( 6) = (    -1          1          0      )
                  (     0          1          0      )
                  (     0          1         -1      )

 cart.    s( 6) = ( -0.5000003  0.8660253  0.0000001 )
                  (  0.8660252  0.5000003  0.0000001 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym =  7     inversion

 cryst.   s( 7) = (    -1          0          0      )
                  (     0         -1          0      )
                  (     0          0         -1      )

 cart.    s( 7) = ( -1.0000000  0.0000000  0.0000000 )
                  (  0.0000000 -1.0000000  0.0000000 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym =  8     inv. 180 deg rotation - cart. axis [1,0,0]

 cryst.   s( 8) = (    -1          0          0      )
                  (    -1          1          0      )
                  (    -1          0          1      )

 cart.    s( 8) = ( -1.0000000 -0.0000006 -0.0000006 )
                  (  0.0000000  1.0000000  0.0000000 )
                  (  0.0000000  0.0000000  1.0000000 )

      isym =  9     inv. 120 deg rotation - cryst. axis [0,0,1]

 cryst.   s( 9) = (     1         -1          0      )
                  (     1          0          0      )
                  (     1          0         -1      )

 cart.    s( 9) = (  0.5000003  0.8660256  0.0000004 )
                  ( -0.8660252  0.4999997 -0.0000004 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym = 10     inv. 120 deg rotation - cryst. axis [0,0,-1]

 cryst.   s(10) = (     0          1          0      )
                  (    -1          1          0      )
                  (     0          1         -1      )

 cart.    s(10) = (  0.4999997 -0.8660256  0.0000006 )
                  (  0.8660252  0.5000003  0.0000001 )
                  (  0.0000000  0.0000000 -1.0000000 )

      isym = 11     inv. 180 deg rotation - cryst. axis [0,1,0]

 cryst.   s(11) = (     0          1          0      )
                  (     1          0          0      )
                  (     0          0          1      )

 cart.    s(11) = (  0.4999997  0.8660259 -0.0000002 )
                  (  0.8660252 -0.4999997  0.0000004 )
                  (  0.0000000  0.0000000  1.0000000 )

      isym = 12     inv. 180 deg rotation - cryst. axis [1,1,0]

 cryst.   s(12) = (     1         -1          0      )
                  (     0         -1          0      )
                  (     0         -1          1      )

 cart.    s(12) = (  0.5000003 -0.8660253 -0.0000001 )
                  ( -0.8660252 -0.5000003 -0.0000001 )
                  (  0.0000000  0.0000000  1.0000000 )

   Cartesian axes

     site n.     atom                  positions (alat units)
         1        Si     tau(   1) = (   0.0000000   0.0000000   0.0000000  )

   Crystallographic axes

     site n.     atom                  positions (cryst. coord.)
         1        Si     tau(   1) = (  0.0000000  0.0000000  0.0000000  )

     number of k points=    19
                       cart. coord. in units 2pi/alat
        k(    1) = (   0.0000000   0.0000000   0.0000000), wk =   0.0160000
        k(    2) = (   0.0000000   0.0000000   0.2449490), wk =   0.0320000
        k(    3) = (   0.0000000   0.0000000   0.4898980), wk =   0.0320000
        k(    4) = (   0.0000000   0.2309402  -0.0816497), wk =   0.0960000
        k(    5) = (   0.0000000   0.2309402   0.1632993), wk =   0.0960000
        k(    6) = (   0.0000000   0.2309402   0.4082483), wk =   0.0960000
        k(    7) = (   0.0000000   0.2309402  -0.5715476), wk =   0.0960000
        k(    8) = (   0.0000000   0.2309402  -0.3265987), wk =   0.0960000
        k(    9) = (   0.0000000   0.4618803  -0.1632994), wk =   0.0960000
        k(   10) = (   0.0000000   0.4618803   0.0816496), wk =   0.0960000
        k(   11) = (   0.0000000   0.4618803   0.3265986), wk =   0.0960000
        k(   12) = (   0.0000000   0.4618803  -0.6531973), wk =   0.0960000
        k(   13) = (   0.0000000   0.4618803  -0.4082483), wk =   0.0960000
        k(   14) = (   0.2000000   0.3464103  -0.2449489), wk =   0.1920000
        k(   15) = (   0.2000000   0.3464103   0.0000000), wk =   0.0960000
        k(   16) = (   0.2000000   0.3464103  -0.7348469), wk =   0.1920000
        k(   17) = (   0.2000000  -0.5773503   0.0816498), wk =   0.1920000
        k(   18) = (   0.2000000  -0.5773503   0.5715477), wk =   0.1920000
        k(   19) = (   0.2000000  -0.5773503  -0.4082482), wk =   0.0960000

                       cryst. coord.
        k(    1) = (   0.0000000   0.0000000   0.0000000), wk =   0.0160000
        k(    2) = (   0.0000000   0.0000000   0.2000000), wk =   0.0320000
        k(    3) = (   0.0000000   0.0000000   0.4000000), wk =   0.0320000
        k(    4) = (   0.0000000   0.2000000  -0.0000000), wk =   0.0960000
        k(    5) = (   0.0000000   0.2000000   0.2000000), wk =   0.0960000
        k(    6) = (   0.0000000   0.2000000   0.4000000), wk =   0.0960000
        k(    7) = (   0.0000000   0.2000000  -0.4000000), wk =   0.0960000
        k(    8) = (   0.0000000   0.2000000  -0.2000000), wk =   0.0960000
        k(    9) = (   0.0000000   0.4000000  -0.0000000), wk =   0.0960000
        k(   10) = (   0.0000000   0.4000000   0.2000000), wk =   0.0960000
        k(   11) = (   0.0000000   0.4000000   0.4000000), wk =   0.0960000
        k(   12) = (   0.0000000   0.4000000  -0.4000000), wk =   0.0960000
        k(   13) = (   0.0000000   0.4000000  -0.2000000), wk =   0.0960000
        k(   14) = (   0.2000000   0.4000000   0.0000000), wk =   0.1920000
        k(   15) = (   0.2000000   0.4000000   0.2000000), wk =   0.0960000
        k(   16) = (   0.2000000   0.4000000  -0.4000000), wk =   0.1920000
        k(   17) = (   0.2000000  -0.4000000  -0.0000000), wk =   0.1920000
        k(   18) = (   0.2000000  -0.4000000   0.4000000), wk =   0.1920000
        k(   19) = (   0.2000000  -0.4000000  -0.4000000), wk =   0.0960000

     Dense  grid:     5961 G-vectors     FFT dimensions: (  25,  25,  25)

     Dynamical RAM for                 wfc:       0.05 MB

     Dynamical RAM for     wfc (w. buffer):       0.90 MB

     Dynamical RAM for           str. fact:       0.09 MB

     Dynamical RAM for           local pot:       0.00 MB

     Dynamical RAM for          nlocal pot:       0.09 MB

     Dynamical RAM for                qrad:       0.36 MB

     Dynamical RAM for          rho,v,vnew:       0.63 MB

     Dynamical RAM for               rhoin:       0.21 MB

     Dynamical RAM for            rho*nmix:       1.46 MB

     Dynamical RAM for           G-vectors:       0.39 MB

     Dynamical RAM for          h,s,v(r/c):       0.00 MB

     Dynamical RAM for          <psi|beta>:       0.00 MB

     Dynamical RAM for                 psi:       0.09 MB

     Dynamical RAM for                hpsi:       0.09 MB

     Dynamical RAM for      wfcinit/wfcrot:       0.09 MB

     Estimated static dynamical RAM per process >       3.44 MB

     Estimated max dynamical RAM per process >       5.08 MB

     Writing config-init to output data dir ./output/chgden-restart.save/ :
     XML data file

     Called by init_run:

     Called by electrons:

     Called by c_bands:

     Called by sum_band:

     Called by *egterg:

     Called by h_psi:

     General routines

     Parallel routines

     PWSCF        :      0.02s CPU      0.02s WALL

   This run was terminated on:  14:41:45  24Oct2024

=------------------------------------------------------------------------------=
   JOB DONE.
=------------------------------------------------------------------------------=
mohanchen commented 2 days ago

If we set nstep = 0, could the esolver perform this "dry run"? @YuLiu98

YuLiu98 commented 2 days ago

If we set nstep = 0, could the esolver perform this "dry run"? @YuLiu98

{
        Input_Item item("relax_nmax");
        item.annotation = "number of ion iteration steps";
        item.reset_value = [](const Input_Item& item, Parameter& para) {
            const std::string& calculation = para.input.calculation;
            const std::vector<std::string> singlelist
                = {"scf", "nscf", "get_S", "get_pchg", "get_wf", "test_memory", "test_neighbour", "gen_bessel"};
            if (std::find(singlelist.begin(), singlelist.end(), calculation) != singlelist.end())
            {
                para.input.relax_nmax = 1;
            }
            else if (calculation == "relax" || calculation == "cell-relax")
            {
                if (para.input.relax_nmax == 0) // default value
                {
                    para.input.relax_nmax = 50;
                }
            }
        };
        read_sync_int(input.relax_nmax);
        this->add_item(item);
    }

In abacus, relax_nmax will be reset to 1 for scf, and 50 for relax/cell-relax. The "dry run" can be implemented as follows:

{
        Input_Item item("relax_nmax");
        item.annotation = "number of ion iteration steps";
        item.reset_value = [](const Input_Item& item, Parameter& para) {
            const std::string& calculation = para.input.calculation;
            const std::vector<std::string> singlelist
                = {"scf", "nscf", "get_S", "get_pchg", "get_wf", "test_memory", "test_neighbour", "gen_bessel"};
            if (std::find(singlelist.begin(), singlelist.end(), calculation) != singlelist.end())
            {
                if (para.input.relax_nmax != 0)
                {
                    para.input.relax_nmax = 1;
                }
            }
            else if (calculation == "relax" || calculation == "cell-relax")
            {
                if (para.input.relax_nmax < 0)
                {
                    para.input.relax_nmax = 50;
                }
            }
        };
        read_sync_int(input.relax_nmax);
        this->add_item(item);
    }