LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
data_reader_pilot2_molecular.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
25 //
26 // data_reader_pilot2_molecular .hpp .cpp - data reader for Pilot 2 molecular
27 // data
29 
30 #ifndef LBANN_DATA_READER_PILOT2_MOLECULAR_HPP
31 #define LBANN_DATA_READER_PILOT2_MOLECULAR_HPP
32 
33 #include "data_reader.hpp"
34 #include <cnpy.h>
35 
36 namespace lbann {
37 
42 {
43 public:
44  pilot2_molecular_reader(int num_neighbors,
45  int max_neighborhood,
46  bool shuffle = true);
50  pilot2_molecular_reader* copy() const override
51  {
52  return new pilot2_molecular_reader(*this);
53  }
54  std::string get_type() const override { return "pilot2_molecular_reader"; }
55 
56  void load() override;
57 
58  int get_linearized_data_size() const override
59  {
60  return m_num_features * (m_num_neighbors + 1);
61  }
62  const std::vector<El::Int> get_data_dims() const override
63  {
64  return m_shape;
65  // return {m_num_neighbors + 1, (int) m_features.shape[2],
66  // (int) m_features.shape[3]};
67  }
68 
74  template <class T>
75  T scale_data(int idx, T datum)
76  {
77  idx = idx % 20;
78  T scaled_datum = datum;
79  if (idx >= 0 && idx <= 2) {
80  scaled_datum /= position_scale_factor;
81  }
82  if (idx >= 8 && idx <= 19) {
83  scaled_datum /= bond_len_scale_factor;
84  }
85  return scaled_datum;
86  }
87 
89  float* get_features_4() { return m_features.data<float>(); }
90  double* get_features_8() { return m_features.data<double>(); }
91  float* get_neighbors_4() { return m_neighbors.data<float>(); }
92  double* get_neighbors_8() { return m_neighbors.data<double>(); }
93 
95  int get_word_size() const { return m_word_size; }
96 
98  int get_num_neighbors() const { return m_num_neighbors; }
99 
102  int get_frame(int data_id) const { return data_id / m_num_samples_per_frame; }
103 
106 
108  int get_max_neighborhood() const { return m_max_neighborhood; }
109 
111  int get_num_features() const { return m_num_features; }
112 
115 
116 protected:
118  bool fetch_datum(CPUMat& X, int data_id, int mb_idx) override;
120  void fetch_molecule(CPUMat& X, int data_id, int idx, int mb_idx);
121 
123  int m_num_samples = 0;
125  int m_num_features = 0;
128  // Number of neighbors to fetch for each molecule.
130  // Size of the neighborhood in the data set
133  cnpy::NpyArray m_features;
135  cnpy::NpyArray m_neighbors;
136 
137  DataType position_scale_factor = 320.0;
138  DataType bond_len_scale_factor = 10.0;
139 
141  std::vector<El::Int> m_shape;
142 
146  int m_owner;
149 };
150 
151 } // namespace lbann
152 
153 #endif // LBANN_DATA_READER_PILOT2_MOLECULAR_HPP
int m_neighbors_data_size
support for data_store_pilot2_molecular
int get_neighbors_data_size()
support for data_store_pilot2_molecular
int m_word_size
support for data_store_pilot2_molecular
int m_owner
support for data_store_pilot2_molecular
int get_num_samples_per_frame() const
support for data_store_pilot2_molecular
int m_num_samples_per_frame
Number of samples in each frame (assume constant across all frames).
bool fetch_datum(CPUMat &X, int data_id, int mb_idx) override
Fetch a molecule and its neighbors.
pilot2_molecular_reader(int num_neighbors, int max_neighborhood, bool shuffle=true)
int get_num_neighbors() const
support for data_store_pilot2_molecular
cnpy::NpyArray m_features
Molecular features.
int get_linearized_data_size() const override
Get the linearized size (i.e. number of elements) in a sample.
std::vector< El::Int > m_shape
support for data_store_pilot2_molecular
int get_num_features() const
support for data_store_pilot2_molecular
int m_num_features
Number of features in each sample.
cnpy::NpyArray m_neighbors
Neighbor information (adjacency matrix).
El::Matrix< DataType, El::Device::CPU > CPUMat
Definition: base.hpp:116
int get_word_size() const
support for data_store_pilot2_molecular
const std::vector< El::Int > get_data_dims() const override
Get the dimensions of the data.
float * get_features_4()
support for data_store_pilot2_molecular
void fetch_molecule(CPUMat &X, int data_id, int idx, int mb_idx)
Fetch molecule data_id into X at molecule offset idx.
pilot2_molecular_reader * copy() const override
pilot2_molecular_reader & operator=(const pilot2_molecular_reader &)=default
int get_max_neighborhood() const
support for data_store_pilot2_molecular