Skip to content

Commit

Permalink
cc: reimplement read_file_to_string without calling TensorFlow (#3176)
Browse files Browse the repository at this point in the history
LAMMPS is using it

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Jan 25, 2024
1 parent 3ee3f4c commit 663e4a8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions source/api_cc/src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <fcntl.h>

#include <cstring>
#include <fstream>
#include <sstream>
#include <string>

#include "AtomMap.h"
#include "device.h"
Expand Down Expand Up @@ -1112,12 +1115,16 @@ template void deepmd::select_map_inv<deepmd::STRINGTYPE>(
#endif

void deepmd::read_file_to_string(std::string model, std::string& file_content) {
#ifdef BUILD_TENSORFLOW
deepmd::check_status(tensorflow::ReadFileToString(tensorflow::Env::Default(),
model, &file_content));
#else
throw deepmd::deepmd_exception("TODO: read_file_to_string only support TF");
#endif
// generated by GitHub Copilot
std::ifstream file(model);
if (file.is_open()) {
std::stringstream buffer;
buffer << file.rdbuf();
file_content = buffer.str();
file.close();
} else {
throw deepmd::deepmd_exception("Failed to open file: " + model);
}
}

void deepmd::convert_pbtxt_to_pb(std::string fn_pb_txt, std::string fn_pb) {
Expand Down

0 comments on commit 663e4a8

Please sign in to comment.