Skip to content

Commit

Permalink
migrate delta stepping write
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Mar 27, 2024
1 parent 0d9fd89 commit c3041a7
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.neo4j.gds.api.GraphName;
import org.neo4j.gds.collections.ha.HugeLongArray;
import org.neo4j.gds.paths.astar.config.ShortestPathAStarMutateConfig;
import org.neo4j.gds.paths.delta.config.AllShortestPathsDeltaMutateConfig;
import org.neo4j.gds.paths.dijkstra.PathFindingResult;
import org.neo4j.gds.paths.dijkstra.config.AllShortestPathsDijkstraMutateConfig;
import org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraMutateConfig;
Expand All @@ -38,6 +39,7 @@

import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.A_STAR;
import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.BFS;
import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.DELTA_STEPPING;
import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.DFS;
import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.DIJKSTRA;
import static org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmLabels.SPANNING_TREE;
Expand Down Expand Up @@ -82,6 +84,24 @@ public <RESULT> RESULT breadthFirstSearch(
);
}

public <RESULT> RESULT deltaStepping(
GraphName graphName,
AllShortestPathsDeltaMutateConfig configuration,
ResultBuilder<AllShortestPathsDeltaMutateConfig, PathFindingResult, RESULT> resultBuilder
) {
var mutateStep = new ShortestPathMutateStep(configuration);

return algorithmProcessingTemplate.processAlgorithm(
graphName,
configuration,
DELTA_STEPPING,
estimationFacade::deltaSteppingEstimation,
graph -> pathFindingAlgorithms.deltaStepping(graph, configuration),
Optional.of(mutateStep),
resultBuilder
);
}

