Skip to content

Commit

Permalink
#16: bindings: Continue binding setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed Oct 12, 2023
1 parent da2fc51 commit 7f5337c
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 6 deletions.
9 changes: 9 additions & 0 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from setuptools import setup

setup(
name='tv',
version='0.1',
description='Virtual Transport Task Visualizer',
author='Jonathan Lifflander, Pierre Pebay',
package_data={'': ['/home/pierrelp/Develop/NGA/vt-tv/build/bindings/python/tv.cpython-38-x86_64-linux-gnu.so']}
)
147 changes: 147 additions & 0 deletions bindings/python/tv.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,155 @@
#include "tv.h"

namespace vt::tv::bindings::python {

void process_json(std::string& input) {
auto j = nlohmann::json::parse(input);
fmt::print("JSON: {}\n", j.dump(2));
// Read the json file
// using json = nlohmann::json;

// assert(j != nullptr && "Must have valid json");

// std::unordered_map<ElementIDType, ObjectInfo> object_info;
// std::unordered_map<PhaseType, PhaseWork> phase_info;

// auto phases = j["phases"];
// if (phases.is_array()) {
// for (auto const& phase : phases) {
// auto id = phase["id"];
// auto tasks = phase["tasks"];

// std::unordered_map<ElementIDType, ObjectWork> objects;

// if (tasks.is_array()) {
// for (auto const& task : tasks) {
// auto node = task["node"];
// auto time = task["time"];
// auto etype = task["entity"]["type"];
// assert(time.is_number());
// assert(node.is_number());

// if (etype == "object") {
// auto object = task["entity"]["id"];
// auto home = task["entity"]["home"];
// bool migratable = task["entity"]["migratable"];
// assert(object.is_number());
// assert(home.is_number());

// std::vector<UniqueIndexBitType> index_arr;

// if (
// task["entity"].find("collection_id") != task["entity"].end() and
// task["entity"].find("index") != task["entity"].end()
// ) {
// auto cid = task["entity"]["collection_id"];
// auto idx = task["entity"]["index"];
// if (cid.is_number() && idx.is_array()) {
// std::vector<UniqueIndexBitType> arr = idx;
// index_arr = std::move(arr);
// }
// }

// ObjectInfo oi{object, home, migratable, std::move(index_arr)};

// if (task["entity"].find("collection_id") != task["entity"].end()) {
// oi.setIsCollection(true);
// oi.setMetaID(task["entity"]["collection_id"]);
// }

// if (task["entity"].find("objgroup_id") != task["entity"].end()) {
// oi.setIsObjGroup(true);
// oi.setMetaID(task["entity"]["objgroup_id"]);
// }

// object_info.try_emplace(object, std::move(oi));

// std::unordered_map<SubphaseType, TimeType> subphase_loads;

// if (task.find("subphases") != task.end()) {
// auto subphases = task["subphases"];
// if (subphases.is_array()) {
// for (auto const& s : subphases) {
// auto sid = s["id"];
// auto stime = s["time"];

// assert(sid.is_number());
// assert(stime.is_number());

// subphase_loads[sid] = stime;
// }
// }
// }

// std::unordered_map<std::string, ObjectWork::VariantType> 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;
// }
// }
// }
// // fmt::print(" Add object {}\n", (ElementIDType)object);
// objects.try_emplace(
// object,
// ObjectWork{
// object, time, std::move(subphase_loads), std::move(user_defined)
// }
// );
// }
// }
// }

// auto communications = phase["communications"];
// if (communications.is_array()) {
// for (auto const& comm : communications) {
// auto type = comm["type"];
// if (type == "SendRecv") {
// auto bytes = comm["bytes"];
// auto messages = comm["messages"];

// auto from = comm["from"];
// auto to = comm["to"];

// ElementIDType from_id = from["id"];
// ElementIDType to_id = to["id"];

// assert(bytes.is_number());
// assert(from.is_number());
// assert(to.is_number());

// // fmt::print(" From: {}, to: {}\n", from_id, to_id);

// // Object on this rank sent data
// if (objects.find(from_id) != objects.end()) {
// objects.at(from_id).addSentCommunications(to_id, bytes);
// } else if (objects.find(to_id) != objects.end()) {
// objects.at(to_id).addReceivedCommunications(from_id, bytes);
// }
// }
// }
// }
// phase_info.try_emplace(id, PhaseWork{id, std::move(objects)});
// }
// }

// Rank r{rank_, std::move(phase_info)};

// std::unordered_map<NodeType, Rank> rank_info;
// rank_info.try_emplace(rank_, std::move(r));
// auto info = std::make_unique<Info>(std::move(object_info), std::move(rank_info));

// // Render the data
// Render render{std::move(info)};
// render.generate(2000, 2000);
}

namespace nb = nanobind;
using namespace nb::literals;

NB_MODULE(tv, m) {
m.def("process_json", &process_json);
}

} /* end namespace vt::tv::bindings::python */
18 changes: 12 additions & 6 deletions bindings/python/tv.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@
#include <string>

#include <fmt-vt/format.h>
#include "vt-tv/render/render.h"
#include "vt-tv/api/types.h"
#include "vt-tv/api/info.h"
#include "vt-tv/utility/decompression_input_container.h"
#include "vt-tv/utility/input_iterator.h"

#include <nlohmann/json.hpp>
#include <nanobind/nanobind.h>

#include <nanobind/stl/string.h>

void process_json(std::string& input) {
auto j = nlohmann::json::parse(input);
// Print the contents of the JSON object
fmt::print("JSON object: {}\n", j.dump());
}
namespace vt::tv::bindings::python {

void process_json(std::string&);

} /* end namespace vt::tv::bindings::python */

#endif /*INCLUDED_VT_TV_BINDINGS_PYTHON_JSON_INTERFACE_H*/
#endif /*INCLUDED_VT_TV_BINDINGS_PYTHON_JSON_INTERFACE_H*/

0 comments on commit 7f5337c

Please sign in to comment.