Installing Tiger graph algorithms on windows to use in Graph Studio - WCC, Jacard, Louvian etc

Unfortunately you will have to install the user defined functions as documented in the previous link I sent. This is relatively painless, and does not require C++ knowledge. These functions are required due to our core database product not having this functionality built into it. If you have more questions, let us know!

Query installation is failing for louvain, same is the case with wcc -

GSQL > INSTALL QUERY tg_louvain
Start installing queries, about 1 minute ...
tg_louvain query: curl -X GET 'http://127.0.0.1:9000/query/NetworkAnomalyDetection/tg_louvain?v_type=VALUE&e_type=VALUE&[wt_attr=VALUE]&[max_iter=VALUE]&[result_attr=VALUE]&[file_path=VALUE]&[print_info=VALUE]'. Add -H "Authorization: Bearer TOKEN" if authentication is enabled.
Select 'm1' as compile server, now connecting ...
Node 'm1' is prepared as compile server.

[===================================================================================================     ] 95% (0/1)  m1: Reload libudf Failed!
Query installation failed during linking!
Query installation failed!

@Parker_Erickson @Pawan_Mall
I folowed below steps:

  1. In CLI, went to path /home/tigergraph/tigergraph/app/3.4.0/dev/gdk/gsql/src/QueryUdf
  2. Updated ExprFunctions.hpp, added functions present in tg_fastRP.cpp. Please refer the contents of updated file below.
  3. In windows powershell, opened gsql and ran below commands
    a) GSQL > PUT ExprFunctions from “/home/tigergraph/tigergraph/app/3.4.0/dev/gdk/gsql/src/QueryUdf/ExprFunctions.hpp”
    PUT ExprFunctions successfully.
    b) USE GRAPH NetworkAnomalyDetection
    c) @tg_fastRP.gsql

Got below error -
Semantic Check Error in query tg_fastRP (SEM-45): line 34, col 13
The tuple name or the function tg_extract_list is not defined.
Failed to create queries: [tg_fastRP].

I checked the contents of updated hpp file and found that function is available there, see contents below -

#ifndef EXPRFUNCTIONS_HPP_
#define EXPRFUNCTIONS_HPP_

#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <gle/engine/cpplib/headers.hpp>


#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <gle/engine/cpplib/headers.hpp>
#include <iostream>
#include <random>
#include <sstream>
#include <string>
#include <math.h>
#include <functional>

/**     XXX Warning!! Put self-defined struct in ExprUtil.hpp **
 *  No user defined struct, helper functions (that will not be directly called
 *  in the GQuery scripts) etc. are allowed in this file. This file only
 *  contains user-defined expression function's signature and body.
 *  Please put user defined structs, helper functions etc. in ExprUtil.hpp
 */
#include "ExprUtil.hpp"

namespace UDIMPL {
  typedef std::string string; //XXX DON'T REMOVE

  /****** BIULT-IN FUNCTIONS **************/
  /****** XXX DON'T REMOVE ****************/
  inline int64_t str_to_int (string str) {
    return atoll(str.c_str());
  }

  inline int64_t float_to_int (float val) {
    return (int64_t) val;
  }

  inline string to_string (double val) {
    char result[200];
    sprintf(result, "%g", val);
    return string(result);
  }
  
  inline ListAccum<float> tg_extract_list(string weights){
  ListAccum<float> wghts;
  string current_weight;
  std::stringstream s_stream(weights);
  while (s_stream.good()) {
    std::getline(s_stream, current_weight, ',');
    wghts.data_.push_back(std::stof(current_weight));
  }
  return wghts;
}

inline float tg_fastrp_rand_func(int64_t v_id, int64_t emb_idx, int64_t seed, int64_t s){	  
  std::hash<std::string> hasher;
  auto hash = hasher(std::to_string(v_id) + "," + std::to_string(emb_idx) + "," + std::to_string(seed));

  std::mt19937 gen(hash);
  std::uniform_real_distribution<float> distribution(0.0, 1.0);
  float p1 = 0.5 / s, p2 = p1, p3 = 1 - 1.0 / s;
  float v1 = sqrt(s), v2 = -v1, v3 = 0.0;

  float random_value = distribution(gen);
  if (random_value <= p1)
    return v1;
  else if (random_value <= p1 + p2)
    return v2;
  else
    return v3;
}
}
/****************************************/

#endif /* EXPRFUNCTIONS_HPP_ */
#

@Dan_Barkus @Jon_Herke @Pawan_Mall @Vladimir_Slesarev @Parker_Erickson
I tried to install the queries for wcc as well as jacard, getting same error for both -

