io#
import qrules.io
Serialization module for the qrules
.
The io
module provides tools to export or import objects from qrules
to and from
disk, so that they can be used by external packages, or just to store (cache) the state
of the system.
- asdot(instance: object, *, render_node: bool | None = None, render_final_state_id: bool = True, render_resonance_id: bool = False, render_initial_state_id: bool = False, strip_spin: bool = False, collapse_graphs: bool = False, edge_style: Dict[str, Any] | None = None, node_style: Dict[str, Any] | None = None, **figure_style: Any) str [source]#
Convert a
object
to a DOT languagestr
.Only works for objects that can be represented as a graph, particularly a
MutableTransition
or alist
ofMutableTransition
instances.- Parameters:
instance – the input
object
that is to be rendered as DOT (graphviz) language.strip_spin – Normally, each
MutableTransition
has aParticle
with a spin projection on its edges. This option hides the projections, leaving onlyParticle
names on edges.collapse_graphs – Group all transitions by equivalent kinematic topology and combine all allowed particles on each edge.
render_node –
Whether or not to render node ID (in the case of a
Topology
) and/or node properties (in the case of aMutableTransition
). Meaning of the labels:\(P\): parity prefactor
\(s\): tuple of coupled spin magnitude and its projection
\(l\): tuple of angular momentum and its projection
See
InteractionProperties
for more info.render_final_state_id – Add edge IDs for the final state edges.
render_resonance_id – Add edge IDs for the intermediate state edges.
render_initial_state_id – Add edge IDs for the initial state edges.
edge_style – Styling of a Graphviz edge.
node_style – Styling of a Graphviz node.
figure_style – Styling of the whole figure.
See also
See Graphviz attributes for the available styling arguments.
See also
- class JSONSetEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
Bases:
JSONEncoder
JSONEncoder
that supportsset
andfrozenset
.>>> import json >>> instance = {"val1": {1, 2, 3}, "val2": frozenset({2, 3, 4, 5})} >>> json.dumps(instance, cls=JSONSetEncoder) '{"val1": [1, 2, 3], "val2": [2, 3, 4, 5]}'
- default(o: Any) Any [source]#
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)