replace

Applicable Products

All processors

Function Usage

Replaces the subgraph described by boundary with replacement. This is a static method.

Prototype

1
2
@staticmethod
replace(boundary: SubgraphBoundary, replacement: Graph) -> int

Parameters

Parameter

Input/Output

Description

boundary

Input

Subgraph boundary, which is of the SubgraphBoundary type. It describes the input or output of the subgraph to be replaced.

replacement

Input

Replacement graph, which is of the ge.graph.Graph type.

Returns

Type

Description

int

The integer form of the C++ Status. In case of failure, check the logs for information about boundary integrity and index alignment.

Restrictions

The replacement must be a non-empty graph wrapper. The graph will be copied on the C++ side, but you must still follow GE's ownership rules for Python graph objects.

Example

1
2
3
4
5
6
7
from ge.passes import SubgraphBoundary, SubgraphInput, SubgraphOutput, SubgraphRewriter

# n0 and out_node are existing nodes in the main graph, and replacement_graph is the constructed replacement graph.
b = SubgraphBoundary()
b.add_input(0, SubgraphInput([(n0, 0), (n0, 1)]))
b.add_output(0, SubgraphOutput(out_node, 0))
ret = SubgraphRewriter.replace(b, replacement_graph)