Visualize decay topologies


The PWA Expert System has been split up into QRules and AmpForm. Please use these packages instead!


The formulas and figures on this page have been generated with the lineshapes in the lineshape module, so as to glue them back in to the API of that module.

The io module allows you to convert StateTransitionGraph and Topology instances to DOT language with asdot(). You can visualize its output with third-party libraries, such as Graphviz. This is particularly useful after running find_solutions(), which produces a Result object with a list of StateTransitionGraph instances (see Generate transitions).


First of all, here are is an example of how to visualize a group of Topology instances. We use create_isobar_topologies() and create_n_body_topology() to create a few standard topologies.

import graphviz

from expertsystem import io
from expertsystem.reaction.topology import (
topology = create_n_body_topology(2, 4)
graphviz.Source(io.asdot(topology, render_initial_state_id=True))

Note the IDs of the nodes is also rendered if there is more than node:

topologies = create_isobar_topologies(4)

This can be turned on or off with the arguments of asdot():

topologies = create_isobar_topologies(3)
graphviz.Source(io.asdot(topologies, render_node=False))

asdot() provides other options as well:

topologies = create_isobar_topologies(5)
dot = io.asdot(


Here, we’ll visualize the allowed transitions for the decay \(\psi' \to \gamma\eta\eta\) as an example.

import expertsystem as es

result = es.reaction.generate(
    final_state=["gamma", "eta", "eta"],

As noted in 3. Find solutions, the transitions contain all spin projection combinations (which is necessary for the amplitude module). It is possible to convert all these solutions to DOT language with asdot(). To avoid visualizing all solutions, we just take a subset of the transitions:

dot =[::50][:3])  # just some selection

This str of DOT language for the list of StateTransitionGraph instances can then be visualized with a third-party library, for instance, with graphviz.Source:

import graphviz

dot =
    result.transitions[::50][:3], render_node=False
)  # just some selection

You can also serialize the DOT string to file with io.write. The file extension for a DOT file is .gv:, "decay_topologies_with_spin.gv")

Collapse graphs

Since this list of all possible spin projections transitions is rather long, it is often useful to use strip_spin=True or collapse_graphs=True to bundle comparable graphs. First, strip_spin=True allows one collapse (ignore) the spin projections (we again show a selection only):

dot =[:3], strip_spin=True)


By default, .asdot renders edge IDs, because they represent the (final) state IDs as well. In the example above, we switched this off.

If that list is still too much, there is collapse_graphs=True, which bundles all graphs with the same final state groupings:

dot =, collapse_graphs=True, render_node=False)