Skip to content

Commit

Permalink
Refs #22027: Remove Orchestrator auxiliar methods
Browse files Browse the repository at this point in the history
Signed-off-by: eProsima <[email protected]>
  • Loading branch information
JesusPoderoso committed Nov 4, 2024
1 parent 9c23d4c commit 70ff356
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 196 deletions.
14 changes: 0 additions & 14 deletions include/sustainml/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <QWaitCondition>

#include <sustainml_cpp/core/Constants.hpp>
#include <sustainml_cpp/orchestrator/OrchestratorNode.hpp>
#include <sustainml_cpp/types/types.hpp>

class Engine : public QQmlApplicationEngine
Expand Down Expand Up @@ -139,10 +138,6 @@ private slots:
sustainml::NodeID get_node_from_json(
const QJsonObject& json);

QString get_task_from_data(
const sustainml::NodeID& id,
void* data);

QString get_task_from_json(
const QJsonObject& json);

Expand All @@ -153,21 +148,12 @@ private slots:
const types::TaskId& task_id);

QString get_raw_output(
const sustainml::NodeID& id,
void* data);

QString get_raw_output_json(
const QJsonObject& json);

QString update_node_status(
const sustainml::NodeID& id,
const types::NodeStatus& status);

size_t split_string(
const std::string& string,
std::vector<std::string>& string_set,
char delimeter);

size_t split_string(
const std::string& string,
QJsonArray& string_array,
Expand Down
184 changes: 2 additions & 182 deletions src/cpp/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include <sustainml/Engine.h>

#include <sustainml_cpp/orchestrator/OrchestratorNode.hpp>
#include <sustainml_cpp/types/types.hpp>

#define PRINT_STATUS_LOG false
Expand Down Expand Up @@ -250,46 +249,6 @@ sustainml::NodeID Engine::get_node_from_json(
}
}

QString Engine::get_task_from_data(
const sustainml::NodeID& id,
void* data)
{
types::AppRequirements* requirements = nullptr;
types::CO2Footprint* carbon = nullptr;
types::HWConstraints* hw_constraints = nullptr;
types::HWResource* hw_resources = nullptr;
types::MLModel* model = nullptr;
types::MLModelMetadata* metadata = nullptr;
types::UserInput* input = nullptr;

switch (id)
{
case sustainml::NodeID::ID_APP_REQUIREMENTS:
requirements = static_cast<types::AppRequirements*>(data);
return get_task_QString(requirements->task_id());
case sustainml::NodeID::ID_CARBON_FOOTPRINT:
carbon = static_cast<types::CO2Footprint*>(data);
return get_task_QString(carbon->task_id());
case sustainml::NodeID::ID_HW_CONSTRAINTS:
hw_constraints = static_cast<types::HWConstraints*>(data);
return get_task_QString(hw_constraints->task_id());
case sustainml::NodeID::ID_HW_RESOURCES:
hw_resources = static_cast<types::HWResource*>(data);
return get_task_QString(hw_resources->task_id());
case sustainml::NodeID::ID_ML_MODEL:
model = static_cast<types::MLModel*>(data);
return get_task_QString(model->task_id());
case sustainml::NodeID::ID_ML_MODEL_METADATA:
metadata = static_cast<types::MLModelMetadata*>(data);
return get_task_QString(metadata->task_id());
case sustainml::NodeID::ID_ORCHESTRATOR:
input = static_cast<types::UserInput*>(data);
return get_task_QString(input->task_id());
default:
return QString("UNKNOWN");
}
}

