---
title: "TracedGraph"
sidebar_label: "TracedGraph"
description: "The clika_runtime TracedGraph class."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

The result of :func:`trace`: the recorded graph as :attr:`graph`, the
    structure of the traced inputs and outputs, and the graph's own surface
    (``run``, ``input_names``, ``output_names``, ``nodes``, ...) reachable
    directly on this object.

    ``run`` takes the flattened tensor inputs positionally (a list) or by
    name (a dict) and returns the graph's output list; calling the object
    takes the traced input structure and returns the traced output
    structure. The graph arrives as recorded: ``optimize()``, ``to()`` and
    ``finalize()`` reach it through this object, and only a finalized graph
    runs.
    

## `in_spec` (property)

The pytree structure of the traced ``(args, kwargs)``; ``None``
when the trace ran against a signature alone.

## `out_spec` (property)

The pytree structure of the traced result.

## `__init__`

```python
__init__(self, graph: '_io.ModelGraph', in_spec: 'TreeSpec | None', outputs: '_Outputs') -> 'None'
```

Initialize self.  See help(type(self)) for accurate signature.

## `finalize`

```python
finalize(self) -> 'None'
```

finalize() -> None

Ready the graph to run (:meth:`~clika_runtime.io.ModelGraph.finalize`);
calling it again changes nothing.

## `is_finalized`

```python
is_finalized(self) -> 'bool'
```

is_finalized() -> bool

True once :meth:`finalize` ran; a trace returns a graph that is not
finalized yet.

## `optimize`

```python
optimize(self, transforms: 'Sequence[Transform] | None' = None, max_num_iterations: 'int | None' = None, *, defaults: '_io.DefaultsOptions | None' = None) -> '_io.OptimizeReport'
```

optimize(transforms=None, max_num_iterations=None, *, defaults=None) -> OptimizeReport

Run the graph optimizer on the recorded graph
(:meth:`~clika_runtime.io.ModelGraph.optimize`); ``max_num_iterations``
None takes the graph's default cap.

## `run`

```python
run(self, inputs: 'Sequence[Tensor] | Mapping[str, Tensor]') -> 'list[Tensor]'
```

run(inputs) -> list[Tensor]

Run the traced graph on flat tensor inputs and return its flat
outputs: a sequence feeds the inputs in signature order, a mapping
feeds them by input name. ``__call__`` is the structured form.

## `to`

```python
to(self, where: 'Device | Stream | str') -> 'None'
```

to(where) -> None

Choose where the graph runs, or move a finalized graph
(:meth:`~clika_runtime.io.ModelGraph.to`).
