Skip to content

Commit

Permalink
Merge pull request #138 from DARMA-tasking/135-change-method-to-find-…
Browse files Browse the repository at this point in the history
…json-files

#135: Add file name expression matching
  • Loading branch information
lifflander authored Feb 3, 2025
2 parents 352c162 + 6b25fda commit 49ebd88
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 6 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,57 @@ A YAML configuration exemplar can be found in `${VTTV_SOURCE_DIR}/config/conf.ya
${VTTV_BUILD_DIR}/apps/vt_standalone -c config/conf.yaml
```

The following is a complete description of possible keys that can be used in a configuration file:

```yaml
input:
# Directory containing the input data files
directory: data/lb_test_data
# (Optional) Stem of the data file names. Default is "data"
data_file_stem: data
# Number of ranks (data files) expected
n_ranks: 4

viz:
# Number of ranks along the X-axis
x_ranks: 2
# Number of ranks along the Y-axis
y_ranks: 2
# (Optional) Number of ranks along the Z-axis. Default is 1
z_ranks: 1
# (Optional) Adds jitter to the object positions. Default is 0.5
object_jitter: 0.5
# (Optional) Quantity of interest for ranks. Default is "load"
rank_qoi: load
# (Optional) Quantity of interest for objects. Default is "load"
object_qoi: load
# (Optional) Enable or disable saving of 3D meshes. Default is true
save_meshes: true
# (Optional) Enable or disable saving of PNG visualizations. Default is true
save_pngs: true
# (Optional) Force continuous quantities of interest for objects. Default is true
force_continuous_object_qoi: true

output:
# (Optional) Directory for saving output files. Default is "output"
directory: output
# (Optional) Base name for output files. Default is "vttv"
file_stem: lb_test
# (Optional) Visualization window size in pixels. Default is 2000
window_size: 2000
# (Optional) Font size for visualizations. Default is 2.5% of the window size
font_size: 50
```
**Additional Notes:**
- Output Directory:
The directory specified in `output.directory` must already exist. If it does not, `vt-tv` will fail during runtime.

- Validation:
The number of files matching the pattern `input.data_file_stem.[integer].json` (with `[integer]` indicating the rank the file was generated for) in the `input.directory` must match the value of `input.n_ranks`.
The product of `viz.x_ranks`, `viz.y_ranks`, and `viz.z_ranks` must equal `input.n_ranks`.

#### JSON Data Files

Sample JSON data files are provided in `${VTTV_SOURCE_DIR}/tests/unit/lb_test_data`.
Expand Down
51 changes: 51 additions & 0 deletions docs/md/mainpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,57 @@ A YAML configuration exemplar can be found in `${VTTV_SOURCE_DIR}/config/conf.ya
${VTTV_BUILD_DIR}/apps/vt_standalone -c config/conf.yaml
```

The following is a complete description of possible keys that can be used in a configuration file:

```yaml
input:
# Directory containing the input data files
directory: data/lb_test_data
# (Optional) Stem of the data file names. Default is "data"
data_file_stem: data
# Number of ranks (data files) expected
n_ranks: 4

viz:
# Number of ranks along the X-axis
x_ranks: 2
# Number of ranks along the Y-axis
y_ranks: 2
# (Optional) Number of ranks along the Z-axis. Default is 1
z_ranks: 1
# (Optional) Adds jitter to the object positions. Default is 0.5
object_jitter: 0.5
# (Optional) Quantity of interest for ranks. Default is "load"
rank_qoi: load
# (Optional) Quantity of interest for objects. Default is "load"
object_qoi: load
# (Optional) Enable or disable saving of 3D meshes. Default is true
save_meshes: true
# (Optional) Enable or disable saving of PNG visualizations. Default is true
save_pngs: true
# (Optional) Force continuous quantities of interest for objects. Default is true
force_continuous_object_qoi: true

output:
# (Optional) Directory for saving output files. Default is "output"
directory: output
# (Optional) Base name for output files. Default is "vttv"
file_stem: lb_test
# (Optional) Visualization window size in pixels. Default is 2000
window_size: 2000
# (Optional) Font size for visualizations. Default is 2.5% of the window size
font_size: 50
```
**Additional Notes:**
- Output Directory:
The directory specified in `output.directory` must already exist. If it does not, `vt-tv` will fail during runtime.

