Skip to content

Commit

Permalink
Add LCC Write facade
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisPanagiotas committed Oct 12, 2023
1 parent 4ab6dc4 commit b87d87b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.gds.algorithms.KmeansSpecificFields;
import org.neo4j.gds.algorithms.LabelPropagationSpecificFields;
import org.neo4j.gds.algorithms.LeidenSpecificFields;
import org.neo4j.gds.algorithms.LocalClusteringCoefficientSpecificFields;
import org.neo4j.gds.algorithms.LouvainSpecificFields;
import org.neo4j.gds.algorithms.ModularityOptimizationSpecificFields;
import org.neo4j.gds.algorithms.NodePropertyWriteResult;
Expand All @@ -53,6 +54,7 @@
import org.neo4j.gds.result.StatisticsComputationInstructions;
import org.neo4j.gds.scc.SccAlphaWriteConfig;
import org.neo4j.gds.scc.SccWriteConfig;
import org.neo4j.gds.triangle.LocalClusteringCoefficientWriteConfig;
import org.neo4j.gds.triangle.TriangleCountWriteConfig;
import org.neo4j.gds.wcc.WccWriteConfig;

Expand Down Expand Up @@ -545,6 +547,36 @@ public NodePropertyWriteResult<TriangleCountSpecificFields> triangleCount(
);
}

public NodePropertyWriteResult<LocalClusteringCoefficientSpecificFields> localClusteringCoefficient(
String graphName,
LocalClusteringCoefficientWriteConfig config,
User user,
DatabaseId databaseId
) {

// 1. Run the algorithm and time the execution
var intermediateResult = runWithTiming(
() -> communityAlgorithmsFacade.localClusteringCoefficient(graphName, config, user, databaseId)
);
var algorithmResult = intermediateResult.algorithmResult;

return writeToDatabase(
algorithmResult,
config,
(result, configuration) -> NodePropertyValuesAdapter.adapt(result.localClusteringCoefficients()),
(result) -> new LocalClusteringCoefficientSpecificFields(
result.localClusteringCoefficients().size(),
result.averageClusteringCoefficient()
),
intermediateResult.computeMilliseconds,
() -> LocalClusteringCoefficientSpecificFields.EMPTY,
"LocalClusteringCoefficientWrite",
config.writeConcurrency(),
config.writeProperty(),
config.arrowConnectionInfo()
);
}


