API
Graph Generation
- pargraph.graph(function: Callable) Graphable
Graph decorator
Note
There are a few assumptions when decorating a function with the graph decorator:
The function must have a return annotation
Variadic positional and/or keyword arguments are not supported
Function must not have any side effects
Function must be comprised of other graph or delayed functions
- Parameters:
function – function to decorate
- Returns:
decorated function
- pargraph.delayed(function: Callable) Graphable
Delayed decorator
Note
There are a few assumptions when decorating a function with the delayed decorator:
The function must have a return annotation
Variadic positional arguments are supported, but must not contain other named arguments
Function must not have any side effects
- Parameters:
function – function to decorate
- Returns:
decorated function
- class pargraph.Result(name: str)
Annotate a function output with a name
@delayed def my_function() -> Annotated[str, Result("my_output")]: return "Hello, World!"
- get_name() str
Get result name
- Returns:
result name
- class pargraph.graph.decorators.Graphable
- __call__(*args, **kwargs) Any
Call the function with the given arguments
- Parameters:
args – positional arguments to the function
kwargs – keyword arguments to the function
- Returns:
result of the function
- class pargraph.graph.objects.Graph
Graph representation
- static from_json(data: Dict) Graph
Create graph from json serializable dictionary by inferring the graph type
- Parameters:
data – graph dict
- Returns:
graph
- static from_json_with_edge_list(data: Dict) Graph
Create graph from json serializable dictionary with edge list
- Parameters:
data – graph dict with edge list
- Returns:
graph
- static from_json_with_node_arguments(data: Dict) Graph
Create graph from json serializable dictionary with node arguments
- Parameters:
data – graph dict with node arguments
- Returns:
graph
- to_json() Dict[str, Any]
Convert graph representation to json serializable dictionary
- Returns:
json serializable dictionary
- to_dict(*args, **kwargs) Tuple[Dict[str, Any], List[str]]
Convert graph to dict graph
Dict graph representation:
{ "a": 1, "b": 2, "sum": (add, "a", "b") }
Values can be:
Tasks: represented as tuples with the format
(fn, *args)
Constants: all other values
- Parameters:
args – positional arguments
kwargs – keyword arguments
- Returns:
dict graph and output keys
- to_dask(*args, **kwargs) Tuple[Dict[str, Any], List[str]]
Convert graph to dask graph
Warning
This method is deprecated and will be removed in a future release. Please use
to_dict()
instead.- Parameters:
args – positional arguments
kwargs – keyword arguments
- Returns:
dask graph and output keys
- to_dot(rankdir: Literal['LR', 'RL', 'TB', 'BT'] = 'LR', no_input: bool = False, no_const: bool = False, no_output: bool = False) Dot
Generate dot graph from graph
- Parameters:
rankdir – rank direction (“LR”, “RL”, “TB”, “BT”)
no_input – do not include input nodes
no_const – do not include const nodes
no_output – do not include output nodes
- Returns:
dot graph
- stabilize(depth: int = -1) Graph
Stabilize the graph’s node names to ensure the resulting graph is deterministic
Note
This method mutates the graph
- Parameters:
depth – depth to stabilize subgraphs, default is -1 (stabilize all subgraphs)
- Returns:
stabilized graph
Graph Engine
- class pargraph.GraphEngine(backend: Backend | None = None)
- set_parallel_backend(backend: Backend) None
Set parallel backend
- Parameters:
backend – parallel backend to use
- get(graph: Dict, keys: Any, **kwargs) Any
Compute dict graph
- Parameters:
graph – dict graph
keys – keys to compute (e.g.
"x"
,["x", "y", "z"]
, etc)kwargs – keyword arguments to forward to the parallel backend
- Returns:
results in the same structure as keys