neuralogic.utils.visualize package

Module contents

draw(drawer: Any, obj: Any, filename: str | None = None, show: bool = True, img_type: str = 'png', *args: Any, **kwargs: Any) → Any[source]

Draws the object using the provided drawer.

Parameters:
  • drawer (Any) – The drawer to use.

  • obj (Any) – The object to draw.

  • filename (str, optional) – The filename to draw into. Default: None.

  • show (bool) – Whether to show the image. Default: True.

  • img_type (str) – The image type. Default: β€œpng”.

  • args (Any) – Additional arguments for the drawer.

  • kwargs (Any) – Additional keyword arguments for the drawer.

Returns:

The drawing data, image object, or None if drawn into a file.

Return type:

Union[Any, bytes, None]

draw_grounding(grounding: Any, filename: str | None = None, show: bool = True, img_type: str = 'png', value_detail: int = 0, graphviz_path: str | None = None, settings: DrawingSettings | None = None, *args: Any, **kwargs: Any) → Any[source]
Draws sample’s grounding either as an image of type img_type either into:
  • a file - if filename is specified),

  • an IPython Image or Image popup - if show is True

  • or bytes otherwise

Parameters:
  • grounding (Any) – The grounding to draw.

  • filename (str, optional) – The filename to draw into. Default: None.

  • show (bool) – Whether to show the image. Default: True.

  • img_type (str) – The image type. Default: β€œpng”.

  • value_detail (int) – The level of detail for values. Default: 0.

  • graphviz_path (str, optional) – The path to the Graphviz executable. Default: None.

  • settings (DrawingSettings, optional) – Styling settings. When provided, they control value detail and graph styling, while filename, img_type and graphviz_path from this call still control the output.

  • args (Any) – Additional arguments for the drawer.

  • kwargs (Any) – Additional keyword arguments for the drawer.

Returns:

The grounding drawing.

Return type:

Union[Any, bytes, None]

draw_model(model: Any, filename: str | None = None, show: bool = True, img_type: str = 'png', value_detail: int = 0, graphviz_path: str | None = None, settings: DrawingSettings | None = None, *args: Any, **kwargs: Any) → Any[source]
Draws model either as an image of type img_type either into:
  • a file - if filename is specified),

  • an IPython Image or Image popup - if show is True

  • or bytes otherwise

Parameters:
  • model (NeuralModule) – The model to draw.

  • filename (str, optional) – The filename to draw into. Default: None.

  • show (bool) – Whether to show the image. Default: True.

  • img_type (str) – The image type. Default: β€œpng”.

  • value_detail (int) – The level of detail for values. Default: 0.

  • graphviz_path (str, optional) – The path to the Graphviz executable. Default: None.

  • settings (DrawingSettings, optional) – Styling settings. When provided, they control value detail and graph styling, while filename, img_type and graphviz_path from this call still control the output.

  • args (Any) – Additional arguments for the drawer.

  • kwargs (Any) – Additional keyword arguments for the drawer.

Returns:

The model drawing.

Return type:

Union[Any, bytes, None]

draw_pipeline(pipeline: Any, filename: str | None = None, show: bool = True, img_type: str = 'png', value_detail: int = 0, graphviz_path: str | None = None, settings: DrawingSettings | None = None, *args: Any, **kwargs: Any) → Any[source]
Draws a backend pipeline either as an image of type img_type either into:
  • a file - if filename is specified),

  • an IPython Image or Image popup - if show is True

  • or bytes otherwise

Parameters:
  • pipeline (Any) – The backend pipeline (cz.cvut.fel.ida.pipelines.Pipeline) to draw.

  • filename (str, optional) – The filename to draw into. Default: None.

  • show (bool) – Whether to show the image. Default: True.

  • img_type (str) – The image type. Default: β€œpng”.

  • value_detail (int) – The level of detail for values. Default: 0.

  • graphviz_path (str, optional) – The path to the Graphviz executable. Default: None.

  • settings (DrawingSettings, optional) – Styling settings. When provided, they control value detail and graph styling, while filename, img_type and graphviz_path from this call still control the output.

  • args (Any) – Additional arguments for the drawer.

  • kwargs (Any) – Additional keyword arguments for the drawer.

Returns:

The pipeline drawing.

Return type:

Union[Any, bytes, None]

draw_sample(sample: Any, filename: str | None = None, show: bool = True, img_type: str = 'png', value_detail: int = 0, graphviz_path: str | None = None, settings: DrawingSettings | None = None, *args: Any, **kwargs: Any) → Any[source]
Draws sample either as an image of type img_type either into:
  • a file - if filename is specified),

  • an IPython Image or Image popup - if show is True

  • or bytes otherwise

Parameters:
  • sample (Any) – The sample to draw.

  • filename (str, optional) – The filename to draw into. Default: None.

  • show (bool) – Whether to show the image. Default: True.

  • img_type (str) – The image type. Default: β€œpng”.

  • value_detail (int) – The level of detail for values. Default: 0.

  • graphviz_path (str, optional) – The path to the Graphviz executable. Default: None.

  • settings (DrawingSettings, optional) – Styling settings. When provided, they control value detail and graph styling, while filename, img_type and graphviz_path from this call still control the output.

  • args (Any) – Additional arguments for the drawer.

  • kwargs (Any) – Additional keyword arguments for the drawer.

Returns:

The sample drawing.

Return type:

Union[Any, bytes, None]

get_drawing_settings(img_type: str = 'png', value_detail: int = 0, graphviz_path: str | None = None) → DrawingSettings[source]

