16.6.2 Getting the Progress of a Running Algorithm

The progress of a graph algorithm is based on the value of a monotonically increasing counter that gets incremented periodically during algorithm executions.

You can track the progress of the algorithms using the AlgorithmProgress Java API and review the progress by comparing the counter value at various points in time to an estimate of the final value of the counter.

The AlgorithmProgress object represents the progress of an algorithm execution at a certain time. It contains the following two attributes:

  • numberOfStepsCompleted: This counter represents the current number of steps executed.
  • numberOfStepsEstimatedForCompletion: This value is an estimation of the total number of steps needed for completion.

    A default positive value is provided for numberOfStepsEstimatedForCompletion for the following list of built-in algorithms:

    • PageRank
    • Approximate PageRank
    • Personalized PageRank
    • Personalized PageRank (for a set of vertices)
    • Personalized Weighted PageRank
    • Personalized Weighted PageRank (for a set of vertices)
    • Weighted PageRank
    • Degree Centrality
    • In-Degree Centrality
    • Out-Degree Centrality
    • Filtered Speaker Listener Label Propagation
    • Filtered Weighted Speaker Listener Label Propagation
    • Weighted Speaker Listener Label Propagation
    • Speaker Listener Label Propagation
    • Label Propagation
    • Louvain
    • Soman and Narang
    • Weighted Infomap
    • Dijkstra
    • Undirected Dijkstra
    • Filtered Dijkstra
    • Undirected Filtered Dijkstra
    • Bidirectional Dijkstra
    • Bidirectional Undirected Dijkstra
    • Bidirectional Filtered Dijkstra
    • Bidirectional Undirected Filtered Dijkstra
    • Fattest Path
    • Undirected Fattest Path
    • Hop Distance
    • Undirected Hop Distance
    • Backward Hop Distance

You cannot estimate the progress as a percentage for algorithms that do not provide a value for numberOfStepsEstimatedForCompletion. In such a case, you can only access the value of the counter (numberOfStepsCompleted).

However, you can set the numberOfStepsEstimatedForCompletion value for a custom PGX graph algorithm. See Tracking the Progress of a Running Custom PGX Graph Algorithm for more information.

The following example uses the in-built PageRank algorithm and describes the steps to get the progress of the running built-in algorithm using the AlgorithmProgress Java API:

opg4j> var graph = session.readGraphByName("BANK_TXN_GRAPH", GraphSource.PG_PGQL)
g ==> PgxGraph[name=BANK_TXN_GRAPH,N=1000,E=4993,created=1712307339271]
opg4j>  var future = analyst.pagerankAsync(graph)
future ==> oracle.pgx.api.PgxFuture@1dfe5dd1[Not completed]
opg4j> var futureProgress = future.getProgress()
futureProgress ==> oracle.pgx.api.DefaultFutureProgress@6d7bb5cc
opg4j> var algorithmProgress = futureProgress.asAlgorithmExecutionProgress()
PgxGraph graph = session.readGraphByName("BANK_TXN_GRAPH", GraphSource.PG_PGQL);
PgxFuture<?> future = analyst.pagerank.runAsync(graph);
FutureProgress futureProgress = future.getProgress();
Optional<AlgorithmProgress> algorithmProgress = futureProgress.asAlgorithmExecutionProgress();

The following code shows how you can estimate the progress as a percentage for the running algorithm:

opg4j> if (algorithmProgress.isPresent()) {
...>   var progress = algorithmProgress.get();
...>   var completedSteps = progress.getNumberOfStepsCompleted();
...>   var numberOfStepsEstimatedForCompletion = progress.getNumberOfStepsEstimatedForCompletion();
...>   var progressPercentage = completedSteps * 100 / numberOfStepsEstimatedForCompletion;
...>   System.out.println(completedSteps);
...>   System.out.println(numberOfStepsEstimatedForCompletion);
...>   System.out.println(progressPercentage);
...> }
if (algorithmProgress.isPresent()) {
  AlgorithmProgress progress = algorithmProgress.get();
  long completedSteps = progress.getNumberOfStepsCompleted();
  Long numberOfStepsEstimatedForCompletion = progress.getNumberOfStepsEstimatedForCompletion();
  long progressPercentage = completedSteps * 100 / numberOfStepsEstimatedForCompletion;
  System.out.println(completedSteps); 
  System.out.println(numberOfStepsEstimatedForCompletion); 
  System.out.println(progressPercentage); 
};

The preceding code shows the progress at that current moment. If you try to get the progress of the running algorithm after a while (for example, 1min), then you should get a larger value for progressPercentage.