You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

eval.py 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """eval."""
  16. import argparse
  17. import numpy as np
  18. import mindspore.common.dtype as mstype
  19. from mindspore import Tensor
  20. from mindspore import context
  21. from mindspore.train.serialization import load_checkpoint, load_param_into_net
  22. from src.network import Network
  23. parser = argparse.ArgumentParser(description='MD Simulation')
  24. parser.add_argument('--checkpoint_path', type=str, default=None, help='Checkpoint file path')
  25. parser.add_argument('--dataset_path', type=str, default=None, help='Dataset path')
  26. args_opt = parser.parse_args()
  27. context.set_context(mode=context.GRAPH_MODE, save_graphs=False, device_target="Ascend")
  28. if __name__ == '__main__':
  29. # get input data
  30. r = np.load(args_opt.dataset_path)
  31. d_coord, d_nlist, avg, std, atype, nlist = r['d_coord'], r['d_nlist'], r['avg'], r['std'], r['atype'], r['nlist']
  32. batch_size = 1
  33. atype_tensor = Tensor(atype)
  34. avg_tensor = Tensor(avg)
  35. std_tensor = Tensor(std)
  36. nlist_tensor = Tensor(nlist)
  37. d_coord_tensor = Tensor(np.reshape(d_coord, (1, -1, 3)))
  38. d_nlist_tensor = Tensor(d_nlist)
  39. frames = []
  40. for i in range(batch_size):
  41. frames.append(i * 1536)
  42. frames = Tensor(frames)
  43. # evaluation
  44. net = Network()
  45. param_dict = load_checkpoint(args_opt.checkpoint_path)
  46. load_param_into_net(net, param_dict)
  47. net.to_float(mstype.float32)
  48. energy, atom_ener, _ = \
  49. net(d_coord_tensor, d_nlist_tensor, frames, avg_tensor, std_tensor, atype_tensor, nlist_tensor)
  50. print('energy:', energy)
  51. print('atom_energy:', atom_ener)