- Validation:
The number of files matching the pattern `input.data_file_stem.[integer].json` (with `[integer]` indicating the rank the file was generated for) in the `input.directory` must match the value of `input.n_ranks`.
The product of `viz.x_ranks`, `viz.y_ranks`, and `viz.z_ranks` must equal `input.n_ranks`.

#### JSON Data Files

Sample JSON data files are provided in `${VTTV_SOURCE_DIR}/tests/unit/lb_test_data`.
Expand Down
42 changes: 36 additions & 6 deletions src/vt-tv/utility/parse_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "vt-tv/api/info.h"

#include <filesystem>
#include <regex>

namespace vt::tv::utility {

Expand All @@ -58,6 +59,7 @@ void ParseRender::parseAndRender(

if (info == nullptr) {
std::string input_dir = config["input"]["directory"].as<std::string>();
std::string data_file_stem = config["input"]["file_stem"].as<std::string>("data");
std::filesystem::path input_path(input_dir);

// If it's a relative path, prepend the SRC_DIR
Expand All @@ -77,8 +79,35 @@ void ParseRender::parseAndRender(

// Collect all file paths into a vector
std::vector<std::filesystem::path> data_files;
std::regex pattern(data_file_stem + R"(\.\d+\.json(\.br)?)");

for (const auto& entry : std::filesystem::directory_iterator(input_dir)) {
data_files.push_back(entry.path());
if (entry.is_regular_file()) {
const std::string filename = entry.path().filename().string();
if (std::regex_match(filename, pattern)) {
data_files.push_back(entry.path());
}
}
}

std::size_t n_ranks = config["input"]["n_ranks"].as<std::size_t>();
std::size_t x_ranks = config["viz"]["x_ranks"].as<std::size_t>();
std::size_t y_ranks = config["viz"]["y_ranks"].as<std::size_t>();
std::size_t z_ranks = config["viz"]["z_ranks"].as<std::size_t>(1);

std::size_t expected_ranks = x_ranks * y_ranks * z_ranks;

// Validate the number of files matches n_ranks and expected_ranks
if (data_files.size() != n_ranks) {
throw std::runtime_error(
"Number of data files (" + std::to_string(data_files.size()) +
") does not match the specified n_ranks (" + std::to_string(n_ranks) + ").");
}

if (n_ranks != expected_ranks) {
throw std::runtime_error(
"n_ranks (" + std::to_string(n_ranks) + ") does not match the product of x_ranks, y_ranks, and z_ranks (" +
std::to_string(expected_ranks) + ").");
}

info = std::make_unique<Info>();
Expand All @@ -105,9 +134,8 @@ void ParseRender::parseAndRender(
utility::JSONReader reader{static_cast<NodeType>(rank)};

// Validate the JSON data file
std::string data_file_path = input_dir + "data." + std::to_string(rank) + ".json";
if (reader.validate_datafile(data_file_path)) {
reader.readFile(data_file_path);
if (reader.validate_datafile(filepath)) {
reader.readFile(filepath);
auto tmpInfo = reader.parse();

#if VT_TV_OPENMP_ENABLED
Expand All @@ -116,13 +144,14 @@ void ParseRender::parseAndRender(
{ info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank)); }

} else {
throw std::runtime_error("JSON data file is invalid: " + data_file_path);
throw std::runtime_error("JSON data file is invalid: " + filepath);
}
}
std::size_t n_ranks = config["input"]["n_ranks"].as<std::size_t>();

if (info->getNumRanks() != n_ranks) {
throw std::runtime_error("Number of ranks does not match expected value.");
}

fmt::print("Num ranks={}\n", info->getNumRanks());
}

Expand Down Expand Up @@ -206,4 +235,5 @@ void ParseRender::parseAndRender(
}
}


} /* end namespace vt::tv::utility */

0 comments on commit 49ebd88

Please sign in to comment.