QString Engine::get_task_from_json(
const QJsonObject& json)
{
Expand Down Expand Up @@ -334,123 +293,6 @@ QString Engine::get_task_QString(
}

QString Engine::get_raw_output(
const sustainml::NodeID& id,
void* data)
{
QString output = "";
types::AppRequirements* requirements = nullptr;
types::CO2Footprint* carbon = nullptr;
types::HWConstraints* hw_constraints = nullptr;
types::HWResource* hw_resources = nullptr;
types::MLModel* model = nullptr;
types::MLModelMetadata* metadata = nullptr;
types::UserInput* input = nullptr;

switch (id)
{
case sustainml::NodeID::ID_APP_REQUIREMENTS:
requirements = static_cast<types::AppRequirements*>(data);
output += "App requirements: ";
for (std::string req : requirements->app_requirements())
{
output += QString::fromStdString(req) + QString(", ");
}
output += "\n";
return output;
case sustainml::NodeID::ID_CARBON_FOOTPRINT:
carbon = static_cast<types::CO2Footprint*>(data);
output += QString("Carbon footprint: ") + QString::number(carbon->carbon_footprint()) + QString("\n");
output += QString("Energy consumption: ") + QString::number(carbon->energy_consumption()) + QString("\n");
output += QString("Carbon intensity: ") + QString::number(carbon->carbon_intensity()) + QString("\n");
return output;
case sustainml::NodeID::ID_HW_CONSTRAINTS:
hw_constraints = static_cast<types::HWConstraints*>(data);
output += QString("Max memory footprint: ") + QString::number(hw_constraints->max_memory_footprint()) +
QString("\n");
output += "Hardware required: ";
for (std::string hw_req : hw_constraints->hardware_required())
{
output += QString::fromStdString(hw_req) + QString(", ");
}
output += QString("\n");
return output;
case sustainml::NodeID::ID_HW_RESOURCES:
hw_resources = static_cast<types::HWResource*>(data);
output += QString("Hardware description: ") +
QString::fromStdString(hw_resources->hw_description()) + QString("\n");
output += QString("Power consumption: ") +
QString::number(hw_resources->power_consumption()) + QString("\n");
output += QString("Latency: ") + QString::number(hw_resources->latency()) + QString("\n");
output += QString("Model memory footprint: ") +
QString::number(hw_resources->memory_footprint_of_ml_model()) + QString("\n");
output += QString("Max hardware memory footprint: ") +
QString::number(hw_resources->max_hw_memory_footprint()) + QString("\n");
return output;
case sustainml::NodeID::ID_ML_MODEL:
model = static_cast<types::MLModel*>(data);
output += QString("Model path: ") + QString::fromStdString(model->model_path()) + QString("\n");
output += QString("Model: ") + QString::fromStdString(model->model()) + QString("\n");
output += QString("Model properties path: ") +
QString::fromStdString(model->model_properties_path()) + QString("\n");
output += QString("Model properties: ") + QString::fromStdString(model->model_properties()) + QString("\n");
output += "Input batch: ";
for (std::string input : model->input_batch())
{
output += QString::fromStdString(input) + QString(", ");
}
output += QString("\nTarget latency: ") + QString::number(model->target_latency()) + QString("\n");
return output;
case sustainml::NodeID::ID_ML_MODEL_METADATA:
metadata = static_cast<types::MLModelMetadata*>(data);
output += "Key words: ";
for (std::string keyword : metadata->keywords())
{
output += QString::fromStdString(keyword) + QString(", ");
}
output += "\nMetadata: ";
for (std::string meta : metadata->ml_model_metadata())
{
output += QString::fromStdString(meta) + QString(", ");
}
output += "\n";
return output;
case sustainml::NodeID::ID_ORCHESTRATOR:
input = static_cast<types::UserInput*>(data);
output += QString("Problem short description: ") +
QString::fromStdString(input->problem_short_description()) + QString("\n");
output += QString("Problem definition: ") +
QString::fromStdString(input->problem_definition()) + QString("\n");
output += QString("Modality: ") + QString::fromStdString(input->modality()) + QString("\n");
output += QString("Inputs: ");
for (std::string in : input->inputs())
{
output += QString::fromStdString(in) + QString(", ");
}
output += "\nOutputs: ";
for (std::string out : input->outputs())
{
output += QString::fromStdString(out) + QString(", ");
}
output += QString("\nMin samples: ") + QString::number(input->minimum_samples()) + QString("\n");
output += QString("Max samples: ") + QString::number(input->maximum_samples()) + QString("\n");
output += QString("Optimize automatically: ") +
(input->optimize_carbon_footprint_auto() ? QString("true\n") : QString("false\n"));
output += QString("Optimize manually: ") +
(input->optimize_carbon_footprint_manual() ? QString("true\n") : QString("false\n"));
output += QString("Previous iteration: ") + QString::number(input->previous_iteration()) + QString("\n");
output += QString("Desired carbon footprint: ") +
QString::number(input->desired_carbon_footprint()) + QString("\n");
output += QString("Geo location continent: ") +
QString::fromStdString(input->geo_location_continent()) + QString("\n");
output += QString("Geo location region: ") +
QString::fromStdString(input->geo_location_region()) + QString("\n");
return output;
default:
return QString("Unknown node output\n");
}
}

QString Engine::get_raw_output_json(
const QJsonObject& json_obj)
{
QString output = "";
Expand Down Expand Up @@ -553,27 +395,6 @@ QString Engine::update_node_status(
return status_value;
}

size_t Engine::split_string(
const std::string& string,
std::vector<std::string>& string_set,
char delimeter)
{
size_t position = string.find(delimeter);
size_t initial_position = 0;
string_set.clear();

// Split loop
while (position != std::string::npos)
{
string_set.push_back(string.substr(initial_position, position - initial_position));
initial_position = position + 1;
position = string.find(delimeter, initial_position);
}
string_set.push_back(string.substr(initial_position, std::min(position, string.size()) - initial_position + 1));

return string_set.size();
}

size_t Engine::split_string(
const std::string& string,
QJsonArray& string_array,
Expand Down Expand Up @@ -616,9 +437,8 @@ void Engine::node_response(
if (!json_obj.empty())
{
QString name = get_name_from_node_id(get_node_from_json(json_obj));
emit update_log(QString("Output received. Task ") + get_task_from_json(json_obj[name].toObject()) +
(",\tnode ") +
name + ":\n" + get_raw_output_json(json_obj));
emit update_log(QString("Output received. ") + get_task_from_json(json_obj[name].toObject()) +
(",\tnode ") + name + ":\n" + get_raw_output(json_obj));
}
reply_->deleteLater();
}

0 comments on commit 70ff356

Please sign in to comment.