Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
3.4 consistent signature across algorithms (#836)
Browse files Browse the repository at this point in the history
* use writeProperty consistently across algorithms 
* new and old keys

* add write property to SCC

* add write property to UnionFind

* add write property to Label Propagation

* override 3rd parameter of LPA so that it can be the same as all the other algos

* some places I missed for SCC

* update docs to reflect writeProperty changes
  • Loading branch information
mneedham committed Mar 13, 2019
1 parent d847f82 commit fee6aa9
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 45 deletions.
28 changes: 21 additions & 7 deletions algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public final class LabelPropagationProc {

public static final String CONFIG_WEIGHT_KEY = "weightProperty";
public static final String CONFIG_WRITE_KEY = "writeProperty";
public static final String CONFIG_PARTITION_KEY = "partitionProperty";
public static final Integer DEFAULT_ITERATIONS = 1;
public static final Boolean DEFAULT_WRITE = Boolean.TRUE;
Expand All @@ -73,23 +74,36 @@ public final class LabelPropagationProc {
public Stream<LabelPropagationStats> labelPropagation(
@Name(value = "label", defaultValue = "") String label,
@Name(value = "relationship", defaultValue = "") String relationshipType,
@Name(value = "direction", defaultValue = "OUTGOING") String directionName,
@Name(value = "config", defaultValue = "{}") Map<String, Object> config) {
@Name(value = "config", defaultValue="null") Object directionOrConfig,
@Name(value = "deprecatedConfig", defaultValue = "{}") Map<String, Object> config) {
Map<String, Object> rawConfig = config;
if (directionOrConfig == null) {
if (!config.isEmpty()) {
directionOrConfig = "OUTGOING";
}
} else if (directionOrConfig instanceof Map) {
rawConfig = (Map<String, Object>) directionOrConfig;
}

final ProcedureConfiguration configuration = ProcedureConfiguration.create(config)
final ProcedureConfiguration configuration = ProcedureConfiguration.create(rawConfig)
.overrideNodeLabelOrQuery(label)
.overrideRelationshipTypeOrQuery(relationshipType)
.overrideDirection(directionName);
.overrideRelationshipTypeOrQuery(relationshipType);

if(directionOrConfig instanceof String) {
configuration.overrideDirection((String) directionOrConfig);
}

final int iterations = configuration.getIterations(DEFAULT_ITERATIONS);
final int batchSize = configuration.getBatchSize();
final int concurrency = configuration.getConcurrency();
final String partitionProperty = configuration.getString(CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY);
final String writeProperty = configuration.get(CONFIG_WRITE_KEY, CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY);
final String weightProperty = configuration.getString(CONFIG_WEIGHT_KEY, DEFAULT_WEIGHT_KEY);

LabelPropagationStats.Builder stats = new LabelPropagationStats.Builder()
.iterations(iterations)
.partitionProperty(partitionProperty)
.writeProperty(writeProperty)
.weightProperty(weightProperty);

GraphLoader graphLoader = graphLoader(configuration, partitionProperty, weightProperty, createPropertyMappings(partitionProperty, weightProperty));
Expand All @@ -109,9 +123,9 @@ public Stream<LabelPropagationStats> labelPropagation(
}

final int[] labels = compute(direction, iterations, batchSize, concurrency, graph, stats);
if (configuration.isWriteFlag(DEFAULT_WRITE) && partitionProperty != null) {
if (configuration.isWriteFlag(DEFAULT_WRITE) && writeProperty != null) {
stats.withWrite(true);
write(concurrency, partitionProperty, graph, labels, stats);
write(concurrency, writeProperty, graph, labels, stats);
}

return Stream.of(stats.build(graph.nodeCount(), l -> (long) labels[(int) l]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
*/
public class StronglyConnectedComponentsProc {

public static final String CONFIG_WRITE_PROPERTY = "partitionProperty";
public static final String CONFIG_WRITE_PROPERTY = "writeProperty";
public static final String CONFIG_OLD_WRITE_PROPERTY = "partitionProperty";
public static final String CONFIG_CLUSTER = "partition";

@Context
Expand Down Expand Up @@ -124,7 +125,7 @@ public Stream<SCCResult> sccTarjan(
final int[] connectedComponents = tarjan.getConnectedComponents();
if (configuration.isWriteFlag()) {
builder.withWrite(true);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
builder.withPartitionProperty(partitionProperty);

builder.timeWrite(() -> {
Expand Down Expand Up @@ -179,7 +180,7 @@ public Stream<SCCResult> sccTunedTarjan(

if (configuration.isWriteFlag()) {
builder.withWrite(true);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
builder.withPartitionProperty(partitionProperty);

builder.timeWrite(() -> Exporter
Expand Down Expand Up @@ -261,8 +262,8 @@ public Stream<SCCResult> sccIterativeTarjan(

if (configuration.isWriteFlag()) {
builder.withWrite(true);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
builder.withPartitionProperty(partitionProperty);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
builder.withPartitionProperty(partitionProperty).withWriteProperty(partitionProperty);

builder.timeWrite(() -> write(configuration, graph, terminationFlag, tarjan, partitionProperty));
}
Expand Down Expand Up @@ -382,7 +383,7 @@ public Stream<SCCResult> multistep(
multistep.release();
builder.timeWrite(() -> {
builder.withWrite(true);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
builder.withPartitionProperty(partitionProperty);

Exporter
Expand Down
27 changes: 20 additions & 7 deletions algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
public final class UnionFindProcExec implements BiConsumer<String, Algorithm<?>> {

private static final String CONFIG_THRESHOLD = "threshold";
private static final String CONFIG_CLUSTER_PROPERTY = "partitionProperty";
private static final String CONFIG_CLUSTER_PROPERTY = "writeProperty";
private static final String CONFIG_OLD_CLUSTER_PROPERTY = "partitionProperty";
private static final String DEFAULT_CLUSTER_PROPERTY = "partition";


Expand Down Expand Up @@ -86,9 +87,9 @@ public static Stream<UnionFindResult> run(
graph.release();

if (configuration.isWriteFlag()) {
String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY);
String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, CONFIG_OLD_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY);
builder.withWrite(true);
builder.withPartitionProperty(writeProperty);
builder.withPartitionProperty(writeProperty).withWriteProperty(writeProperty);

uf.write(builder::timeWrite, graph, dssResult, configuration, writeProperty);
}
Expand Down Expand Up @@ -119,7 +120,7 @@ public static class UnionFindResult {
-1,
-1,
-1,
false, null);
false, null, null);

public final long loadMillis;
public final long computeMillis;
Expand All @@ -140,9 +141,12 @@ public static class UnionFindResult {
public final long p100;
public final boolean write;
public final String partitionProperty;
public final String writeProperty;


public UnionFindResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount, long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, boolean write, String partitionProperty) {
public UnionFindResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount,
long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, boolean write,
String partitionProperty, String writeProperty) {
this.loadMillis = loadMillis;
this.computeMillis = computeMillis;
this.writeMillis = writeMillis;
Expand All @@ -161,11 +165,13 @@ public UnionFindResult(long loadMillis, long computeMillis, long postProcessingM
this.p1 = p1;
this.write = write;
this.partitionProperty = partitionProperty;
this.writeProperty = writeProperty;
}
}

public static class Builder extends AbstractCommunityResultBuilder<UnionFindResult> {
private String partitionProperty;
private String writeProperty;

@Override
protected UnionFindResult build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
Expand All @@ -187,13 +193,20 @@ protected UnionFindResult build(long loadMillis, long computeMillis, long writeM
communityHistogram.getValueAtPercentile(5),
communityHistogram.getValueAtPercentile(1),
write,
partitionProperty
partitionProperty,
writeProperty
);
}

public Builder withPartitionProperty(String partitionProperty) {
this.partitionProperty = partitionProperty;
return null;
return this;
}


public Builder withWriteProperty(String writeProperty) {
this.writeProperty = writeProperty;
return this;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class LabelPropagationStats {
false,
false,
"<empty>",
"<empty>");
"<empty>", "<empty>");

public final long loadMillis;
public final long computeMillis;
Expand All @@ -70,10 +70,11 @@ public class LabelPropagationStats {
public final String weightProperty;
public final boolean write;
public final String partitionProperty;
public final String writeProperty;

public LabelPropagationStats(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes,
long communityCount, long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, long iterations, boolean write, boolean didConverge,
String weightProperty, String partitionProperty) {
String weightProperty, String partitionProperty, String writeProperty) {
this.loadMillis = loadMillis;
this.computeMillis = computeMillis;
this.postProcessingMillis = postProcessingMillis;
Expand All @@ -95,6 +96,7 @@ public LabelPropagationStats(long loadMillis, long computeMillis, long postProce
this.didConverge = didConverge;
this.weightProperty = weightProperty;
this.partitionProperty = partitionProperty;
this.writeProperty = writeProperty;
}


Expand All @@ -104,6 +106,7 @@ public static class Builder extends AbstractCommunityResultBuilder<LabelPropagat
private boolean didConverge = false;
private String weightProperty;
private String partitionProperty;
private String writeProperty;

public Builder iterations(final long iterations) {
this.iterations = iterations;
Expand All @@ -124,6 +127,11 @@ public Builder partitionProperty(final String partitionProperty) {
this.partitionProperty = partitionProperty;
return this;
}
public Builder writeProperty(final String writeProperty) {
this.writeProperty = writeProperty;
return this;
}


@Override
protected LabelPropagationStats build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
Expand All @@ -148,7 +156,8 @@ protected LabelPropagationStats build(long loadMillis, long computeMillis, long
write,
didConverge,
weightProperty,
partitionProperty
partitionProperty,
writeProperty
);
}

Expand Down
14 changes: 11 additions & 3 deletions algo/src/main/java/org/neo4j/graphalgo/results/SCCResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SCCResult {

public static SCCResult EMPTY = new SCCResult(
0, 0, 0, 0,0, 0, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0,
false, null);
false, null, null);

public final long loadMillis;
public final long computeMillis;
Expand All @@ -51,10 +51,11 @@ public class SCCResult {
public final long p100;
public final boolean write;
public final String partitionProperty;
public final String writeProperty;

public SCCResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount,
long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1,
long minSetSize, long maxSetSize, boolean write, String partitionProperty) {
long minSetSize, long maxSetSize, boolean write, String partitionProperty, String writeProperty) {
this.loadMillis = loadMillis;
this.computeMillis = computeMillis;
this.postProcessingMillis = postProcessingMillis;
Expand All @@ -75,6 +76,7 @@ public SCCResult(long loadMillis, long computeMillis, long postProcessingMillis,
this.maxSetSize = maxSetSize;
this.write = write;
this.partitionProperty = partitionProperty;
this.writeProperty = writeProperty;
}

public static Builder builder() {
Expand All @@ -83,6 +85,7 @@ public static Builder builder() {

public static final class Builder extends AbstractCommunityResultBuilder<SCCResult> {
private String partitionProperty;
private String writeProperty;

@Override
protected SCCResult build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
Expand All @@ -106,14 +109,19 @@ protected SCCResult build(long loadMillis, long computeMillis, long writeMillis,
communityHistogram.getMinNonZeroValue(),
communityHistogram.getMaxValue(),
write,
partitionProperty
partitionProperty, writeProperty
);
}

public Builder withPartitionProperty(String partitionProperty) {
this.partitionProperty = partitionProperty;
return this;
}

public Builder withWriteProperty(String writeProperty) {
this.writeProperty = writeProperty;
return this;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ public <V> V get(String key, V defaultValue) {
return (V) value;
}

public <V> V get(String newKey, String oldKey, V defaultValue) {
Object value = config.get(newKey);
if (null == value) {
value = config.get(oldKey);
if(null == value) {
return defaultValue;
}
}
return (V) value;
}

public static ProcedureConfiguration create(Map<String, Object> config) {
return new ProcedureConfiguration(config);
}
Expand Down Expand Up @@ -415,4 +426,6 @@ public DuplicateRelationshipsStrategy getDuplicateRelationshipsStrategy() {
String strategy = get("duplicateRelationships", null);
return strategy != null ? DuplicateRelationshipsStrategy.valueOf(strategy.toUpperCase()) : DuplicateRelationshipsStrategy.NONE;
}


}
6 changes: 3 additions & 3 deletions doc/asciidoc/connected-components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ include::scripts/connected-components.cypher[tag=cypher-loading]
[source, cypher]
----
CALL algo.unionFind(label:String, relationship:String, {threshold:0.42,
defaultValue:1.0, write: true, partitionProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4})
defaultValue:1.0, write: true, writeProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4})
YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
----

Expand All @@ -221,7 +221,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
| relationship | string | null | yes | The relationship-type to load from the graph. If null, load all relationships
| weightProperty | string | null | yes | The property name that contains weight. If null, treats the graph as unweighted. Must be numeric.
| write | boolean | true | yes | Specifies if the result should be written back as a node property
| partitionProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to
| writeProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to
| threshold | float | null | yes | The value of the weight above which the relationship is not thrown away
| defaultValue | float | null | yes | The default value of the weight in case it is missing or invalid
| concurrency | int | available CPUs | yes | The number of concurrent threads
Expand Down Expand Up @@ -252,7 +252,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
| p100 | double | The 100 percentile of community size.

| write | boolean | Specifies if the result was written back as a node property
| partitionProperty | string | The property name written back to
| writeProperty | string | The property name written back to
|===


Expand Down
Loading

0 comments on commit fee6aa9

Please sign in to comment.