Returns standalone drawing settings configured with the specified image type.

Parameters:
  • img_type (str) – The image type. Default: β€œpng”.

  • value_detail (int) – The level of detail for values (0, 1 or 2). Default: 0.

  • graphviz_path (str, optional) – The path to the Graphviz executable. Default: None.

Returns:

Standalone drawing settings. Style and value detail can be further configured on the returned object before it is passed to a drawer.

Return type:

DrawingSettings

get_graphviz_path(path: str | None = None) → str | None[source]

Get the path to the Graphviz executable

get_grounding_drawer(settings: DrawingSettings) → Any[source]

Returns the grounding drawer.

Parameters:

settings (DrawingSettings) – The drawing settings.

Returns:

The grounding drawer.

Return type:

Any

get_model_drawer(settings: DrawingSettings) → Any[source]

Returns the model drawer.

Parameters:

settings (DrawingSettings) – The drawing settings.

Returns:

The model drawer.

Return type:

Any

get_pipeline_drawer(settings: DrawingSettings) → Any[source]

Returns the pipeline drawer.

Parameters:

settings (DrawingSettings) – The drawing settings.

Returns:

The pipeline drawer.

Return type:

Any

get_sample_drawer(settings: DrawingSettings) → Any[source]

Returns the sample drawer.

Parameters:

settings (DrawingSettings) – The drawing settings.

Returns:

The sample drawer.

Return type:

Any

graphml_to_networkx(graphml: str | None) → Any[source]

Loads a GraphML string into a networkx graph.

Parameters:

graphml (str | None) – The GraphML source.

Returns:

The graph read from the GraphML source.

Return type:

networkx.DiGraph

is_jupyter() → bool[source]
model_to_dot_source(model: Any, settings: DrawingSettings | None = None) → str[source]

Renders the model into its dot source representation.

Parameters:
  • model (NeuralModule) – The model to render.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, they are used instead of the defaults.

Returns:

The dot source representation.

Return type:

str

model_to_graphml_source(model: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → str | None[source]

Renders the model into its GraphML source representation.

Parameters:
  • model (NeuralModule) – The model to render.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The GraphML source, or None if the backend graphviz-based conversion failed.

Return type:

str | None

model_to_networkx(model: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → Any[source]

Converts the model into a networkx graph.

Parameters:
  • model (NeuralModule) – The model to convert.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The model as a directed graph. Node labels are stored in the β€œlabel” attribute.

Return type:

networkx.DiGraph

pipeline_to_dot_source(pipeline: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → str[source]

Renders the pipeline into its dot source representation.

Parameters:
  • pipeline (Any) – The backend pipeline to render.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The dot source representation.

Return type:

str

pipeline_to_graphml_source(pipeline: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → str | None[source]

Renders the pipeline into its GraphML source representation.

Parameters:
  • pipeline (Any) – The backend pipeline to render.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The GraphML source, or None if the backend graphviz-based conversion failed.

Return type:

str | None

pipeline_to_networkx(pipeline: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → Any[source]

Converts the pipeline into a networkx graph.

Parameters:
  • pipeline (Any) – The backend pipeline to convert.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The pipeline as a directed graph. Node labels are stored in the β€œlabel” attribute.

Return type:

networkx.DiGraph

sample_to_dot_source(sample: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → str[source]

Renders the sample into its dot source representation.

Parameters:
  • sample (Any) – The sample to render.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The dot source representation.

Return type:

str

sample_to_graphml_source(sample: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → str | None[source]

Renders the sample into its GraphML source representation.

Parameters:
  • sample (Any) – The sample to render.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The GraphML source, or None if the backend graphviz-based conversion failed.

Return type:

str | None

sample_to_networkx(sample: Any, value_detail: int = 0, settings: DrawingSettings | None = None) → Any[source]

Converts the sample into a networkx graph.

Parameters:
  • sample (Any) – The sample to convert.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

Returns:

The sample as a directed graph. Node labels are stored in the β€œlabel” attribute.

Return type:

networkx.DiGraph

save_model_graphml(model: Any, path: str, value_detail: int = 0, settings: DrawingSettings | None = None) → None[source]

Saves the model graph as a GraphML file consumable by networkx.

Parameters:
  • model (NeuralModule) – The model to save.

  • path (str) – The destination file path. Parent directories are created if needed.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

save_pipeline_graphml(pipeline: Any, path: str, value_detail: int = 0, settings: DrawingSettings | None = None) → None[source]

Saves the pipeline graph as a GraphML file consumable by networkx.

Parameters:
  • pipeline (Any) – The backend pipeline to save.

  • path (str) – The destination file path. Parent directories are created if needed.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

save_sample_graphml(sample: Any, path: str, value_detail: int = 0, settings: DrawingSettings | None = None) → None[source]

Saves the sample graph as a GraphML file consumable by networkx.

Parameters:
  • sample (Any) – The sample to save.

  • path (str) – The destination file path. Parent directories are created if needed.

  • value_detail (int) – The level of detail for values. Default: 0.

  • settings (DrawingSettings, optional) – Standalone drawing settings. When provided, value_detail is ignored.

to_dot_source(drawer: Any, obj: Any) → str[source]
to_graphml_source(drawer: Any, obj: Any) → str | None[source]

Renders the object into its GraphML source representation.

Parameters:
  • drawer (Any) – The drawer to use.

  • obj (Any) – The object to render.

Returns:

The GraphML source, or None if the backend graphviz-based conversion failed.

Return type:

str | None