{ "cells": [ { "cell_type": "markdown", "id": "aca93fea", "metadata": {}, "source": [ "```{seealso}\n", "This notebook can be downloaded {nb-download}`here `\n", "```\n", "\n", "# UML class diagram generator\n", "\n", "- This notebook generates UML diagrams of class hierarchies\n", "- Dependencies: `pylint`, `ipykernel` (install these two in a python env), [graphviz](https://graphviz.org/download/)" ] }, { "cell_type": "code", "execution_count": 1, "id": "bfba5c99", "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image, display\n", "from quantify_scheduler.helpers.inspect import make_uml_diagram" ] }, { "cell_type": "markdown", "id": "5035953a", "metadata": {}, "source": [ "## General notes\n", "- Yellow labels indicate addition as a submodule\n", "- Different colors indicate different packages\n", "- Generated figures are saved in png format\n", "- Options must be given in `list[str]` format\n", "- For more information, visit the [Wikipedia page](https://en.wikipedia.org/wiki/Class_diagram#Relationships) on relationships in class diagrams\n", "\n", "## Plotting all classes in a module\n", "- Be aware that this option will only plot classes that are contained within `module_to_plot`, and not related classes defined outside the module.\n", "- Extra options:\n", " - Show ancestors (aka parent classes): `-A`\n", " - Ignore specific submodules: `--ignore ` (e.g. `[\"--ignore\", \"circuit_to_device.py,corrections.py,zhinst\"]`)" ] }, { "cell_type": "code", "execution_count": 2, "id": "15cc9936", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error running 'dot': is 'graphviz' installed?\n" ] } ], "source": [ "from quantify_scheduler.backends import qblox\n", "\n", "module_to_plot = qblox\n", "options = [\"-A\"]\n", "\n", "diagram_name = make_uml_diagram(module_to_plot, options)\n", "if diagram_name:\n", " display(Image(diagram_name))" ] }, { "cell_type": "markdown", "id": "443575bd", "metadata": {}, "source": [ "## Plotting ancestors and submodules of a class\n", "- Remove `--only-classnames` option to show all class attributes" ] }, { "cell_type": "code", "execution_count": 3, "id": "472126e7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error running 'dot': is 'graphviz' installed?\n" ] } ], "source": [ "from quantify_scheduler.device_under_test.transmon_element import BasicTransmonElement\n", "\n", "class_to_plot = BasicTransmonElement\n", "options = [\"--only-classnames\"]\n", "\n", "diagram_name = make_uml_diagram(class_to_plot, options)\n", "if diagram_name:\n", " display(Image(diagram_name))" ] } ], "metadata": { "file_format": "mystnb", "kernelspec": { "display_name": "python3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.21" }, "source_map": [ 6, 16, 19, 35, 45, 51 ] }, "nbformat": 4, "nbformat_minor": 5 }