Skip to content

Commit

Permalink
migrate KNN estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Apr 19, 2024
1 parent 936efd0 commit cefa83b
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.neo4j.gds.similarity.filteredknn.FilteredKnnMemoryEstimateDefinition;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityBaseConfig;
import org.neo4j.gds.similarity.filterednodesim.FilteredNodeSimilarityMemoryEstimateDefinition;
import org.neo4j.gds.similarity.knn.KnnBaseConfig;
import org.neo4j.gds.similarity.knn.KnnMemoryEstimateDefinition;
import org.neo4j.gds.similarity.nodesim.NodeSimilarityBaseConfig;
import org.neo4j.gds.similarity.nodesim.NodeSimilarityMemoryEstimateDefinition;

Expand Down Expand Up @@ -63,18 +61,6 @@ public <C extends FilteredNodeSimilarityBaseConfig> MemoryEstimateResult filtere
);
}

public <C extends KnnBaseConfig> MemoryEstimateResult knn(
Object graphNameOrConfiguration,
C configuration
) {
return algorithmEstimator.estimate(
graphNameOrConfiguration,
configuration,
Optional.empty(),
new KnnMemoryEstimateDefinition(configuration.toMemoryEstimationParameters())
);
}

public <C extends FilteredKnnBaseConfig> MemoryEstimateResult filteredKnn(
Object graphNameOrConfiguration,
C configuration
Expand Down
1 change: 1 addition & 0 deletions applications/algorithms/machinery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation project(':core')
implementation project(':core-write')
implementation project(':logging')
implementation project(':memory-estimation')
implementation project(':memory-usage')
implementation project(':metrics-api')
implementation project(':progress-tracking')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
* 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.pathfinding;
package org.neo4j.gds.applications.algorithms.machinery;

import org.neo4j.gds.applications.algorithms.machinery.RequestScopedDependencies;
import org.neo4j.gds.applications.algorithms.machinery.GraphDimensionsComputer;
import org.neo4j.gds.api.GraphName;
import org.neo4j.gds.config.AlgoBaseConfig;
import org.neo4j.gds.config.GraphProjectConfig;
Expand All @@ -33,7 +31,6 @@
import org.neo4j.gds.memest.FictitiousGraphStoreEstimationService;
import org.neo4j.gds.memest.GraphMemoryEstimation;
import org.neo4j.gds.memest.MemoryEstimationGraphConfigParser;
import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult;

import java.util.Map;

Expand Down Expand Up @@ -63,7 +60,7 @@ public AlgorithmEstimationTemplate(
this.requestScopedDependencies = requestScopedDependencies;
}

<CONFIGURATION extends AlgoBaseConfig> MemoryEstimateResult estimate(
public <CONFIGURATION extends AlgoBaseConfig> MemoryEstimateResult estimate(
CONFIGURATION configuration,
Object graphNameOrConfiguration,
MemoryEstimation memoryEstimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.gds.applications.algorithms.pathfinding;

import org.neo4j.gds.applications.algorithms.machinery.AlgorithmEstimationTemplate;
import org.neo4j.gds.config.AlgoBaseConfig;
import org.neo4j.gds.core.utils.mem.MemoryEstimation;
import org.neo4j.gds.exceptions.MemoryEstimationNotImplementedException;
Expand Down Expand Up @@ -216,11 +217,11 @@ public MemoryEstimation steinerTreeEstimation(SteinerTreeBaseConfig configuratio
return new SteinerTreeMemoryEstimateDefinition(configuration.applyRerouting()).memoryEstimation();
}

public MemoryEstimation topologicalSortEstimation() {
MemoryEstimation topologicalSortEstimation() {
throw new MemoryEstimationNotImplementedException();
}

public <CONFIGURATION extends AlgoBaseConfig> MemoryEstimateResult runEstimation(
private <CONFIGURATION extends AlgoBaseConfig> MemoryEstimateResult runEstimation(
CONFIGURATION configuration,
Object graphNameOrConfiguration,
MemoryEstimation memoryEstimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,30 @@
*/
package org.neo4j.gds.applications.algorithms.similarity;

import org.neo4j.gds.applications.algorithms.machinery.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult;
import org.neo4j.gds.core.utils.mem.MemoryEstimation;
import org.neo4j.gds.similarity.knn.KnnBaseConfig;
import org.neo4j.gds.similarity.knn.KnnMemoryEstimateDefinition;

public class SimilarityAlgorithmsEstimationModeBusinessFacade {
private final AlgorithmEstimationTemplate algorithmEstimationTemplate;

public SimilarityAlgorithmsEstimationModeBusinessFacade(AlgorithmEstimationTemplate algorithmEstimationTemplate) {
this.algorithmEstimationTemplate = algorithmEstimationTemplate;
}

public MemoryEstimation knn(KnnBaseConfig knnMutateConfig) {
return new KnnMemoryEstimateDefinition(knnMutateConfig.toMemoryEstimationParameters()).memoryEstimation();
}

public MemoryEstimateResult knn(KnnBaseConfig configuration, Object graphNameOrConfiguration) {
var memoryEstimation = knn(configuration);

return algorithmEstimationTemplate.estimate(
configuration,
graphNameOrConfiguration,
memoryEstimation
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package org.neo4j.gds.applications;

import org.neo4j.gds.algorithms.similarity.WriteRelationshipService;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTemplate;
import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator;
import org.neo4j.gds.applications.algorithms.machinery.RequestScopedDependencies;
import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.graphstorecatalog.CatalogBusinessFacade;
import org.neo4j.gds.applications.graphstorecatalog.DefaultCatalogBusinessFacade;
import org.neo4j.gds.core.loading.GraphStoreCatalogService;
Expand Down Expand Up @@ -87,6 +87,7 @@ public static ApplicationsFacade create(

var similarityApplications = SimilarityApplications.create(
log,
algorithmEstimationTemplate,
algorithmProcessingTemplate,
progressTrackerCreator,
writeRelationshipService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTemplate;
import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator;
import org.neo4j.gds.applications.algorithms.machinery.RequestScopedDependencies;
import org.neo4j.gds.applications.algorithms.pathfinding.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingAlgorithms;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingAlgorithmsEstimationModeBusinessFacade;
import org.neo4j.gds.applications.algorithms.pathfinding.PathFindingAlgorithmsMutateModeBusinessFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.gds.applications;

import org.neo4j.gds.algorithms.similarity.WriteRelationshipService;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmEstimationTemplate;
import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTemplate;
import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator;
import org.neo4j.gds.applications.algorithms.similarity.SimilarityAlgorithms;
Expand Down Expand Up @@ -53,11 +54,12 @@ private SimilarityApplications(

static SimilarityApplications create(
Log log,
AlgorithmEstimationTemplate algorithmEstimationTemplate,
AlgorithmProcessingTemplate algorithmProcessingTemplate,
ProgressTrackerCreator progressTrackerCreator,
WriteRelationshipService writeRelationshipService
) {
var estimationModeFacade = new SimilarityAlgorithmsEstimationModeBusinessFacade();
var estimationModeFacade = new SimilarityAlgorithmsEstimationModeBusinessFacade(algorithmEstimationTemplate);
var similarityAlgorithms = new SimilarityAlgorithms(progressTrackerCreator);

var mutateModeFacade = new SimilarityAlgorithmsMutateModeBusinessFacade(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
return facade.similarity().knnStatsEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.similarity().theOtherFacade().knnStatsEstimate(graphNameOrConfiguration, algoConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
return facade.similarity().knnStreamEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.similarity().theOtherFacade().knnStreamEstimate(graphNameOrConfiguration, algoConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public Stream<MemoryEstimateResult> estimate(
@Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration,
@Name(value = "algoConfiguration") Map<String, Object> algoConfiguration
) {
return facade.similarity().knnWriteEstimate(graphNameOrConfiguration, algoConfiguration);
return facade.similarity().theOtherFacade().knnWriteEstimate(graphNameOrConfiguration, algoConfiguration);
}
}
Loading

0 comments on commit cefa83b

Please sign in to comment.