<RESULT, CONFIG extends AlgoBaseConfig, ASF extends CommunityStatisticsSpecificFields> NodePropertyWriteResult<ASF> writeToDatabase(
AlgorithmComputationResult<RESULT> algorithmResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
package org.neo4j.gds.triangle;

import org.neo4j.gds.BaseProc;
import org.neo4j.gds.core.write.NodePropertyExporterBuilder;
import org.neo4j.gds.executor.ExecutionContext;
import org.neo4j.gds.executor.MemoryEstimationExecutor;
import org.neo4j.gds.executor.ProcedureExecutor;
import org.neo4j.gds.procedures.GraphDataScience;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult;
import org.neo4j.gds.results.MemoryEstimateResult;
import org.neo4j.procedure.Context;
Expand All @@ -41,18 +38,16 @@
public class LocalClusteringCoefficientWriteProc extends BaseProc {

@Context
public NodePropertyExporterBuilder nodePropertyExporterBuilder;
public GraphDataScience facade;

@Procedure(value = "gds.localClusteringCoefficient.write", mode = WRITE)
@Description(DESCRIPTION)
public Stream<LocalClusteringCoefficientWriteResult> write(
@Name(value = "graphName") String graphName,
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
) {
return new ProcedureExecutor<>(
new LocalClusteringCoefficientWriteSpec(),
executionContext()
).compute(graphName, configuration);
return facade.community().localClusteringCoefficientWrite(graphName, configuration);

}

@Procedure(value = "gds.localClusteringCoefficient.write.estimate", mode = READ)
Expand All @@ -61,15 +56,7 @@ public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
return new MemoryEstimationExecutor<>(
new LocalClusteringCoefficientWriteSpec(),
executionContext(),
transactionContext()
).computeEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.community().localClusteringCoefficientEstimateWrite(graphNameOrConfiguration, algoConfiguration);
}

@Override
public ExecutionContext executionContext() {
return super.executionContext().withNodePropertyExporterBuilder(nodePropertyExporterBuilder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientMutateResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStatsResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStreamResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult;
import org.neo4j.gds.procedures.community.triangleCount.TriangleCountMutateResult;
import org.neo4j.gds.procedures.community.triangleCount.TriangleCountStatsResult;
import org.neo4j.gds.procedures.community.triangleCount.TriangleCountStreamResult;
Expand All @@ -121,6 +122,7 @@
import org.neo4j.gds.triangle.LocalClusteringCoefficientMutateConfig;
import org.neo4j.gds.triangle.LocalClusteringCoefficientStatsConfig;
import org.neo4j.gds.triangle.LocalClusteringCoefficientStreamConfig;
import org.neo4j.gds.triangle.LocalClusteringCoefficientWriteConfig;
import org.neo4j.gds.triangle.TriangleCountMutateConfig;
import org.neo4j.gds.triangle.TriangleCountStatsConfig;
import org.neo4j.gds.triangle.TriangleCountStreamConfig;
Expand Down Expand Up @@ -1068,6 +1070,21 @@ public Stream<LocalClusteringCoefficientStatsResult> localClusteringCoefficientS
return Stream.of(LCCComputationResultTransformer.toStatsResult(computationResult, statsConfig));
}

public Stream<LocalClusteringCoefficientWriteResult> localClusteringCoefficientWrite(
String graphName,
Map<String, Object> configuration
) {
var writeConfig = createConfig(configuration, LocalClusteringCoefficientWriteConfig::of);

var computationResult = writeBusinessFacade.localClusteringCoefficient(
graphName,
writeConfig,
user,
databaseId
);

return Stream.of(LCCComputationResultTransformer.toWriteResult(computationResult));
}

public Stream<MemoryEstimateResult> localClusteringCoefficientEstimateMutate(
Object graphNameOrConfiguration,
Expand All @@ -1077,6 +1094,14 @@ public Stream<MemoryEstimateResult> localClusteringCoefficientEstimateMutate(
return Stream.of(estimateBusinessFacade.localClusteringCoefficient(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> localClusteringCoefficientEstimateWrite(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
) {
var config = createConfig(algoConfiguration, LocalClusteringCoefficientWriteConfig::of);
return Stream.of(estimateBusinessFacade.localClusteringCoefficient(graphNameOrConfiguration, config));
}

public Stream<MemoryEstimateResult> localClusteringCoefficientEstimateStats(
Object graphNameOrConfiguration,
Map<String, Object> algoConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

import org.neo4j.gds.algorithms.LocalClusteringCoefficientSpecificFields;
import org.neo4j.gds.algorithms.NodePropertyMutateResult;
import org.neo4j.gds.algorithms.NodePropertyWriteResult;
import org.neo4j.gds.algorithms.StatsResult;
import org.neo4j.gds.algorithms.StreamComputationResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientMutateResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStatsResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStreamResult;
import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult;
import org.neo4j.gds.triangle.LocalClusteringCoefficientMutateConfig;
import org.neo4j.gds.triangle.LocalClusteringCoefficientResult;
import org.neo4j.gds.triangle.LocalClusteringCoefficientStatsConfig;
Expand Down Expand Up @@ -77,4 +79,19 @@ static LocalClusteringCoefficientStatsResult toStatsResult(
);
}

static LocalClusteringCoefficientWriteResult toWriteResult(
NodePropertyWriteResult<LocalClusteringCoefficientSpecificFields> computationResult
) {
return new LocalClusteringCoefficientWriteResult(
computationResult.algorithmSpecificFields().averageClusteringCoefficient(),
computationResult.algorithmSpecificFields().nodeCount(),
computationResult.preProcessingMillis(),
computationResult.computeMillis(),
computationResult.writeMillis(),
computationResult.nodePropertiesWritten(),
computationResult.configuration().toMap()
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class LocalClusteringCoefficientWriteResult extends LocalClustering
public long writeMillis;
public long nodePropertiesWritten;

private LocalClusteringCoefficientWriteResult(
public LocalClusteringCoefficientWriteResult(
double averageClusteringCoefficient,
long nodeCount,
long preProcessingMillis,
Expand Down

0 comments on commit b87d87b

Please sign in to comment.