View source on GitHub |
Whether a given order of operations is consistent with the DAG.
cirq.contrib.acquaintance.is_topologically_sorted(
dag: 'cirq.contrib.CircuitDag',
operations: 'cirq.OP_TREE',
equals: Callable[[cirq.Operation
, cirq.Operation
], bool] = operator.eq
) -> bool
For example, suppose the (transitive reduction of the) circuit DAG is
╭─> Op2 ─╮
Op1 ─┤ ├─> Op4 ╰─> Op3 ─╯
Then [Op1, Op2, Op3, Op4] and Op1, Op3, Op2, Op4 are topologically sorted according to the DAG, and any other ordering of the four operations is not.
Evaluates to False when the set of operations is different from those in the nodes of the DAG, regardless of the ordering.
Args | |
---|---|
dag
|
The circuit DAG. |
operations
|
The ordered operations. |
equals
|
The function to determine equality of operations. Defaults to
operator.eq .
|
Returns | |
---|---|
Whether or not the operations given are topologically sorted according to the DAG. |