PURIFY
Next-generation radio interferometric imaging
mpi_read_measurements.cc
Go to the documentation of this file.
1 #include "purify/config.h"
2 #include "purify/types.h"
3 #include "catch2/catch_all.hpp"
4 #include "purify/logging.h"
5 
6 #include "purify/directories.h"
8 #include "purify/utilities.h"
9 #include <sopt/gradient_utils.h>
10 #ifdef PURIFY_H5
11 #include "purify/h5reader.h"
13 #endif
14 
15 using namespace purify;
16 
17 TEST_CASE("uvfits") {
18  auto const comm = sopt::mpi::Communicator::World();
19  const std::string filename = atca_filename("0332-391");
20  SECTION("one") {
21  SECTION("uvfits") {
22  const auto uvfits = read_measurements::read_measurements(filename + ".uvfits", comm);
23  CAPTURE(comm.rank());
24  CHECK(comm.all_sum_all(uvfits.size()) == 245886);
25  }
26  SECTION("vis") {
27  const auto vis =
30  CAPTURE(comm.rank());
31  CHECK(comm.all_sum_all(vis.size()) == 245886);
33  }
34  }
35  SECTION("two") {
36  SECTION("uvfits") {
37  const auto uvfits = read_measurements::read_measurements(
38  std::vector<std::string>{filename + ".uvfits", filename + ".uvfits"}, comm);
39  CAPTURE(comm.rank());
40  CHECK(comm.all_sum_all(uvfits.size()) == 245886 * 2);
41  }
42  SECTION("vis") {
43  const auto vis = read_measurements::read_measurements(
44  std::vector<std::string>{filename + ".vis", filename + ".vis"}, comm);
45  CAPTURE(comm.rank());
46  CHECK(comm.all_sum_all(vis.size()) == 245886 * 2);
47  CHECK(vis.units == utilities::vis_units::lambda);
48  }
49  }
50  SECTION("ms") {
51  SECTION("one") {
52 #ifdef PURIFY_CASACORE
53  const auto ms = read_measurements::read_measurements(filename + ".ms", comm);
54  CAPTURE(comm.rank());
55  CHECK(comm.all_sum_all(ms.size()) == 245994);
56 #endif
57  }
58  SECTION("two") {
59 #ifdef PURIFY_CASACORE
61  std::vector<std::string>{filename + ".ms", filename + ".ms"}, comm);
62  CAPTURE(comm.rank());
63  CHECK(comm.all_sum_all(ms.size()) == 245994 * 2);
64 #endif
65  }
66  }
67 #ifdef PURIFY_H5
68  SECTION("H5") {
69  SECTION("one") {
70  // each rank reads the full file
71  H5::H5Handler f(filename + ".h5");
72  const std::vector<double> u = f.read("u");
73  CAPTURE(u.size());
74  // total size is Nranks * data length
75  CHECK(comm.all_sum_all(u.size()) == 245886 * comm.size());
76  }
77  SECTION("two") {
78  // each rank reads an evenly distributed slice of the data set
79  H5::H5Handler f(filename + ".h5", comm);
80  const std::vector<double> u = f.distread("u");
81  CAPTURE(u.size());
82  // total size is the data length
83  CHECK(comm.all_sum_all(u.size()) == 245886);
84  }
85  SECTION("three") {
86  // Root rank reads the data and scatters evenly split slices
87  const auto uvfits = read_measurements::read_measurements(filename + ".h5", comm);
88  CAPTURE(uvfits.size());
89  CHECK(comm.all_sum_all(uvfits.size()) == 245886);
90  }
91  SECTION("four") {
92  // each rank reads a stochastically sampled set of 10k dataset members
93  // @todo account for w-stacking
94  const size_t N = 10000;
95  H5::H5Handler f(filename + ".h5", comm);
96  const std::vector<double> u = f.stochread("u", N);
97  CAPTURE(u.size());
98  // total size is the data length
99  CHECK(comm.all_sum_all(u.size()) == N * comm.size());
100  }
101  SECTION("five") {
102  // each rank reads a stochastically sampled set of 10k dataset members
103  // and constructs a uv_params object from it
104  // @todo account for w-stacking
105  const size_t N = 10000;
106  H5::H5Handler f(filename + ".h5", comm);
107  const auto uvfits = H5::stochread_visibility(f, N, true); //< true = include w-term
108  CAPTURE(uvfits.size());
109  CHECK(comm.all_sum_all(uvfits.size()) == N * comm.size());
110  }
111  SECTION("six") {
112  // a functor is used to read a stochastically sampled set of 10k dataset members
113  // on each rank and to constructs a uv_params object from it, along with a measurement
114  // operator which are then returned, wrapped in a sopt::IterationState object
115  // @todo account for w-stacking
116  const size_t N = 10000;
117  H5::H5Handler h5file(filename + ".h5", comm);
118  using t_complexVec = Vector<t_complex>;
119 
120  // This functor would be defined in Purify
121  auto functor = [&f = h5file, &N]() {
122  utilities::vis_params uv_data = H5::stochread_visibility(f, N, true);
123  auto phi = factory::measurement_operator_factory<t_complexVec>(
125  1, 2, kernels::kernel_from_string.at("kb"), 4, 4);
126 
127  return sopt::IterationState<t_complexVec>(uv_data.vis, phi);
128  };
129 
130  // And it would be called in Sopt like this
131  sopt::IterationState<t_complexVec> item = functor();
132 
133  // Make sure the return values are sensible
134  const bool pass = comm.all_sum_all(item.target().size()) == N * comm.size() &&
135  item.Phi().sizes()[0] == 0 && item.Phi().sizes()[1] == 1 &&
136  item.Phi().sizes()[2] == N;
137  CHECK(pass);
138  }
139  }
140 #endif
141 }
#define CHECK(CONDITION, ERROR)
Definition: casa.cc:6
Purify interface class to handle HDF5 input files.
Definition: h5reader.h:48
std::vector< T > read(const std::string &label) const
Method to read the entire dataset.
Definition: h5reader.h:76
std::vector< T > distread(const std::string &label)
Definition: h5reader.h:84
std::vector< T > stochread(const std::string &label, size_t batchsize, bool shuffle=false)
Definition: h5reader.h:96
TEST_CASE("uvfits")
const std::vector< t_real > u
data for u coordinate
Definition: operators.cc:18
utilities::vis_params stochread_visibility(H5Handler &file, const size_t N, const bool w_term)
Stochastically reads dataset slices from the supplied HDF5-file handler, constructs a vis_params obje...
Definition: h5reader.h:206
const std::map< std::string, kernel > kernel_from_string
Definition: kernels.h:16
utilities::vis_params read_measurements(const std::string &name, const bool w_term, const stokes pol, const utilities::vis_units units)
read in single measurement file
std::string atca_filename(std::string const &filename)
Specific atca data.
Vector< t_complex > vis
Definition: uvw_utilities.h:22