Skip to content

netlist_carpentry.vis.dynamic.ipycytoscape

Wrapper module for ipycytoscape, handling the creation of graph objects for Jupyter notebooks.

Classes:

  • GraphDataDict

    Format of a dictionary containing graph data.

  • CytoscapeGraph

    Interactive cytoscape graph visualization for Jupyter notebooks using ipycytoscape.

GraphDataDict

Bases: TypedDict

Format of a dictionary containing graph data.

Attributes:

  • ntype (Literal['PORT', 'INSTANCE']) –

    The node type. Either PORT or Instance.

  • nsubtype (str) –

    The node type, but more specific. input/output for ports, and the instance type for instances.

  • ndata (Union[Port[Module], Instance]) –

    The actual circuit object modeled by the node.

ntype instance-attribute

ntype: Literal['PORT', 'INSTANCE']

The node type. Either PORT or Instance.

nsubtype instance-attribute

nsubtype: str

The node type, but more specific. input/output for ports, and the instance type for instances.

ndata instance-attribute

The actual circuit object modeled by the node.

CytoscapeGraph

Bases: BaseModel

Interactive cytoscape graph visualization for Jupyter notebooks using ipycytoscape.

Methods:

  • apply_config

    Applies the given CytoscapeConfig to this instance's CytoscapeWidget.

  • update_format

    Reads the current format definitions, translates them into css and applies them as stylesheet to the CytoscapeWidget.

  • format_node

    Apply a given format to a given node.

  • format_nodes

    Applies the given format to all nodes that match the given predicate.

  • format_in_out

    Applies the given in_format to all input nodes and out_format to all output nodes.

  • get_node_map

    Returns a dictionary with node names mapped to ipycytoscape.Node objects.

  • get_node

    Returns the node object for the given node identifier.

  • get_node_element

    Returns the circuit object for the given node name.

  • get_edge_map

    Returns a dictionary with wire names mapped to ipycytoscape.Edge objects.

  • get_edge

    Returns the edge object for the given wire name.

  • toggle_label

    Toggles the label of the given node id or object.

  • show

    Create and return an ipycytoscape widget for display in Jupyter notebooks.

Attributes:

  • module_graph (ModuleGraph) –

    The ModuleGraph (i.e. the source graph) represented in this Cytoscape graph.

  • formats (Formats) –

    Contains all format definitons for this Cytoscape graph, along with a mapping of nodes to formats, and labels.

  • output (Output) –

    The output widget that handles output triggered by widget interaction.

  • cyto (CytoscapeWidget) –

    The CytoscapeWidget that contains the graph and properties.

  • info_box (HTML) –

    The info box widget containing data about the selected node.

module_graph instance-attribute

module_graph: ModuleGraph

The ModuleGraph (i.e. the source graph) represented in this Cytoscape graph.

formats class-attribute instance-attribute

formats: Formats = Formats(
    definitions={"node": DEFAULT_NODE, "edge": DEFAULT_EDGE}
)

Contains all format definitons for this Cytoscape graph, along with a mapping of nodes to formats, and labels.

output property

output: Output

The output widget that handles output triggered by widget interaction.

cyto property

cyto: CytoscapeWidget

The CytoscapeWidget that contains the graph and properties.

info_box property

info_box: HTML

The info box widget containing data about the selected node.

apply_config

apply_config(cfg: CytoscapeConfig) -> None

Applies the given CytoscapeConfig to this instance's CytoscapeWidget.

The CytoscapeConfig defines environment values like 'min_zoom'/'max_zoom' or 'panning_enabled' that handle how the rendered widget behaves. Unset values (i.e. values that are None) are ignored, and the previous settings are kept.

Parameters:

  • cfg

    (CytoscapeConfig) –

    The config object with the parameter values to set. Unset parameters (i.e. parameters that are None) are ignored, and the previous settings are kept.

update_format

update_format(nodes: Optional[List[Node]] = None) -> None

Reads the current format definitions, translates them into css and applies them as stylesheet to the CytoscapeWidget.

format_node

format_node(node_id: str, format_name: str) -> None

Apply a given format to a given node.

The node must exist in the module graph, otherwise an ObjectNotFoundError is raised.

Parameters:

  • node_id

    (str) –

    The node id of the node to format. Must exist in the module graph

  • format_name

    (str) –

    The name of the format. format_name='foo' will apply the format 'foo', which in css conforms to the class '.foo'.

Raises:

format_nodes

format_nodes(
    predicate: Callable[[str, GraphDataDict], bool], format_name: str
) -> None

Applies the given format to all nodes that match the given predicate.

The predicate is a callable (lambda or function) that takes two parameters, being the node name (string) and the node data (dictionary), while returning either True or False. If the condition is True for a given node, the given format is applied to this node.

Parameters:

  • predicate

    (Callable[[str, GraphDataDict], bool]) –

    A callable (lambda or function) that takes two parameters, being the node name (string) and the node data (dictionary), while returning either True or False.

  • format_name

    (str) –

    The format name to apply to all nodes that match the given condition.

format_in_out

format_in_out(
    *, in_format: Optional[str] = None, out_format: Optional[str] = None
) -> None

Applies the given in_format to all input nodes and out_format to all output nodes.

Parameters:

  • in_format

    (Optional[str], default: None ) –

    The name of the format to apply to all input nodes (i.e. input ports). Defaults to None.

  • out_format

    (Optional[str], default: None ) –

    The name of the format to apply to all output nodes (i.e. output ports). Defaults to None.

get_node_map

get_node_map() -> Dict[str, Node]

Returns a dictionary with node names mapped to ipycytoscape.Node objects.

get_node

get_node(node_id: str) -> Node

Returns the node object for the given node identifier.

Parameters:

  • node_id

    (str) –

    The node identifier, i.e. the node name in the graph.

Raises:

Returns:

  • Node ( Node ) –

    An ipycytoscape Node object whose identifier matches the given identifier.

get_node_element

get_node_element(node_id: str) -> Union[Instance, Port[Module]]

Returns the circuit object for the given node name.

Parameters:

  • node_id

    (str) –

    The node name for which the circuit object (Instance or Module Port) should be retrieved.

Raises:

Returns:

  • Union[Instance, Port[Module]]

    Union[Instance, Port[Module]]: The circuit object (Instance or Module Port) associated with the given node name.

get_edge_map

get_edge_map() -> Dict[str, Edge]

Returns a dictionary with wire names mapped to ipycytoscape.Edge objects.

get_edge

get_edge(wire_name: str) -> Edge

Returns the edge object for the given wire name.

Parameters:

  • wire_name

    (str) –

    The wire name in the graph.

Raises:

Returns:

  • Edge ( Edge ) –

    An ipycytoscape Edge object whose identifier matches the given wire name.

toggle_label

toggle_label(node: Union[str, Node]) -> None

Toggles the label of the given node id or object.

If the name of the node is currently shown, it will switch to the type of the node. If the type of the node is currently shown, it will switch to the name of the node instead.

Parameters:

  • node

    (Union[str, Node]) –

    The name (identifer) of the node, or the node object itself.

show

show() -> None

Create and return an ipycytoscape widget for display in Jupyter notebooks.