opto.trace.nodes.Graph.clear#
- Graph.clear()[source]#
Remove all nodes from the graph.
The clear function iterates over the current nodes stored in the _nodes attribute and deletes each node. After all nodes have been deleted, it reinitializes the _nodes attribute to an empty defaultdict of lists. This ensures that the graph is completely cleared and ready to be repopulated with new nodes if necessary.
Notes
After calling clear, any references to the previously stored nodes will become invalid. The function is called in unit tests to reset the state of the graph between test cases, ensuring that each test runs with a clean slate and is not affected by the state left by previous tests.