19.4. Graphs

class popxl.Graph

Construct a Graph object.

The Graph class represents graphs in the PopART IR.

This class cannot be instantiated using the constructor. Graph instances are created by the Ir class. During construction, each Ir constructs a default main graph. More Graph instances can be made using the create_graph() method of the Ir class.


TypeError – If an attempt is made to create an object of this class.

property called_graphs: Tuple[popxl.graph.Graph, ...]

Return all Graphs called by ops in the graph.

property constants: Tuple[popxl.tensor.Constant, ...]

Return all constant tensors in the graph.


Get tensor using string identifier tensor_id.


tensor_id (str) –

Return type


property id: str
property inputs: Tuple[popxl.tensor.Tensor, ...]

Get the input tensors of the graph.


A tuple of all the input tensors.

Return type

Dict[Tensor, …]

property inputs_by_name: Dict[str, popxl.tensor.Tensor]

Get the input tensors of the graph as a dictionary.


A dict that maps tensor name to tensor

Return type

Dict[str, Tensor]

property ir: Ir
property main_graph: popxl.graph.Graph
property name: str
property outputs: Tuple[popxl.tensor.Tensor, ...]

Get the output tensors of the graph.


A tuple of all the output tensors.

Return type

Tuple[Tensor, …]


Register a function to be called after an op is created in the graph.


fn (Callable[[_ir.Op], Any]) – Function to be called.


Hook handle. Can be passed to Graph.remove_op_created_hook to remove the hook.

Return type



Remove an op created hook. handle should be the result of calling Graph.register_op_created_hook.


handle (int) – Handle to an op-created hook.

property tensors: Tuple[popxl.tensor.Tensor, ...]

Return all tensors in the graph.

property variables: Tuple[popxl.tensor.Variable, ...]

Return all variable tensors in the graph.