cutcutcodec.core.edit.operation.remove

Allow to remove elements from the graph by managing collateral damage.

Functions

remove_edge(graph, edge)

Delete an edge from the graph.

remove_edges(graph, edges)

Delete several edges from the graph.

remove_element(graph, element)

Alias to cutcutcodec.core.edit.operation.remove.remove_elements.

remove_elements(graph, elements)

Delete several nodes or edges from the graph.

remove_node(graph, node)

Delete a node from the graph.

remove_nodes(graph, nodes)

Delete several nodes from the graph.

Details

cutcutcodec.core.edit.operation.remove.remove_edge(graph: MultiDiGraph, edge: tuple[str, str, str]) dict[tuple[str, str, str], None | tuple[str, str, str]][source]

Delete an edge from the graph.

Parameters

graphnetwork.MultiDiGraph

The assembly graph containing the edge to be deleted. The operations on this graph will be performed in-place.

edgetuple[str, str, str]

The name of the edge to delete from the graph (src_node, dst_node, key).

Returns

edgesdict

Each old edge name is associated with its new name. If the new name is None, it means that the edge has been deleted. This allows to be informed of all the operations performed.

Raises

KeyError

If the edge is not in the graph.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.edit.operation.remove import remove_edge
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> with ContainerInputFFMPEG(media) as container:
...     tree = ContainerOutput(container.out_streams)
...
>>> graph = tree_to_graph(tree)
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3')]
>>> pprint(remove_edge(graph, ('container_input_ffmpeg_1', 'container_output_1', '1->1')))
{('container_input_ffmpeg_1', 'container_output_1', '1->1'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'): ('container_input_ffmpeg_1',
                                                              'container_output_1',
                                                              '2->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'): ('container_input_ffmpeg_1',
                                                              'container_output_1',
                                                              '3->2')}
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->2')]
>>>
cutcutcodec.core.edit.operation.remove.remove_edges(graph: MultiDiGraph, edges: Iterable[tuple[str, str, str]]) dict[tuple[str, str, str], None | tuple[str, str, str]][source]

Delete several edges from the graph.

Parameters

graphnetwork.MultiDiGraph

The assembly graph containing the edges to be deleted. The operations on this graph will be performed in-place.

edgestyping.Iterable[tuple[str, str, str]]

The name of the edges to delete from the graph [(src_node, dst_node, key), …].

Returns

edgesdict

Each old edge name is associated with its new name. If the new name is None, it means that the edge has been deleted. This allows to be informed of all the operations performed.

Raises

KeyError

If one of the edges is not in the graph.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.edit.operation.remove import remove_edges
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> with ContainerInputFFMPEG(media) as container:
...     tree = ContainerOutput(container.out_streams)
...
>>> graph = tree_to_graph(tree)
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3')]
>>> pprint(remove_edges(
...     graph,
...     [
...         ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
...         ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
...     ],
... ))
{('container_input_ffmpeg_1', 'container_output_1', '1->1'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'): ('container_input_ffmpeg_1',
                                                              'container_output_1',
                                                              '3->1')}
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->1')]
>>>
cutcutcodec.core.edit.operation.remove.remove_element(graph: MultiDiGraph, element: str | tuple[str, str, str]) dict[str | tuple[str, str, str], None | tuple[str, str, str]][source]

Alias to cutcutcodec.core.edit.operation.remove.remove_elements.

cutcutcodec.core.edit.operation.remove.remove_elements(graph: MultiDiGraph, elements: Iterable[str | tuple[str, str, str]]) dict[str | tuple[str, str, str], None | tuple[str, str, str]][source]

Delete several nodes or edges from the graph.

Parameters

graphnetwork.MultiDiGraph

The assembly graph containing the nodes and edges to be deleted. The operations on this graph will be performed in-place.

elementstyping.Iterable[str | tuple[str, str, str]]

The name of nodes and edges to delete from the graph.

Returns

transformationsdict

Each old edge or node name is associated with its new name. If the new name is None, it means that the element has been deleted. This allows to be informed of all the operations performed.

Raises

KeyError

