Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cb8e20a
Add Mermaid graph rendering parallel to Graphvis rendering including …
Flomber Aug 17, 2026
8f2ca31
Merge branch 'main' into Mermaidrendering
Flomber Aug 18, 2026
b3f2da9
MAINT: implement pre-commit autofixes
pre-commit-ci[bot] Aug 18, 2026
646781c
MAINT: implement updates from formatters
web-flow Aug 18, 2026
d702c47
Refactor Mermaid visualization: replace show_mermaid_markdown with as…
Flomber Aug 19, 2026
cfa59e8
MAINT: implement pre-commit autofixes
pre-commit-ci[bot] Aug 19, 2026
7e9a03b
MAINT: implement updates from formatters
web-flow Aug 19, 2026
85e300e
MAINT: fix mypy problem
redeboer Aug 19, 2026
67f9520
Fix references of old visualize notebook
Flomber Aug 19, 2026
83829af
MAINT: implement updates from formatters
web-flow Aug 19, 2026
d79c997
Fix rendering issue on website
Flomber Aug 19, 2026
93f9260
MAINT: implement pre-commit autofixes
pre-commit-ci[bot] Aug 19, 2026
e04753f
MAINT: implement updates from formatters
web-flow Aug 19, 2026
3dc6947
Kick CI
redeboer Aug 19, 2026
9f83bde
DX: strip newlines with ComPWA/nbhooks@68b087e
redeboer Aug 19, 2026
2c1e010
Add mermaid examples into 'visualize_dot.ipynb'
Flomber Aug 19, 2026
f5f606b
Replace visualize_dot and visualize_mermaid with merged visualize not…
Flomber Aug 19, 2026
b8d5971
Fix double reference of visualize.ipynb in usage.ipynb and add stylis…
Flomber Aug 20, 2026
4c59a19
MAINT: reduce diff
redeboer Aug 20, 2026
0f8b6c2
MAINT: minor formatting issues
redeboer Aug 20, 2026
c47bf92
DOC: hide input cells of Mermaid examples
redeboer Aug 20, 2026
42b2552
Remove unnecessary dependencies
Flomber Aug 20, 2026
9329393
Fix issue with node and node id beeing rendered, when flags were disa…
Flomber Aug 20, 2026
9b30be0
reduce diff
Flomber Aug 20, 2026
b41e903
Merge functions for rendering labels etc. from _dot.py and _mermaid.p…
Flomber Aug 21, 2026
2a31073
Make escape label translation more stable
Flomber Aug 21, 2026
8c3eed0
Define MermaidPrinter class with a constructor
Flomber Aug 21, 2026
e9a7366
Make styling mapping module-level based
Flomber Aug 21, 2026
d2cc85f
Remove redundant freeze in func strip_projections
Flomber Aug 21, 2026
ed8b685
Fix priority sorting issue
Flomber Aug 21, 2026
34b69a9
Fix iteration issue in {func} collapse_graphs
Flomber Aug 21, 2026
6d36ff2
Add style of rendering shown in #159 (comment)
Flomber Aug 21, 2026
d9b1f1a
DX: add doctest to `__extract_priority()`
redeboer Aug 21, 2026
b4fcd8f
MAINT: reduce diff
redeboer Aug 21, 2026
a8003fe
MAINT: unpack tuple
redeboer Aug 21, 2026
cf9abf0
MAINT: reorganize tests to match module structure
redeboer Aug 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"useGitignore": true,
"version": "0.2",
"words": [
"asmermaid",
"blatt",
"bosonic",
"bottomness",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Output files
*.gv
*.json
*.mmd
*.npy
*.pdf
*.pickle
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
metadata.vscode
- repo: https://github.com/ComPWA/nbhooks
rev: 0.0.1
rev: 0.0.2
hooks:
- id: colab-toc-visible
- id: fix-nbformat-version
Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def __get_newtypes(some_type: type) -> list:
"sphinx_pybtex_etal_style",
"sphinx_thebe",
"sphinx_togglebutton",
"sphinxcontrib.mermaid",
"sphinxcontrib.bibtex",
]
generate_apidoc_package_path = f"../src/{PACKAGE}"
Expand Down Expand Up @@ -268,6 +269,7 @@ def __get_newtypes(some_type: type) -> list:
"smartquotes",
"substitution",
]
myst_fence_as_directive = ["mermaid"]
myst_heading_anchors = 2
myst_substitutions = {
"branch": BRANCH,
Expand All @@ -284,6 +286,7 @@ def __get_newtypes(some_type: type) -> list:
nb_execution_show_tb = True
nb_execution_timeout = -1
nb_output_stderr = "remove"
nb_render_markdown_format = "myst"
nitpick_ignore = [
("py:class", "StrPath"),
]
Expand Down
192 changes: 183 additions & 9 deletions docs/usage/visualize.ipynb
Comment thread
Flomber marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The {mod}`~qrules.io` module allows you to convert {class}`.MutableTransition`, {class}`.Topology` instances, and {class}`.ProblemSet`s to [DOT language](https://graphviz.org/doc/info/lang.html) with {func}`.asdot`. You can visualize its output with third-party libraries, such as [Graphviz](https://graphviz.org). This is particularly useful after running {meth}`~.StateTransitionManager.find_solutions`, which produces a {class}`.ReactionInfo` object with a {class}`.list` of {class}`.MutableTransition` instances (see {doc}`/usage/reaction`)."
"The {mod}`~qrules.io` module allows you to convert {class}`.MutableTransition`, {class}`.Topology` instances, and {class}`.ProblemSet`s to [DOT language](https://graphviz.org/doc/info/lang.html) with {func}`.asdot`. You can visualize its output with third-party libraries, such as [Graphviz](https://graphviz.org). This is particularly useful after running {meth}`~.StateTransitionManager.find_solutions`, which produces a {class}`.ReactionInfo` object with a {class}`.list` of {class}`.MutableTransition` instances (see {doc}`/usage/reaction`).\n",
"\n",
"In addition, the same objects can be converted to [Mermaid language](https://mermaid.ai/open-source/intro/syntax-reference.html) with {func}`.asmermaid`. We include a few Mermaid examples to demonstrate that this renderer is implemented and working as well."
]
},
{
Expand All @@ -49,7 +51,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First of all, here are is an example of how to visualize a group of {class}`.Topology` instances. We use {func}`.create_isobar_topologies` and {func}`.create_n_body_topology` to create a few standard topologies."
"First of all, here is an example of how to visualize a group of {class}`.Topology` instances. We use {func}`.create_isobar_topologies` and {func}`.create_n_body_topology` to create a few standard topologies."
]
},
{
Expand All @@ -66,7 +68,7 @@
"outputs": [],
"source": [
"import graphviz\n",
"from IPython.display import display\n",
"from IPython.display import Markdown, display\n",
"\n",
"import qrules\n",
"from qrules.conservation_rules import (\n",
Expand Down Expand Up @@ -152,6 +154,32 @@
"display(graphviz.Source(dot))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"or analogously for {func}`.asmermaid`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source = qrules.io.asmermaid(\n",
" topologies[0],\n",
" render_final_state_id=False,\n",
" render_resonance_id=True,\n",
" render_node=False,\n",
")\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
},
Comment thread
Flomber marked this conversation as resolved.
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -216,6 +244,31 @@
"graphviz.Source(dot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In Mermaid, a {class}`.ProblemSet` is rendered as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"source = qrules.io.asmermaid(problem_set, render_node=True)\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -244,7 +297,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The list of solutions consist of a {obj}`tuple` of a {obj}`.QNProblemSet` (compare {ref}`problem-sets`) and a {obj}`.QNResult`:"
"The list of solutions consists of a {obj}`tuple` of a {obj}`.QNProblemSet` (compare {ref}`problem-sets`) and a {obj}`.QNResult`:"
]
},
{
Expand Down Expand Up @@ -389,6 +442,56 @@
"graphviz.Source(dot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In Mermaid, the {class}`.QNProblemSet` is rendered as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"source = qrules.io.asmermaid(qn_problem_set, render_node=True)\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And analogously, the filtered {class}`.QNResult` can be visualized:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"hide-input"
]
},
"outputs": [],
"source": [
"source = qrules.io.asmermaid(filtered_qn_result, render_node=True)\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -431,7 +534,8 @@
"metadata": {},
"outputs": [],
"source": [
"dot = qrules.io.asdot(reaction.transitions[::50][:3]) # just some selection"
"some_transitions = reaction.transitions[::50][:3]\n",
"dot = qrules.io.asdot(some_transitions)"
]
},
{
Expand All @@ -449,9 +553,7 @@
"source": [
"import graphviz\n",
"\n",
"dot = qrules.io.asdot(\n",
" reaction.transitions[::50][:3], render_node=False\n",
") # just some selection\n",
"dot = qrules.io.asdot(some_transitions, render_node=False)\n",
"graphviz.Source(dot)"
]
},
Expand All @@ -471,6 +573,22 @@
"qrules.io.write(reaction, \"decay_topologies_with_spin.gv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or you can serialize a mermaid string to file with {func}`.io.write`. The file extension for a mermaid file is `.mmd`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"qrules.io.write(reaction, \"decay_topologies_with_spin.mmd\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -538,6 +656,27 @@
"graphviz.Source(dot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The above examples also work with {func}`.asmermaid`, for example:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Comment thread
Flomber marked this conversation as resolved.
"source = qrules.io.asmermaid(reaction, collapse_graphs=True, render_node=False)\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -726,6 +865,41 @@
")\n",
"display(graphviz.Source(dot))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{func}`.asmermaid` also accepts styling arguments, for example `node_style`, `edge_style`, and `figure_style`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source = qrules.io.asmermaid(\n",
" reaction.transitions[0],\n",
" render_node=True,\n",
" figure_style={\"bgcolor\": \"white\"},\n",
" edge_style={\n",
" \"color\": \"red\",\n",
" \"fontcolor\": \"blue\",\n",
" \"fontsize\": 25,\n",
" },\n",
" node_style={\n",
" \"color\": \"gray\",\n",
" \"fill\": \"lightgray\",\n",
" \"stroke\": \"black\",\n",
" },\n",
")\n",
"Markdown(f\"\"\"\n",
"```mermaid\n",
"{source}\n",
"```\n",
"\"\"\")"
]
}
],
"metadata": {
Expand All @@ -747,7 +921,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.12"
"version": "3.13.15"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ doc = [
"sphinx-thebe",
"sphinx-togglebutton",
"sphinxcontrib-bibtex >=2",
"sphinxcontrib-mermaid",
{ include-group = "notebooks" },
]
jupyter = [
Expand Down
Loading
Loading