Skip to content

temporian.save_graph #

save_graph(
    inputs: Optional[graph.NamedEventSetNodes],
    outputs: graph.NamedEventSetNodes,
    path: str,
) -> None

Saves the graph between the inputs and outputs EventSetNodes to a file.

Usage example
>>> evset = tp.event_set(
...    timestamps=[1, 2, 3],
...    features={"input_feature": [0, 42, 10]}
... )

>>> # Create a graph
>>> a = evset.node()
>>> b = a.moving_sum(2)
>>> b = b.rename("result_feature")

>>> # Check evaluation
>>> b.run({a: evset})
indexes: []
features: [('result_feature', int64)]
events:
    (3 events):
        timestamps: [1. 2. 3.]
        'result_feature': [ 0 42 52]
...


>>> # Save the graph
>>> file_path = tmp_dir / "graph.tem"
>>> tp.save_graph(
...     inputs={"input_node": a},
...     outputs={"output_node": b},
...     path=file_path,
... )

>>> # Load the graph
>>> inputs, outputs = tp.load_graph(path=file_path)

>>> # Evaluate reloaded graph
>>> a_reloaded = inputs["input_node"]
>>> b_reloaded = outputs["output_node"]
>>> b_reloaded.run({a_reloaded: evset})
indexes: []
features: [('result_feature', int64)]
events:
    (3 events):
        timestamps: [1. 2. 3.]
        'result_feature': [ 0 42 52]
...

Parameters:

Name Type Description Default
inputs Optional[NamedEventSetNodes]

Input EventSetNodes. If None, the inputs is inferred. In this case, input EventSetNodes have to be named.

required
outputs NamedEventSetNodes

Output EventSetNodes.

required
path str

File path to save to.

required