Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#209] Link Creation Agent support to list of templates #285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ run-link-creation-agent:
run-link-creation-client:
@bash -x src/scripts/run.sh link_creation_agent_client $(OPTIONS)

run-inference-agent:
@bash -x src/scripts/run.sh inference_agent_server $(OPTIONS)

run-inference-agent-client:
@bash -x src/scripts/run.sh inference_agent_client $(OPTIONS)

setup-nunet-dms:
@bash -x src/scripts/setup-nunet-dms.sh

Expand Down
11 changes: 11 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,14 @@ cc_binary(
"//main:inference_agent_main_lib",
],
)


cc_binary(
name = "inference_agent_client",
srcs = [],
defines = ["BAZEL_BUILD"],
linkstatic = 1,
deps = [
"//main:inference_agent_client_main_lib",
],
)
7 changes: 4 additions & 3 deletions src/inference_agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ PROOF_OF_IMPLICATION_OR_EQUIVALENCE "handle1" "handle2" "10"
## Build

```
make build
make build-all
```

## Run
## Run Server

```
inference_agent --config_file <config_path>
make run-inference-agent OPTIONS="path_to_config_file"
```

## Config
Expand Down Expand Up @@ -64,3 +64,4 @@ distributed_inference_control_node_id = "localhost:8085"
distributed_inference_control_node_server_id = "localhost:8086"
```


21 changes: 11 additions & 10 deletions src/inference_agent/inference_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,17 @@ std::vector<std::vector<std::string>> ProofOfImplicationOrEquivalence::get_reque
query_and_link_creation_template.push_back(token);
}
requests.push_back(query_and_link_creation_template);
// proof of implication
ProofOfImplication proof_of_implication(first_handle, second_handle, max_proof_length);
for (auto request : proof_of_implication.get_requests()) {
requests.push_back(request);
}
// proof of equivalence
ProofOfEquivalence proof_of_equivalence(first_handle, second_handle, max_proof_length);
for (auto request : proof_of_equivalence.get_requests()) {
requests.push_back(request);
}
// Not supported yet
// // proof of implication
// ProofOfImplication proof_of_implication(first_handle, second_handle, max_proof_length);
// for (auto request : proof_of_implication.get_requests()) {
// requests.push_back(request);
// }
// // proof of equivalence
// ProofOfEquivalence proof_of_equivalence(first_handle, second_handle, max_proof_length);
// for (auto request : proof_of_equivalence.get_requests()) {
// requests.push_back(request);
// }

return requests;
}
Expand Down
3 changes: 2 additions & 1 deletion src/link_creation_agent/das_agent_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DasAgentNode::~DasAgentNode() { DistributedAlgorithmNode::graceful_shutdown(); }
void DasAgentNode::create_link(vector<string>& request) {
cout << "Creating link" << endl;
for (string token : request) {
cout << token << endl;
cout << token << " ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only cout? Maybe you missed a TODO: here as a reminder to implement the actual feature?

}
cout << endl;
}
26 changes: 25 additions & 1 deletion src/link_creation_agent/link_create_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,28 @@ std::string CustomField::to_string() {
return custom_field;
}

std::vector<std::string> CustomField::tokenize() { return split(this->to_string(), ' '); }
std::vector<std::string> CustomField::tokenize() { return split(this->to_string(), ' '); }


LinkCreateTemplateList::LinkCreateTemplateList(std::vector<std::string> link_template) {
if (get_token(link_template, 0) != "LIST")
throw std::invalid_argument("Can not create Link Template List: Invalid arguments");

size_t cursor = 0;
int link_template_size = string_to_int(get_token(link_template, 1));
cursor += 2;
for (int i = 0; i < link_template_size; i++) {
std::vector<std::string> sub_link_template = parse_sub_link_template(link_template, cursor);
this->templates.push_back(LinkCreateTemplate(sub_link_template));
}
if (this->templates.size() != link_template_size) {
throw std::invalid_argument("Can not create Link Template List: Invalid arguments");
}
}


LinkCreateTemplateList::~LinkCreateTemplateList() {}

std::vector<LinkCreateTemplate> LinkCreateTemplateList::get_templates() {
return this->templates;
}
11 changes: 11 additions & 0 deletions src/link_creation_agent/link_create_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,21 @@ class LinkCreateTemplate {
*/
void add_custom_field(CustomField custom_field);


private:
std::string link_type;
std::vector<LinkCreateTemplateTypes> targets;
std::vector<CustomField> custom_fields;
};

class LinkCreateTemplateList {
public:
LinkCreateTemplateList(std::vector<std::string> link_template);
~LinkCreateTemplateList();
std::vector<LinkCreateTemplate> get_templates();

private:
std::vector<LinkCreateTemplate> templates;
};

} // namespace link_creation_agent
23 changes: 21 additions & 2 deletions src/link_creation_agent/link_creation_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,23 @@ void LinkCreationAgent::load_buffer() {
file.close();
}

static bool is_link_template_arg(string arg) {
if (arg == "LIST") return true;
if (arg == "LINK_CREATE") return true;
if (arg == "PROOF_OF_IMPLICATION_OR_EQUIVALENCE") return true;
if (arg == "PROOF_OF_IMPLICATION") return true;
if (arg == "PROOF_OF_EQUIVALENCE") return true;
return false;
}

shared_ptr<LinkCreationAgentRequest> LinkCreationAgent::create_request(vector<string> request) {
try {
LinkCreationAgentRequest* lca_request = new LinkCreationAgentRequest();
int cursor = 0;
bool is_link_create = false;
for (string arg : request) {
cursor++;
is_link_create = (arg == "LINK_CREATE") || is_link_create;
is_link_create = is_link_template_arg(arg) || is_link_create;
if (!is_link_create) {
lca_request->query.push_back(arg);
}
Expand All @@ -186,10 +195,20 @@ shared_ptr<LinkCreationAgentRequest> LinkCreationAgent::create_request(vector<st
}
}
lca_request->infinite = (lca_request->repeat == -1);
string joined_string = Utils::join(lca_request->query, ' ') + Utils::join(lca_request->link_template, ' ');
string joined_string = Utils::join(lca_request->query, ' ') + Utils::join(lca_request->link_template, ' ') + lca_request->context;
shared_ptr<char> joined_string_c = shared_ptr<char>(new char[joined_string.size() + 1]);
strcpy(joined_string_c.get(), joined_string.c_str());
lca_request->id = string(compute_hash(joined_string_c.get()));
// couts
cout << "Query: " << Utils::join(lca_request->query, ' ') << endl;
cout << "Link Template: " << Utils::join(lca_request->link_template, ' ') << endl;
cout << "Max Results: " << lca_request->max_results << endl;
cout << "Repeat: " << lca_request->repeat << endl;
cout << "Context: " << lca_request->context << endl;
cout << "Update Attention Broker: " << lca_request->update_attention_broker << endl;
cout << "Infinite: " << lca_request->infinite << endl;
cout << "ID: " << lca_request->id << endl;

return shared_ptr<LinkCreationAgentRequest>(lca_request);
} catch (exception& e) {
cout << "Error parsing request: " << e.what() << endl;
Expand Down
12 changes: 10 additions & 2 deletions src/link_creation_agent/servive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ void LinkCreationService::process_request(shared_ptr<RemoteIterator<HandlesAnswe
Utils::sleep();
} else {
cout << "LinkCreationService::process_request: Processing query_answer" << endl;
Link link(query_answer, link_template);
this->create_link(link, *das_client);
if (link_template.front() == "LIST") {
LinkCreateTemplateList link_create_template_list(link_template);
for(auto link_template : link_create_template_list.get_templates()){
Link link(query_answer, link_template.tokenize());
this->create_link(link, *das_client);
}
}else{
Link link(query_answer, link_template);
this->create_link(link, *das_client);
}
delete query_answer;
if (++count == max_query_answers) break;
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ cc_library(

],
)


cc_library(
name = "inference_agent_client_main_lib",
srcs = ["inference_agent_client_main.cc"],
deps = [
"//inference_agent:inference_agent_lib",

],
)
46 changes: 46 additions & 0 deletions src/main/inference_agent_client_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <signal.h>

#include <cstring>
#include <iostream>
#include <string>

#include "inference_agent_node.h"

using namespace inference_agent;
using namespace std;

void ctrl_c_handler(int) {
std::cout << "Stopping client..." << std::endl;
std::cout << "Done." << std::endl;
exit(0);
}

int main(int argc, char* argv[]) {
string help = R""""(
Usage: inference_agent CLIENT_HOST:CLIENT_PORT SERVER_HOST:SERVER_PORT REQUEST+
Requests must be in the following format:
PROOF_OF_IMPLICATION_OR_EQUIVALENCE <handle1> <handle2> <max proof length>
PROOF_OF_IMPLICATION <handle1> <handle2> <max proof length>
PROOF_OF_EQUIVALENCE <handle1> <handle2> <max proof length>

)"""";

if (argc < 4) {
cerr << help << endl;
exit(1);
}

string client_id = string(argv[1]);
string server_id = string(argv[2]);

vector<string> request;
for (int i = 3; i < argc; i++) {
request.push_back(argv[i]);
}
signal(SIGINT, &ctrl_c_handler);
string config_path = argv[2];
cout << "Starting inference agent" << endl;
auto client = new InferenceAgentNode(client_id, server_id);
client->send_message(request);
return 0;
}
2 changes: 1 addition & 1 deletion src/main/inference_agent_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) {
}
signal(SIGINT, &ctrl_c_handler);
string config_path = argv[2];
cout << "Starting inference agent" << endl;
cout << "Starting inference agent server" << endl;
auto server = new InferenceAgent(config_path);
server->run();
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/bazel_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fi
if [ "$BUILD_BINARIES" = true ]; then
$BAZELISK_BUILD_CMD //:inference_agent_server
mv bazel-bin/inference_agent_server "$BIN_DIR"
$BAZELISK_BUILD_CMD //:inference_agent_client
mv bazel-bin/inference_agent_client "$BIN_DIR"
$BAZELISK_BUILD_CMD //:link_creation_server
mv bazel-bin/link_creation_server "$BIN_DIR"
$BAZELISK_BUILD_CMD //:link_creation_agent_client
Expand Down