GSQL > INSTALL QUERY tg_jaccard_nbor_ap_batch
Start installing queries, about 1 minute ...
tg_jaccard_nbor_ap_batch query: curl -X GET 'http://127.0.0.1:9000/query/NetworkAnomalyDetection/tg_jaccard_nbor_ap_batch?[top_k=VALUE]&v_type=VALUE&feat_v_type=VALUE&e_type=VALUE&re_type=VALUE&similarity_edge=VALUE&[src_batch_num=VALUE]&[nbor_batch_num=VALUE]&[print_accum=VALUE]&[print_limit=VALUE]&[file_path=VALUE]'. Add -H "Authorization: Bearer TOKEN" if authentication is enabled.
Select 'm1' as compile server, now connecting ...
Node 'm1' is prepared as compile server.

[===================================================================================================     ] 95% (0/1)  m1: Reload libudf Failed!
Query installation failed during linking!
Query installation failed!

@AnuroopAjmera Can you provide information regarding your setup? Looks like you are running Windows. What version of TigerGraph are you running? We can do some testing on this side to replicate the issues you are running into.

Yes Jon, I am running on my Windows Laptop as the client asked to evaluate cloud option later, if required.

I am using version 3.4.0

Let me know if any other information is required.

Thanks

It makes sense that wcc and jacard is failing to install currently, as the query compiles it includes the UDF file which appears to be broken right now. Overall, the code looks correct, although the #include statements without any .h file associated with them as pasted above would be my guess on why the compilation is failing. You should be able to replace everything between #define EXPRFUNCTIONS_HPP_ and /** XXX Warning!! with this:

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <gle/engine/cpplib/headers.hpp>
#include <iostream>
#include <random>
#include <sstream>
#include <string>
#include <math.h>
#include <functional>

@Parker_Erickson
The error is same, says “tg_extract_list is not defined” is not defined but this is defined as mentioned in hpp file contents shared earlier.

GSQL > USE GRAPH NetworkAnomalyDetection
Using graph 'NetworkAnomalyDetection'
GSQL > PUT ExprFunctions from "/home/tigergraph/tigergraph/app/3.4.0/dev/gdk/gsql/src/QueryUdf/ExprFunctions.hpp"
PUT ExprFunctions successfully.
GSQL > @tg_fastRP.gsql

Semantic Check Error in query tg_fastRP (SEM-45): line 34, col 13
The tuple name or the function tg_extract_list is not defined.
Failed to create queries: [tg_fastRP].

Can you paste your entire ExprFunctions.hpp file here?

Hi @AnuroopAjmera
in the following error, I can see libudf reload failure

this means that at a certain point of installing the UDF function you broke your docker instance, in order to confirm that we’d like to have the latest logs from your docker container ( please send them to devrel@tigergraph.com ).

logs are available under /home/tigergraph/logs

Hi Anuroop,

I am Szilard Barany, a sales engineer/solution architect at TigerGraph EMEA. Since you work for Barclays, and since it’s a British company, I am the “closest” tech help for you.
If you want, you can contact me at szilard.barany@tigergraph.com directly. I am at a company event in the US, but I can possibly set up a Zoom call with you at 12pm (noon) your time. Let me know if that would work for you.

Regards,
Szilard

#ifndef EXPRFUNCTIONS_HPP_
#define EXPRFUNCTIONS_HPP_

#include <stdio.h>
#include <stdlib.h>
#include
#include <gle/engine/cpplib/headers.hpp>
#include
#include
#include
#include
#include <math.h>
#include

/** XXX Warning!! Put self-defined struct in ExprUtil.hpp **

  • No user defined struct, helper functions (that will not be directly called
  • in the GQuery scripts) etc. are allowed in this file. This file only
  • contains user-defined expression function’s signature and body.
  • Please put user defined structs, helper functions etc. in ExprUtil.hpp
    */
    #include “ExprUtil.hpp”

namespace UDIMPL {
typedef std::string string; //XXX DON’T REMOVE

/****** BIULT-IN FUNCTIONS ********/
/
XXX DON’T REMOVE ****************/
inline int64_t str_to_int (string str) {
return atoll(str.c_str());
}

inline int64_t float_to_int (float val) {
return (int64_t) val;
}

inline string to_string (double val) {
char result[200];
sprintf(result, “%g”, val);
return string(result);
}

inline ListAccum tg_extract_list(string weights){
ListAccum wghts;
string current_weight;
std::stringstream s_stream(weights);
while (s_stream.good()) {
std::getline(s_stream, current_weight, ‘,’);
wghts.data_.push_back(std::stof(current_weight));
}
return wghts;
}

inline float tg_fastrp_rand_func(int64_t v_id, int64_t emb_idx, int64_t seed, int64_t s){
std::hashstd::string hasher;
auto hash = hasher(std::to_string(v_id) + “,” + std::to_string(emb_idx) + “,” + std::to_string(seed));

std::mt19937 gen(hash);
std::uniform_real_distribution distribution(0.0, 1.0);
float p1 = 0.5 / s, p2 = p1, p3 = 1 - 1.0 / s;
float v1 = sqrt(s), v2 = -v1, v3 = 0.0;

float random_value = distribution(gen);
if (random_value <= p1)
return v1;
else if (random_value <= p1 + p2)
return v2;
else
return v3;
}
}
/****************************************/

