Visualize decay topologies¶
The io
module allows you to convert StateTransitionGraph
, Topology
instances, and ProblemSet
s 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 ReactionInfo
object with a list
of StateTransitionGraph
instances (see Generate transitions).
Topologies¶
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
import qrules
from qrules.topology import create_isobar_topologies, create_n_body_topology
topology = create_n_body_topology(2, 4)
graphviz.Source(qrules.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)
graphviz.Source(qrules.io.asdot(topologies))
This can be turned on or off with the arguments of asdot()
:
topologies = create_isobar_topologies(3)
graphviz.Source(qrules.io.asdot(topologies, render_node=False))
asdot()
provides other options as well:
topologies = create_isobar_topologies(5)
dot = qrules.io.asdot(
topologies[0],
render_final_state_id=False,
render_resonance_id=True,
render_node=False,
)
display(graphviz.Source(dot))
ProblemSet
s¶
As noted in Generate transitions, the StateTransitionManager
provides more control than the façade function generate_transitions()
. One advantages, is that the StateTransitionManager
first generates a set of ProblemSet
s with create_problem_sets()
that you can further configure if you wish.
stm = qrules.StateTransitionManager(
initial_state=["J/psi(1S)"],
final_state=["K0", "Sigma+", "p~"],
formalism="canonical-helicity",
)
problem_sets = stm.create_problem_sets()
Note that the output of create_problem_sets()
is a dict
with float
values as keys (representing the interaction strength) and list
s of ProblemSet
s as values.
sorted(problem_sets, reverse=True)
[3600.0, 60.0, 1.0, 0.006, 0.0001, 1e-08]
len(problem_sets[60.0])
72
problem_set = problem_sets[60.0][0]
dot = qrules.io.asdot(problem_set, render_node=True)
graphviz.Source(dot)
StateTransition
s¶
Here, we’ll visualize the allowed transitions for the decay \(\psi' \to \gamma\eta\eta\) as an example.
import qrules
reaction = qrules.generate_transitions(
initial_state="psi(2S)",
final_state=["gamma", "eta", "eta"],
allowed_interaction_types="EM",
)
As noted in 3. Find solutions, the transitions
contain all spin projection combinations (which is necessary for the ampform
package). 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 = qrules.io.asdot(reaction.transitions[::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 = qrules.io.asdot(
reaction.transitions[::50][:3], render_node=False
) # just some selection
graphviz.Source(dot)
You can also serialize the DOT string to file with io.write()
. The file extension for a DOT file is .gv
:
qrules.io.write(reaction, "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 = qrules.io.asdot(reaction.transitions[:3], strip_spin=True)
graphviz.Source(dot)
or, with stripped node properties:
dot = qrules.io.asdot(
reaction.transitions[:3], strip_spin=True, render_node=True
)
graphviz.Source(dot)
Note
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 = qrules.io.asdot(reaction, collapse_graphs=True, render_node=False)
graphviz.Source(dot)