Skip to content

Commit

Permalink
Merge pull request #66 from DARMA-tasking/65-fix-reading-of-user-defi…
Browse files Browse the repository at this point in the history
…ned-field

#65: Fix reading of `user_defined` field from JSON file.
  • Loading branch information
thearusable authored Apr 2, 2024
2 parents 034e7bf + 584246c commit 4ea6a17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/vt-tv/api/object_work.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ namespace vt::tv {
* \brief Holds work for an object for a given phase
*/
struct ObjectWork {
/// Possible user-defined types for a task
using VariantType = std::variant<int, double, std::string>;

ObjectWork() = default;

Expand All @@ -77,7 +75,7 @@ struct ObjectWork {
ElementIDType in_id,
TimeType in_whole_phase_load,
std::unordered_map<SubphaseType, TimeType> in_subphase_loads,
std::unordered_map<std::string, VariantType> in_user_defined = {},
std::unordered_map<std::string, QOIVariantTypes> in_user_defined = {},
std::unordered_map<std::string, QOIVariantTypes> in_attributes = {}
) : id_(in_id),
whole_phase_load_(in_whole_phase_load),
Expand Down Expand Up @@ -194,7 +192,7 @@ struct ObjectWork {
/// Load broken down into subphases
std::unordered_map<SubphaseType, TimeType> subphase_loads_;
// User-defined field---used to populate the memory block
std::unordered_map<std::string, VariantType> user_defined_;
std::unordered_map<std::string, QOIVariantTypes> user_defined_;
/// QOIs to be visualized
std::unordered_map<std::string, QOIVariantTypes> attributes_;

Expand Down
6 changes: 3 additions & 3 deletions src/vt-tv/utility/json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ std::unique_ptr<Info> JSONReader::parseFile() {
}
}

std::unordered_map<std::string, ObjectWork::VariantType> user_defined;
std::unordered_map<std::string, QOIVariantTypes> readed_user_defined;
if (task.find("user_defined") != task.end()) {
auto user_defined = task["user_defined"];
if (user_defined.is_object()) {
for (auto& [key, value] : user_defined.items()) {
user_defined[key] = value;
readed_user_defined[key] = value;
}
}
}
Expand All @@ -201,7 +201,7 @@ std::unique_ptr<Info> JSONReader::parseFile() {
objects.try_emplace(
object,
ObjectWork{
object, time, std::move(subphase_loads), std::move(user_defined), std::move(readed_metadata)
object, time, std::move(subphase_loads), std::move(readed_user_defined), std::move(readed_metadata)
}
);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,25 @@ TEST_F(TestJSONReader, test_json_reader_qoi_serializer) {
EXPECT_EQ("some data", std::get<std::string>(string_variant));
}

TEST_F(TestJSONReader, test_json_reader_object_work_user_defined) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "tests/unit/lb_test_data" ;
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
utility::JSONReader reader{rank, path + "/reader_test_data.json"};

reader.readFile();
auto info = reader.parseFile();
auto& rank_info = info->getRank(rank);
EXPECT_EQ(rank_info.getRankID(), rank);

auto const& objects = info->getRankObjects(0, 0);
auto const& object_info = objects.at(3407875);

auto& user_defined = object_info.getUserDefined();
EXPECT_FALSE(user_defined.empty());
EXPECT_TRUE(user_defined.find("isSample") != user_defined.end());
EXPECT_EQ(1, std::get<int>(user_defined.at("isSample")));
}

} // end namespace vt::tv::tests::unit

0 comments on commit 4ea6a17

Please sign in to comment.