Skip to content

Commit

Permalink
migrate estimation cli k1 coloring to application layer
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Nov 29, 2024
1 parent fb70ff3 commit 2bb9f8d
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 396 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

import java.util.List;

public class K1ColoringProgressTrackerTaskCreator {

public final class K1ColoringProgressTrackerTaskCreator {
private K1ColoringProgressTrackerTaskCreator() {}

public static Task progressTask(long nodeCount, int maxIterations) {

return Tasks.iterativeDynamic(
AlgorithmLabel.K1Coloring.asString(),
() -> List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.modularityoptimization;

import org.neo4j.gds.api.Graph;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery;
import org.neo4j.gds.core.concurrency.Concurrency;
import org.neo4j.gds.core.concurrency.DefaultPool;
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
import org.neo4j.gds.k1coloring.K1Coloring;
import org.neo4j.gds.k1coloring.K1ColoringParameters;
import org.neo4j.gds.k1coloring.K1ColoringResult;
import org.neo4j.gds.termination.TerminationFlag;

public class K1ColoringStub {
private final AlgorithmMachinery algorithmMachinery;

public K1ColoringStub(AlgorithmMachinery algorithmMachinery) {
this.algorithmMachinery = algorithmMachinery;
}

public K1ColoringResult k1Coloring(
Graph graph,
K1ColoringParameters parameters,
ProgressTracker progressTracker,
TerminationFlag terminationFlag,
Concurrency concurrency,
boolean shouldReleaseProgressTracker
) {
var algorithm = new K1Coloring(
graph,
parameters.maxIterations(),
parameters.batchSize(),
parameters.concurrency(),
DefaultPool.INSTANCE,
progressTracker,
terminationFlag
);

return algorithmMachinery.runAlgorithmsAndManageProgressTracker(
algorithm,
progressTracker,
shouldReleaseProgressTracker,
concurrency
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.gds.api.Graph;
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
import org.neo4j.gds.api.properties.relationships.RelationshipIterator;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery;
import org.neo4j.gds.collections.ha.HugeDoubleArray;
import org.neo4j.gds.collections.ha.HugeLongArray;
import org.neo4j.gds.collections.haa.HugeAtomicDoubleArray;
Expand All @@ -38,8 +39,6 @@
import org.neo4j.gds.core.utils.partition.Partition;
import org.neo4j.gds.core.utils.partition.PartitionUtils;
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
import org.neo4j.gds.k1coloring.K1Coloring;
import org.neo4j.gds.k1coloring.K1ColoringAlgorithmFactory;
import org.neo4j.gds.k1coloring.K1ColoringParameters;
import org.neo4j.gds.termination.TerminationFlag;

Expand Down Expand Up @@ -177,10 +176,16 @@ public ModularityOptimizationResult compute() {

private void computeColoring() {
var parameters = new K1ColoringParameters(concurrency, K1COLORING_MAX_ITERATIONS, minBatchSize);
K1Coloring coloring = new K1ColoringAlgorithmFactory<>().build(graph, parameters, progressTracker);
coloring.setTerminationFlag(terminationFlag);
var k1ColoringStub = new K1ColoringStub(new AlgorithmMachinery());
var k1ColoringResult = k1ColoringStub.k1Coloring(
graph,
parameters,
progressTracker,
terminationFlag,
concurrency,
false
);

var k1ColoringResult = coloring.compute();
modularityColorArray = ModularityColorArray.create(
k1ColoringResult.colors(),
k1ColoringResult.usedColors()
Expand Down Expand Up @@ -394,11 +399,4 @@ private double calculateModularity() {
modularityManager.registerCommunities(currentCommunities);
return modularityManager.calculateModularity();
}

private long getCommunityId(long nodeId) {
if (seedProperty == null || reverseSeedCommunityMapping == null) {
return currentCommunities.get(nodeId);
}
return reverseSeedCommunityMapping.get(currentCommunities.get(nodeId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.neo4j.gds.api.Graph;
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
import org.neo4j.gds.core.concurrency.DefaultPool;
import org.neo4j.gds.k1coloring.K1ColoringProgressTrackerTaskCreator;
import org.neo4j.gds.mem.MemoryEstimation;
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
import org.neo4j.gds.core.utils.progress.tasks.Task;
import org.neo4j.gds.core.utils.progress.tasks.Tasks;
import org.neo4j.gds.k1coloring.K1ColoringAlgorithmFactory;
import org.neo4j.gds.k1coloring.K1ColoringBaseConfig;
import org.neo4j.gds.k1coloring.K1ColoringStreamConfigImpl;
import org.neo4j.gds.termination.TerminationFlag;
Expand Down Expand Up @@ -94,11 +94,13 @@ public Task progressTask(Graph graph, CONFIG config) {
}

public static Task progressTask(Graph graph, int maxIterations) {
var config = createModularityConfig();

return Tasks.task(
MODULARITY_OPTIMIZATION_TASK_NAME,
Tasks.task(
"initialization",
K1ColoringAlgorithmFactory.k1ColoringProgressTask(graph, createModularityConfig())
K1ColoringProgressTrackerTaskCreator.progressTask(graph.nodeCount(), config.maxIterations())
),
Tasks.iterativeDynamic(
"compute modularity",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2bb9f8d

Please sign in to comment.