Visualize decay topologies

The io module allows you to convert a StateTransitionGraph to DOT language, which you can then visualize 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 the Quickstart).

First, we quickly create some dummy solutions. We’re not interested in the propagate process, so we decrease the logging level as well

[1]:
import logging

logging.basicConfig(level=logging.ERROR)
[2]:
from expertsystem.amplitude.helicity_decay import HelicityAmplitudeGenerator
from expertsystem.reaction import InteractionTypes, StateTransitionManager

stm = StateTransitionManager(
    initial_state=[("J/psi(1S)", [-1, 1])],
    final_state=["gamma", "pi0", "pi0"],
    allowed_intermediate_particles=["f(0)(980)", "f(0)(1500)",],
)
stm.set_allowed_interaction_types([InteractionTypes.EM])
graph_interaction_settings_groups = stm.prepare_graphs()
result = stm.find_solutions(graph_interaction_settings_groups)

Now, we use the convert_to_dot function to create a str of DOT language for the list of solutions (StateTransitionGraph instances):

[3]:
from expertsystem import io

dot_source = io.convert_to_dot(result.solutions)

This str can then be visualized with a third-party library, for instance, with graphviz.Source:

[4]:
import graphviz

graphviz.Source(dot_source)
[4]:
../_images/usage_visualization_7_0.svg

Warning

graphviz requires your system to have DOT installed, see Installation.

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

[5]:
io.write(instance=result.solutions, filename="decay_topologies.gv")