public <RESULT> RESULT depthFirstSearch(
GraphName graphName,
DfsMutateConfig configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.gds.ml.pipeline.stubs.SinglePairShortestPathAStarStub;
import org.neo4j.gds.ml.pipeline.stubs.SinglePairShortestPathDijkstraStub;
import org.neo4j.gds.ml.pipeline.stubs.SinglePairShortestPathYensStub;
import org.neo4j.gds.ml.pipeline.stubs.SingleSourceShortestPathDeltaStub;
import org.neo4j.gds.ml.pipeline.stubs.SingleSourceShortestPathDijkstraStub;
import org.neo4j.gds.ml.pipeline.stubs.SpanningTreeStub;
import org.neo4j.gds.ml.pipeline.stubs.SteinerTreeStub;
Expand Down Expand Up @@ -68,6 +69,7 @@ static NodePropertyStepFactoryUsingStubs GetOrCreate() {

private static NodePropertyStepFactoryUsingStubs create() {
Map<CanonicalProcedureName, Stub> supportedProcedures = Map.of(
CanonicalProcedureName.parse("gds.allshortestpaths.delta.mutate"), new SingleSourceShortestPathDeltaStub(),
CanonicalProcedureName.parse("gds.allshortestpaths.dijkstra.mutate"), new SingleSourceShortestPathDijkstraStub(),
CanonicalProcedureName.parse("gds.bfs.mutate"), new BreadthFirstSearchStub(),
CanonicalProcedureName.parse("gds.dfs.mutate"), new DepthFirstSearchStub(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.ml.pipeline.stubs;

import org.neo4j.gds.paths.delta.config.AllShortestPathsDeltaMutateConfig;
import org.neo4j.gds.procedures.algorithms.AlgorithmsProcedureFacade;
import org.neo4j.gds.procedures.algorithms.pathfinding.MutateStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.PathFindingMutateResult;

public class SingleSourceShortestPathDeltaStub extends AbstractStub<AllShortestPathsDeltaMutateConfig, PathFindingMutateResult> {
protected MutateStub<AllShortestPathsDeltaMutateConfig, PathFindingMutateResult> stub(AlgorithmsProcedureFacade facade) {
return facade.pathFinding().deltaSteppingMutateStub();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@
package org.neo4j.gds.paths.singlesource.delta;

import org.neo4j.gds.BaseProc;
import org.neo4j.gds.executor.MemoryEstimationExecutor;
import org.neo4j.gds.executor.ProcedureExecutor;
import org.neo4j.gds.executor.ProcedureExecutorSpec;

import org.neo4j.gds.procedures.GraphDataScience;
import org.neo4j.gds.procedures.algorithms.pathfinding.PathFindingMutateResult;
import org.neo4j.gds.paths.delta.DeltaStepping;
import org.neo4j.gds.paths.delta.config.AllShortestPathsDeltaMutateConfig;
import org.neo4j.gds.paths.dijkstra.PathFindingResult;
import org.neo4j.gds.results.MemoryEstimateResult;
import org.neo4j.procedure.Context;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;
Expand All @@ -37,40 +32,28 @@
import java.util.stream.Stream;

import static org.neo4j.gds.paths.singlesource.SingleSourceShortestPathConstants.DELTA_STEPPING_DESCRIPTION;
import static org.neo4j.gds.procedures.ProcedureConstants.MEMORY_ESTIMATION_DESCRIPTION;
import static org.neo4j.procedure.Mode.READ;

public class AllShortestPathsDeltaMutateProc extends BaseProc {
@Context
public GraphDataScience facade;

@Procedure(name = "gds.allShortestPaths.delta.mutate", mode = READ)
@Description(DELTA_STEPPING_DESCRIPTION)
public Stream<PathFindingMutateResult> stream(
@Name(value = "graphName") String graphName,
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
) {
var mutateSpec = new AllShortestPathsDeltaMutateSpec();
var pipelineSpec = new ProcedureExecutorSpec<DeltaStepping, PathFindingResult, AllShortestPathsDeltaMutateConfig>();

return new ProcedureExecutor<>(
mutateSpec,
pipelineSpec,
executionContext()
).compute(graphName, configuration);
return facade.pathFinding().deltaSteppingMutateStub().execute(graphName, configuration);
}

@Procedure(name = "gds.allShortestPaths.delta.mutate.estimate", mode = READ)
@Description(ESTIMATE_DESCRIPTION)
@Description(MEMORY_ESTIMATION_DESCRIPTION)
public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
var mutateSpec = new AllShortestPathsDeltaMutateSpec();
var pipelineSpec = new ProcedureExecutorSpec<DeltaStepping, PathFindingResult, AllShortestPathsDeltaMutateConfig>();

return new MemoryEstimationExecutor<>(
mutateSpec,
pipelineSpec,
executionContext(),
transactionContext()
).computeEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.pathFinding().deltaSteppingMutateStub().estimate(graphNameOrConfiguration, algoConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationCreator;
import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationParser;
import org.neo4j.gds.procedures.algorithms.pathfinding.stubs.BreadthFirstSearchMutateStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.stubs.DeltaSteppingMutateStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.stubs.DepthFirstSearchMutateStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.stubs.GenericStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.stubs.SinglePairShortestPathAStarMutateStub;
Expand Down Expand Up @@ -104,6 +105,7 @@ public final class PathFindingProcedureFacade {

// applications
private final BreadthFirstSearchMutateStub breadthFirstSearchMutateStub;
private final DeltaSteppingMutateStub deltaSteppingMutateStub;
private final DepthFirstSearchMutateStub depthFirstSearchMutateStub;
private final SinglePairShortestPathAStarMutateStub singlePairShortestPathAStarMutateStub;
private final SinglePairShortestPathDijkstraMutateStub singlePairShortestPathDijkstraMutateStub;
Expand All @@ -122,6 +124,7 @@ private PathFindingProcedureFacade(
PathFindingAlgorithmsStreamModeBusinessFacade streamModeFacade,
PathFindingAlgorithmsWriteModeBusinessFacade writeModeFacade,
BreadthFirstSearchMutateStub breadthFirstSearchMutateStub,
DeltaSteppingMutateStub deltaSteppingMutateStub,
DepthFirstSearchMutateStub depthFirstSearchMutateStub,
SinglePairShortestPathAStarMutateStub singlePairShortestPathAStarMutateStub,
SinglePairShortestPathDijkstraMutateStub singlePairShortestPathDijkstraMutateStub,
Expand All @@ -141,6 +144,7 @@ private PathFindingProcedureFacade(
this.writeModeFacade = writeModeFacade;

this.breadthFirstSearchMutateStub = breadthFirstSearchMutateStub;
this.deltaSteppingMutateStub = deltaSteppingMutateStub;
this.depthFirstSearchMutateStub = depthFirstSearchMutateStub;
this.singlePairShortestPathAStarMutateStub = singlePairShortestPathAStarMutateStub;
this.singlePairShortestPathDijkstraMutateStub = singlePairShortestPathDijkstraMutateStub;
Expand Down Expand Up @@ -189,6 +193,12 @@ public static PathFindingProcedureFacade create(
pathFindingAlgorithmsMutateModeBusinessFacade
);

var deltaSteppingMutateStub = new DeltaSteppingMutateStub(
genericStub,
pathFindingAlgorithmsEstimationModeBusinessFacade,
pathFindingAlgorithmsMutateModeBusinessFacade
);

var depthFirstSearchMutateStub = new DepthFirstSearchMutateStub(
genericStub,
pathFindingAlgorithmsEstimationModeBusinessFacade,
Expand Down Expand Up @@ -235,6 +245,7 @@ public static PathFindingProcedureFacade create(
pathFindingAlgorithmsStreamModeBusinessFacade,
pathFindingAlgorithmsWriteModeBusinessFacade,
breadthFirstSearchMutateStub,
deltaSteppingMutateStub,
depthFirstSearchMutateStub,
aStarStub,
singlePairDijkstraStub,
Expand Down Expand Up @@ -321,6 +332,10 @@ public Stream<MemoryEstimateResult> breadthFirstSearchStreamEstimate(
return Stream.of(result);
}

public DeltaSteppingMutateStub deltaSteppingMutateStub() {
return deltaSteppingMutateStub;
}

public Stream<StandardStatsResult> deltaSteppingStats(String graphName, Map<String, Object> configuration) {
var resultBuilder = new DeltaSteppingResultBuilderForStatsMode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MemoryEstimation getMemoryEstimation(String username, Map<String, Object>
username,
configuration,
BfsMutateConfig::of,
bfsMutateConfig -> estimationFacade.breadthFirstSearchEstimation()
__ -> estimationFacade.breadthFirstSearchEstimation()
);
}

Expand All @@ -71,7 +71,7 @@ public Stream<MemoryEstimateResult> estimate(Object graphName, Map<String, Objec
graphName,
configuration,
BfsMutateConfig::of,
bfsMutateConfig -> estimationFacade.breadthFirstSearchEstimation()
__ -> estimationFacade.breadthFirstSearchEstimation()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.procedures.algorithms.pathfinding.stubs;

import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingAlgorithmsEstimationModeBusinessFacade;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingAlgorithmsMutateModeBusinessFacade;
import org.neo4j.gds.core.utils.mem.MemoryEstimation;
import org.neo4j.gds.paths.delta.config.AllShortestPathsDeltaMutateConfig;
import org.neo4j.gds.procedures.algorithms.pathfinding.MutateStub;
import org.neo4j.gds.procedures.algorithms.pathfinding.PathFindingMutateResult;
import org.neo4j.gds.procedures.algorithms.pathfinding.PathFindingResultBuilderForMutateMode;
import org.neo4j.gds.results.MemoryEstimateResult;

import java.util.Map;
import java.util.stream.Stream;

public class DeltaSteppingMutateStub implements MutateStub<AllShortestPathsDeltaMutateConfig, PathFindingMutateResult> {
private final GenericStub genericStub;
private final PathFindingAlgorithmsEstimationModeBusinessFacade estimationFacade;
private final PathFindingAlgorithmsMutateModeBusinessFacade mutateFacade;

public DeltaSteppingMutateStub(
GenericStub genericStub,
PathFindingAlgorithmsEstimationModeBusinessFacade estimationFacade,
PathFindingAlgorithmsMutateModeBusinessFacade mutateFacade
) {
this.estimationFacade = estimationFacade;
this.mutateFacade = mutateFacade;
this.genericStub = genericStub;
}

@Override
public void validateConfiguration(Map<String, Object> configuration) {
genericStub.validateConfiguration(AllShortestPathsDeltaMutateConfig::of, configuration);
}

@Override
public AllShortestPathsDeltaMutateConfig parseConfiguration(Map<String, Object> configuration) {
return genericStub.parseConfiguration(AllShortestPathsDeltaMutateConfig::of, configuration);
}

@Override
public MemoryEstimation getMemoryEstimation(String username, Map<String, Object> configuration) {
return genericStub.getMemoryEstimation(
username,
configuration,
AllShortestPathsDeltaMutateConfig::of,
__ -> estimationFacade.deltaSteppingEstimation()
);
}

@Override
public Stream<MemoryEstimateResult> estimate(Object graphName, Map<String, Object> rawConfiguration) {
return genericStub.estimate(
graphName,
rawConfiguration,
AllShortestPathsDeltaMutateConfig::of,
__ -> estimationFacade.deltaSteppingEstimation()
);
}

@Override
public Stream<PathFindingMutateResult> execute(String graphName, Map<String, Object> configuration) {
return genericStub.execute(
graphName,
configuration,
AllShortestPathsDeltaMutateConfig::of,
mutateFacade::deltaStepping,
new PathFindingResultBuilderForMutateMode<>()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MemoryEstimation getMemoryEstimation(String username, Map<String, Object>
username,
configuration,
DfsMutateConfig::of,
dfsMutateConfig -> estimationFacade.depthFirstSearchEstimation()
__ -> estimationFacade.depthFirstSearchEstimation()
);
}

Expand All @@ -71,7 +71,7 @@ public Stream<MemoryEstimateResult> estimate(Object graphName, Map<String, Objec
graphName,
configuration,
DfsMutateConfig::of,
dfsMutateConfig -> estimationFacade.depthFirstSearchEstimation()
__ -> estimationFacade.depthFirstSearchEstimation()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MemoryEstimation getMemoryEstimation(String username, Map<String, Object>
username,
configuration,
ShortestPathAStarMutateConfig::of,
shortestPathAStarMutateConfig -> estimationFacade.singlePairShortestPathAStarEstimation()
__ -> estimationFacade.singlePairShortestPathAStarEstimation()
);
}

Expand All @@ -73,7 +73,7 @@ public Stream<MemoryEstimateResult> estimate(Object graphName, Map<String, Objec
graphName,
configuration,
ShortestPathAStarMutateConfig::of,
shortestPathAStarMutateConfig -> estimationFacade.singlePairShortestPathAStarEstimation()
__ -> estimationFacade.singlePairShortestPathAStarEstimation()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MemoryEstimation getMemoryEstimation(String username, Map<String, Object>
username,
configuration,
SpanningTreeMutateConfig::of,
spanningTreeMutateConfig -> estimationFacade.spanningTreeEstimation()
__ -> estimationFacade.spanningTreeEstimation()
);
}

Expand All @@ -71,7 +71,7 @@ public Stream<MemoryEstimateResult> estimate(Object graphName, Map<String, Objec
graphName,
configuration,
SpanningTreeMutateConfig::of,
spanningTreeMutateConfig -> estimationFacade.spanningTreeEstimation()
__ -> estimationFacade.spanningTreeEstimation()
);
}

Expand Down

0 comments on commit c3041a7

Please sign in to comment.