Skip to content

Commit

Permalink
Merge pull request #9344 from lassewesth/misc1
Browse files Browse the repository at this point in the history
migrate scaleproperties mutate
  • Loading branch information
lassewesth authored Jul 9, 2024
2 parents 30d2138 + d36ccfa commit 37141ba
Show file tree
Hide file tree
Showing 41 changed files with 796 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ public MiscAlgorithmMutateBusinessFacade(MiscAlgorithmsFacade miscAlgorithmsFaca
this.mutateNodePropertyService = mutateNodePropertyService;
}

public NodePropertyMutateResult<ScalePropertiesSpecificFields> scaleProperties(
String graphName,
ScalePropertiesMutateConfig configuration
) {
return scaleProperties(graphName,configuration,false);
}

public NodePropertyMutateResult<ScalePropertiesSpecificFields> alphaScaleProperties(
String graphName,
ScalePropertiesMutateConfig configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public enum Algorithm {
Node2Vec,
PageRank,
RandomWalk,
ScaleProperties,
SCC,
SingleSourceDijkstra,
SpanningTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum LabelForProgressTracking {
Node2Vec("Node2Vec"),
PageRank("PageRank"),
RandomWalk("RandomWalk"),
ScaleProperties("ScaleProperties"),
SCC("SCC"),
SingleSourceDijkstra("All Shortest Paths"),
SpanningTree("SpanningTree"),
Expand Down Expand Up @@ -114,6 +115,7 @@ public static LabelForProgressTracking from(Algorithm algorithm) {
case Node2Vec -> Node2Vec;
case PageRank -> PageRank;
case RandomWalk -> RandomWalk;
case ScaleProperties -> ScaleProperties;
case SCC -> SCC;
case SingleSourceDijkstra -> SingleSourceDijkstra;
case SpanningTree -> SpanningTree;
Expand Down
15 changes: 15 additions & 0 deletions applications/algorithms/miscellaneous-algorithms/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apply plugin: 'java-library'

description = 'Neo4j Graph Data Science :: Miscellaneous Applications'

group = 'org.neo4j.gds'

dependencies {
implementation project(":algo")
implementation project(":algo-common")
implementation project(":algorithms-machinery")
implementation project(":config-api")
implementation project(":core")
implementation project(":memory-usage")
implementation project(":progress-tracking")
}
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.applications.algorithms.miscellaneous;

import org.neo4j.gds.api.Graph;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery;
import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator;
import org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking;
import org.neo4j.gds.core.concurrency.DefaultPool;
import org.neo4j.gds.core.utils.progress.tasks.Tasks;
import org.neo4j.gds.scaleproperties.ScaleProperties;
import org.neo4j.gds.scaleproperties.ScalePropertiesMutateConfig;
import org.neo4j.gds.scaleproperties.ScalePropertiesResult;

public class MiscellaneousAlgorithms {
private final AlgorithmMachinery algorithmMachinery = new AlgorithmMachinery();

private final ProgressTrackerCreator progressTrackerCreator;

MiscellaneousAlgorithms(ProgressTrackerCreator progressTrackerCreator) {
this.progressTrackerCreator = progressTrackerCreator;
}

ScalePropertiesResult scaleProperties(Graph graph, ScalePropertiesMutateConfig configuration) {
int totalPropertyDimension = configuration
.nodeProperties()
.stream()
.map(graph::nodeProperties)
.mapToInt(p -> p.dimension().orElseThrow(/* already validated in config */))
.sum();
var task = Tasks.task(
LabelForProgressTracking.ScaleProperties.value,
Tasks.leaf("Prepare scalers", graph.nodeCount() * totalPropertyDimension),
Tasks.leaf("Scale properties", graph.nodeCount() * totalPropertyDimension)
);
var progressTracker = progressTrackerCreator.createProgressTracker(configuration, task);

var algorithm = new ScaleProperties(
graph,
configuration,
progressTracker,
DefaultPool.INSTANCE
);

return algorithmMachinery.runAlgorithmsAndManageProgressTracker(algorithm, progressTracker, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.applications.algorithms.miscellaneous;

import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTemplateConvenience;
import org.neo4j.gds.applications.algorithms.machinery.MutateNodeProperty;
import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator;

public final class MiscellaneousApplications {
private final MiscellaneousEstimationModeBusinessFacade estimation;
private final MiscellaneousMutateModeBusinessFacade mutation;

private MiscellaneousApplications(
MiscellaneousEstimationModeBusinessFacade estimation,
MiscellaneousMutateModeBusinessFacade mutation
) {
this.estimation = estimation;
this.mutation = mutation;
}

public static MiscellaneousApplications create(
AlgorithmProcessingTemplateConvenience algorithmProcessingTemplateConvenience,
ProgressTrackerCreator progressTrackerCreator,
MutateNodeProperty mutateNodeProperty
) {
var algorithms = new MiscellaneousAlgorithms(progressTrackerCreator);

var estimation = new MiscellaneousEstimationModeBusinessFacade();
var mutation = new MiscellaneousMutateModeBusinessFacade(
estimation,
algorithms,
algorithmProcessingTemplateConvenience,
mutateNodeProperty
);

return new MiscellaneousApplications(
estimation,
mutation
);
}

public MiscellaneousEstimationModeBusinessFacade estimate() {
return estimation;
}

public MiscellaneousMutateModeBusinessFacade mutate() {
return mutation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.applications.algorithms.miscellaneous;

import org.neo4j.gds.mem.MemoryEstimation;
import org.neo4j.gds.scaleproperties.ScalePropertiesBaseConfig;
import org.neo4j.gds.scaleproperties.ScalePropertiesMemoryEstimateDefinition;

public class MiscellaneousEstimationModeBusinessFacade {
public MemoryEstimation scaleProperties(ScalePropertiesBaseConfig configuration) {
return new ScalePropertiesMemoryEstimateDefinition(configuration.nodeProperties()).memoryEstimation();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.applications.algorithms.miscellaneous;

import org.neo4j.gds.api.GraphName;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTemplateConvenience;
import org.neo4j.gds.applications.algorithms.machinery.MutateNodeProperty;
import org.neo4j.gds.applications.algorithms.machinery.ResultBuilder;
import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten;
import org.neo4j.gds.scaleproperties.ScalePropertiesMutateConfig;
import org.neo4j.gds.scaleproperties.ScalePropertiesResult;

import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.ScaleProperties;

public class MiscellaneousMutateModeBusinessFacade {
private final MiscellaneousEstimationModeBusinessFacade estimation;
private final MiscellaneousAlgorithms algorithms;
private final AlgorithmProcessingTemplateConvenience algorithmProcessingTemplateConvenience;
private final MutateNodeProperty mutateNodeProperty;

MiscellaneousMutateModeBusinessFacade(
MiscellaneousEstimationModeBusinessFacade estimation,
MiscellaneousAlgorithms algorithms,
AlgorithmProcessingTemplateConvenience algorithmProcessingTemplateConvenience,
MutateNodeProperty mutateNodeProperty
) {
this.estimation = estimation;
this.algorithms = algorithms;
this.algorithmProcessingTemplateConvenience = algorithmProcessingTemplateConvenience;
this.mutateNodeProperty = mutateNodeProperty;
}

public <RESULT> RESULT scaleProperties(
GraphName graphName,
ScalePropertiesMutateConfig configuration,
ResultBuilder<ScalePropertiesMutateConfig, ScalePropertiesResult, RESULT, NodePropertiesWritten> resultBuilder
) {
var mutateStep = new ScalePropertiesMutateStep(mutateNodeProperty, configuration);

return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateOrWriteMode(
graphName,
configuration,
ScaleProperties,
() -> estimation.scaleProperties(configuration),
graph -> algorithms.scaleProperties(graph, configuration),
mutateStep,
resultBuilder
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.applications.algorithms.miscellaneous;

import org.neo4j.gds.algorithms.misc.ScaledPropertiesNodePropertyValues;
import org.neo4j.gds.api.Graph;
import org.neo4j.gds.api.GraphStore;
import org.neo4j.gds.api.ResultStore;
import org.neo4j.gds.applications.algorithms.machinery.MutateNodeProperty;
import org.neo4j.gds.applications.algorithms.machinery.MutateOrWriteStep;
import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten;
import org.neo4j.gds.core.utils.progress.JobId;
import org.neo4j.gds.scaleproperties.ScalePropertiesMutateConfig;
import org.neo4j.gds.scaleproperties.ScalePropertiesResult;

class ScalePropertiesMutateStep implements MutateOrWriteStep<ScalePropertiesResult, NodePropertiesWritten> {
private final MutateNodeProperty mutateNodeProperty;
private final ScalePropertiesMutateConfig configuration;

ScalePropertiesMutateStep(MutateNodeProperty mutateNodeProperty, ScalePropertiesMutateConfig configuration) {
this.mutateNodeProperty = mutateNodeProperty;
this.configuration = configuration;
}

@Override
public NodePropertiesWritten execute(
Graph graph,
GraphStore graphStore,
ResultStore resultStore,
ScalePropertiesResult result,
JobId jobId
) {
var nodePropertyValues = new ScaledPropertiesNodePropertyValues(
graph.nodeCount(),
result.scaledProperties()
);
return mutateNodeProperty.mutateNodeProperties(
graph,
graphStore,
configuration,
nodePropertyValues
);
}
}
1 change: 1 addition & 0 deletions applications/facade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation project(":memory-estimation")
implementation project(":metrics-api")
implementation project(":model-catalog-api")
implementation project(":miscellaneous-algorithms")
implementation project(":node-embedding-algorithms")
implementation project(":path-finding-algorithms")
implementation project(":progress-tracking")
Expand Down
Loading

0 comments on commit 37141ba

Please sign in to comment.