Skip to content

Commit

Permalink
Improve DAG API (#3703)
Browse files Browse the repository at this point in the history
Signed-off-by: Lehmann-Fabian <[email protected]>
Signed-off-by: Lehmann_Fabian <[email protected]>
  • Loading branch information
Lehmann-Fabian authored Mar 3, 2023
1 parent 1e38274 commit 21afb35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions modules/nextflow/src/main/groovy/nextflow/dag/DAG.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import nextflow.script.params.OutParam
import nextflow.script.params.OutputsList
import nextflow.script.params.TupleInParam
import nextflow.script.params.TupleOutParam

import java.util.concurrent.atomic.AtomicLong

/**
* Model a direct acyclic graph of the pipeline execution.
*
Expand Down Expand Up @@ -81,10 +84,8 @@ class DAG {
dataflowBroadcastLookup.put(readChannel, broadcastChannel)
}

@PackageScope
List<Vertex> getVertices() { vertices }

@PackageScope
List<Edge> getEdges() { edges }

boolean isEmpty() { edges.size()==0 && vertices.size()==0 }
Expand Down Expand Up @@ -378,9 +379,10 @@ class DAG {
* @author Paolo Di Tommaso <[email protected]>
*/
@ToString(includeNames = true, includes = 'label,type', includePackage=false)
@PackageScope
class Vertex {

static private AtomicLong nextID = new AtomicLong()

/**
* The vertex label
*/
Expand All @@ -398,6 +400,11 @@ class DAG {

TaskProcessor process

/**
* unique Id
*/
final long id = nextID.getAndIncrement()

/**
* Create a DAG vertex instance
*
Expand Down Expand Up @@ -433,11 +440,12 @@ class DAG {
*
* @author Paolo Di Tommaso <[email protected]>
*/
@PackageScope
@ToString(includeNames = true, includes = 'label,from,to', includePackage=false)
@MapConstructor
class Edge {

static private AtomicLong nextID = new AtomicLong()

/**
* The Dataflow channel that originated this graph edge
*/
Expand All @@ -458,6 +466,11 @@ class DAG {
*/
String label

/**
* unique Id
*/
final long id = nextID.getAndIncrement()

}

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/nextflow/src/test/groovy/nextflow/dag/DAGTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DAGTest extends Specification {
v2.order == 1
v2.name == 'p1'
v2.type == DAG.Type.OPERATOR
v1.id != v2.id
}


Expand Down Expand Up @@ -113,6 +114,8 @@ class DAGTest extends Specification {
v2.label == 'Process 2'
v2.order == 1

v1.id != v2.id

dag.edges.size() == 3

dag.edges[0].label == 'Channel 1'
Expand Down

0 comments on commit 21afb35

Please sign in to comment.