If one of the elements is not in the graph.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.edit.operation.remove import remove_elements
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> with (
...     ContainerInputFFMPEG(media) as container_1,
...     ContainerInputFFMPEG(media) as container_2,
... ):
...     tree = ContainerOutput([*container_1.out_streams, *container_2.out_streams])
...
>>> graph = tree_to_graph(tree)
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'),
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->7')]
>>> pprint(list(graph.nodes))
['container_output_1', 'container_input_ffmpeg_1', 'container_input_ffmpeg_2']
>>> pprint(remove_elements(
...     graph,
...     ["container_input_ffmpeg_1", ('container_input_ffmpeg_2', 'container_output_1', '1->5')]
... ))
{'container_input_ffmpeg_1': None,
 ('container_input_ffmpeg_1', 'container_output_1', '0->0'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '0->0'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '2->1'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->7'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '3->2')}
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_2', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->1'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->2')]
>>> pprint(list(graph.nodes))
['container_output_1', 'container_input_ffmpeg_2']
>>>
cutcutcodec.core.edit.operation.remove.remove_node(graph: MultiDiGraph, node: str) dict[str | tuple[str, str, str], None | tuple[str, str, str]][source]

Delete a node from the graph.

Also deletes the edges linked to this node.

Parameters

graphnetwork.MultiDiGraph

The assembly graph containing the node to be deleted. The operations on this graph will be performed in-place.

nodestr

The name of the node to delete from the graph.

Returns

transformationsdict

Each old edge or node name is associated with its new name. If the new name is None, it means that the element has been deleted. This allows to be informed of all the operations performed.

Raises

KeyError

If the node is not in the graph.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.edit.operation.remove import remove_node
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> with (
...     ContainerInputFFMPEG(media) as container_1,
...     ContainerInputFFMPEG(media) as container_2,
... ):
...     tree = ContainerOutput([*container_1.out_streams, *container_2.out_streams])
...
>>> graph = tree_to_graph(tree)
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'),
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->7')]
>>> pprint(list(graph.nodes))
['container_output_1', 'container_input_ffmpeg_1', 'container_input_ffmpeg_2']
>>> pprint(remove_node(graph, "container_input_ffmpeg_1"))
{'container_input_ffmpeg_1': None,
 ('container_input_ffmpeg_1', 'container_output_1', '0->0'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '0->0'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '1->1'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '2->2'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->7'): ('container_input_ffmpeg_2',
                                                              'container_output_1',
                                                              '3->3')}
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_2', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->3')]
>>> pprint(list(graph.nodes))
['container_output_1', 'container_input_ffmpeg_2']
>>>
cutcutcodec.core.edit.operation.remove.remove_nodes(graph: MultiDiGraph, nodes: Iterable[str]) dict[str | tuple[str, str, str], None | tuple[str, str, str]][source]

Delete several nodes from the graph.

Parameters

graphnetwork.MultiDiGraph

The assembly graph containing the nodes to be deleted. The operations on this graph will be performed in-place.

nodestyping.Iterable[str]

The name of the nodes to delete from the graph.

Returns

transformationsdict

Each old edge or node name is associated with its new name. If the new name is None, it means that the element has been deleted. This allows to be informed of all the operations performed.

Raises

KeyError

If one of the nodes is not in the graph.

Examples

>>> from pprint import pprint
>>> from cutcutcodec.core.classes.container import ContainerOutput
>>> from cutcutcodec.core.compilation.tree_to_graph import tree_to_graph
>>> from cutcutcodec.core.edit.operation.remove import remove_nodes
>>> from cutcutcodec.core.io.read_ffmpeg import ContainerInputFFMPEG
>>> from cutcutcodec.utils import get_project_root
>>> media = get_project_root() / "media" / "video" / "intro.webm"
>>> with (
...     ContainerInputFFMPEG(media) as container_1,
...     ContainerInputFFMPEG(media) as container_2,
...     ContainerInputFFMPEG(media) as container_3,
... ):
...     tree = ContainerOutput(
...         [*container_1.out_streams, *container_2.out_streams, *container_3.out_streams]
...     )
...
>>> graph = tree_to_graph(tree)
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_1', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'),
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'),
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'),
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'),
 ('container_input_ffmpeg_2', 'container_output_1', '3->7'),
 ('container_input_ffmpeg_3', 'container_output_1', '0->8'),
 ('container_input_ffmpeg_3', 'container_output_1', '1->9'),
 ('container_input_ffmpeg_3', 'container_output_1', '2->10'),
 ('container_input_ffmpeg_3', 'container_output_1', '3->11')]
>>> pprint(list(graph.nodes))
['container_output_1',
 'container_input_ffmpeg_1',
 'container_input_ffmpeg_2',
 'container_input_ffmpeg_3']
>>> pprint(remove_nodes(graph, ["container_input_ffmpeg_1", "container_input_ffmpeg_2"]))
{'container_input_ffmpeg_1': None,
 'container_input_ffmpeg_2': None,
 ('container_input_ffmpeg_1', 'container_output_1', '0->0'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '1->1'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '2->2'): None,
 ('container_input_ffmpeg_1', 'container_output_1', '3->3'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '0->4'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '1->5'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '2->6'): None,
 ('container_input_ffmpeg_2', 'container_output_1', '3->7'): None,
 ('container_input_ffmpeg_3', 'container_output_1', '0->8'): ('container_input_ffmpeg_3',
                                                              'container_output_1',
                                                              '0->0'),
 ('container_input_ffmpeg_3', 'container_output_1', '1->9'): ('container_input_ffmpeg_3',
                                                              'container_output_1',
                                                              '1->1'),
 ('container_input_ffmpeg_3', 'container_output_1', '2->10'): ('container_input_ffmpeg_3',
                                                               'container_output_1',
                                                               '2->2'),
 ('container_input_ffmpeg_3', 'container_output_1', '3->11'): ('container_input_ffmpeg_3',
                                                               'container_output_1',
                                                               '3->3')}
>>> pprint(list(graph.edges))
[('container_input_ffmpeg_3', 'container_output_1', '0->0'),
 ('container_input_ffmpeg_3', 'container_output_1', '1->1'),
 ('container_input_ffmpeg_3', 'container_output_1', '2->2'),
 ('container_input_ffmpeg_3', 'container_output_1', '3->3')]
>>> pprint(list(graph.nodes))
['container_output_1', 'container_input_ffmpeg_3']
>>>