#endif /* EXPRFUNCTIONS_HPP_ */

  1. Copy and Paste hasn’t printed #include statement without .h files otherwise the list is same as what you provided, even it was correct earlier also, only there were some duplicate #include statements which shouldn’t have created any issues.
  2. Copy and Paste hasn’t printed “<” and “>” symbols at few places

I can email you this complete file if you want. Your email ID please?

Thanks

parker.erickson@tigergraph.com would be good.

@Mohamed_Zrouga @Parker_Erickson @Vladimir_Slesarev @Dan_Barkus

Great News, I could install wcc, jacard and louvain successfully (with below warning) today morning so the error is just with fastRP now. Thanks to you and TigerGraph team who is providing suggestions. Now I need to implement these to my business problem :slight_smile:

GSQL > INSTALL QUERY tg_wcc
Start installing queries, about 1 minute …
tg_wcc query: curl -X GET ‘http://127.0.0.1:9000/query/NetworkAnomalyDetection/tg_wcc?v_type=VALUE&e_type=VALUE&[output_limit=VALUE]&[print_accum=VALUE]&[result_attr=VALUE]&[file_path=VALUE]’. Add -H “Authorization: Bearer TOKEN” if authentication is enabled.
Select ‘m1’ as compile server, now connecting …
Node ‘m1’ is prepared as compile server.

[========================================================================================================] 100% (1/1)
Query installation finished.
GSQL > INSTALL QUERY tg_jaccard_nbor_ap_batch
Start installing queries, about 1 minute …
tg_jaccard_nbor_ap_batch query: curl -X GET ‘http://127.0.0.1:9000/query/NetworkAnomalyDetection/tg_jaccard_nbor_ap_batch?[top_k=VALUE]&v_type=VALUE&feat_v_type=VALUE&e_type=VALUE&re_type=VALUE&similarity_edge=VALUE&[src_batch_num=VALUE]&[nbor_batch_num=VALUE]&[print_accum=VALUE]&[print_limit=VALUE]&[file_path=VALUE]’. Add -H “Authorization: Bearer TOKEN” if authentication is enabled.
Select ‘m1’ as compile server, now connecting …
Node ‘m1’ is prepared as compile server.

[========================================================================================================] 100% (1/1)
Query installation finished.
GSQL > INSTALL QUERY tg_louvain
Start installing queries, about 1 minute …
tg_louvain query: curl -X GET ‘http://127.0.0.1:9000/query/NetworkAnomalyDetection/tg_louvain?v_type=VALUE&e_type=VALUE&[wt_attr=VALUE]&[max_iter=VALUE]&[result_attr=VALUE]&[file_path=VALUE]&[print_info=VALUE]’. Add -H “Authorization: Bearer TOKEN” if authentication is enabled.
Select ‘m1’ as compile server, now connecting …
Node ‘m1’ is prepared as compile server.

[========================================================================================================] 100% (1/1)
Query installation finished.

Louvain warning from GraphStudio:

(72, 23) Warning: The comparison ‘-t.@max_best_move.weight==t.@sum_cc_weight’ may lead to unexpected behavior because it involves equality test between float/double numeric values. We suggest to do such comparison with an error margin, e.g. ‘abs((-t.@max_best_move.weight) - (t.@sum_cc_weight)) < epsilon’, where epsilon is a very small positive value of your choice, such as 0.0001.
(148, 25) Warning: The comparison ‘-s.@max_best_move.weight==s.@sum_cc_weight’ may lead to unexpected behavior because it involves equality test between float/double numeric values. We suggest to do such comparison with an error margin, e.g. ‘abs((-s.@max_best_move.weight) - (s.@sum_cc_weight)) < epsilon’, where epsilon is a very small positive value of your choice, such as 0.0001.

1 Like

@Parker_Erickson @Vladimir_Slesarev @Szilard_Barany
Strange Error as shared earlier -

GSQL > @tg_fastRP.gsql

Semantic Check Error in query tg_fastRP (SEM-45): line 34, col 13
The tuple name or the function tg_extract_list is not defined.
Failed to create queries: [tg_fastRP].

@Szilard_Barany are you joining zoom call scheduled by you?

Regards
Anuroop

tg_jaccard_nbor_ap_batch is not giving me any result where as tg_jaccard_nbor_ss is working fine but I need to run it for all the nodes simultaneously.

I am not able to find code for tg_jaccard_nbor_ap.gsql. Algo page is broken, giving 404 error.

Could someone please help?

@Mohamed_Zrouga @Dan_Barkus @Parker_Erickson @Szilard_Barany @Vladimir_Slesarev @Jon_Herke

Just verifying this is the link you’re referring to https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Similarity/jaccard then when clicking on tg_jaccard_nbor_ap.gsql you got a 404 (page doesn’t exist). I’ve also (confirmed) received the error.

Forwarding this on to the Graph Data Science team to get their input on this thread.

Yes, this is the link