io
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 = False, 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: Optional[Dict[str, Any]] = None, node_style: Optional[Dict[str, Any]] = None, **figure_style: Any) str[source]ΒΆ
Convert a
objectto a DOT languagestr.Only works for objects that can be represented as a graph, particularly a
StateTransitionGraphor alistofStateTransitionGraphinstances.- Parameters
instance β the input
objectthat is to be rendered as DOT (graphviz) language.strip_spin β Normally, each
StateTransitionGraphhas aParticlewith a spin projection on its edges. This option hides the projections, leaving onlyParticlenames 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 aStateTransitionGraph). 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
InteractionPropertiesfor 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:
JSONEncoderJSONEncoderthat supportssetandfrozenset.>>> 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)