Skip to content

[Code scan] Document or build graph.pb generation in infer_water #5693

Description

@njzjz

This issue comes from a Codex global scan of deepmodeling/deepmd-kit at commit 73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.

Problem

The examples/infer_water README tells users to run CMake and make:

Build the project using
```sh
cmake -DCMAKE_PREFIX_PATH=$deepmd_root .
make
```

The CMake project builds the four inference binaries:

# C++ example
add_executable(infer_water_cc infer_water.cpp)
# link DeePMD-kit C++ API
target_link_libraries(infer_water_cc PRIVATE DeePMD::deepmd_cc)
# C example
add_executable(infer_water_c infer_water.c)
# link DeePMD-kit C API
target_link_libraries(infer_water_c PRIVATE DeePMD::deepmd_c)
# header-only example
add_executable(infer_water_hpp infer_water_hpp.cpp)
# link DeePMD-kit C API
target_link_libraries(infer_water_hpp PRIVATE DeePMD::deepmd_c)
# nlist
add_executable(infer_water_nlist infer_water_nlist.cpp)
# link DeePMD-kit C API
target_link_libraries(infer_water_nlist PRIVATE DeePMD::deepmd_c)

Those binaries all open graph.pb from the current working directory:

int main() {
const char* model = "graph.pb";
double coord[] = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
double cell[] = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
int atype[] = {1, 0, 1};
// init C pointers with given memory
double* e = malloc(sizeof(*e));
double* f = malloc(sizeof(*f) * 9); // natoms * 3
double* v = malloc(sizeof(*v) * 9);
double* ae = malloc(sizeof(*ae) * 9); // natoms
double* av = malloc(sizeof(*av) * 27); // natoms * 9
// DP model
DP_DeepPot* dp = DP_NewDeepPot(model);
DP_DeepPotCompute(dp, 3, coord, atype, cell, e, f, v, ae, av);

int main() {
deepmd::DeepPot dp("graph.pb");
std::vector<double> coord = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
std::vector<double> cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
std::vector<int> atype = {1, 0, 1};
double e;
std::vector<double> f, v;
dp.compute(e, f, v, coord, atype, cell);

int main() {
deepmd::hpp::DeepPot dp("graph.pb");
std::vector<double> coord = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
std::vector<double> cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
std::vector<int> atype = {1, 0, 1};
double e;
std::vector<double> f, v;
dp.compute(e, f, v, coord, atype, cell);

int main() {
DeepPot dp("graph.pb");
std::vector<double> coord = {1., 0., 0., 0., 0., 1.5, 1., 0., 3.};
std::vector<double> cell = {10., 0., 0., 0., 10., 0., 0., 0., 10.};
std::vector<int> atype = {1, 0, 1};
// neighbor list
std::vector<std::vector<int>> nlist_vec = {{1, 2}, {0, 2}, {0, 1}};
double e;
std::vector<double> f, v;
std::vector<int> ilist(3), numneigh(3);
std::vector<int*> firstneigh(3);
InputNlist nlist(3, &ilist[0], &numneigh[0], &firstneigh[0]);
convert_nlist(nlist, nlist_vec);
dp.compute(e, f, v, coord, atype, cell, 0, nlist, 0);

graph.pb is ignored rather than checked in:

There is a convert_model.c helper that can create it, but the helper is not built by CMakeLists.txt and the README does not tell users to run it:

int main() {
DP_ConvertPbtxtToPb("../../source/tests/infer/deeppot.pbtxt", "graph.pb");
return 0;

Impact

Following the documented build commands produces binaries that fail at runtime unless the user already knows how to create graph.pb. The hidden conversion helper also depends on a test fixture path, which makes the example less self-contained.

Suggested fix

Either document the required model-generation step explicitly, or wire convert_model.c into the CMake project as a helper target and have the README run it before the inference examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions