-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9344 from lassewesth/misc1
migrate scaleproperties mutate
- Loading branch information
Showing
41 changed files
with
796 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
applications/algorithms/miscellaneous-algorithms/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
64 changes: 64 additions & 0 deletions
64
...ain/java/org/neo4j/gds/applications/algorithms/miscellaneous/MiscellaneousAlgorithms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...n/java/org/neo4j/gds/applications/algorithms/miscellaneous/MiscellaneousApplications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../gds/applications/algorithms/miscellaneous/MiscellaneousEstimationModeBusinessFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...eo4j/gds/applications/algorithms/miscellaneous/MiscellaneousMutateModeBusinessFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...n/java/org/neo4j/gds/applications/algorithms/miscellaneous/ScalePropertiesMutateStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.