Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove StateTransitionCollection #155

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage/reaction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@
"metadata": {},
"outputs": [],
"source": [
"io.asdict(reaction.transition_groups[0].topology)"
"io.asdict(reaction.transitions[0].topology)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/qrules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ def generate_transitions( # pylint: disable=too-many-arguments
... particle_db=qrules.load_pdg(),
... topology_building="isobar",
... )
>>> len(reaction.transition_groups)
3
>>> len(reaction.transitions)
4
>>> len(reaction.group_by_topology())
3
"""
if isinstance(initial_state, str) or (
isinstance(initial_state, tuple)
Expand Down
19 changes: 4 additions & 15 deletions src/qrules/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@

from qrules.particle import Particle, ParticleCollection
from qrules.topology import StateTransitionGraph, Topology
from qrules.transition import (
ProblemSet,
ReactionInfo,
State,
StateTransition,
StateTransitionCollection,
)
from qrules.transition import ProblemSet, ReactionInfo, State, StateTransition

from . import _dict, _dot

Expand All @@ -33,10 +27,7 @@ def asdict(instance: object) -> dict:
return _dict.from_particle(instance)
if isinstance(instance, ParticleCollection):
return _dict.from_particle_collection(instance)
if isinstance(
instance,
(ReactionInfo, State, StateTransition, StateTransitionCollection),
):
if isinstance(instance, (ReactionInfo, State, StateTransition)):
return attrs.asdict(
instance,
recurse=True,
Expand All @@ -59,12 +50,10 @@ def fromdict(definition: dict) -> object:
return _dict.build_particle(definition)
if keys == {"particles"}:
return _dict.build_particle_collection(definition)
if keys == {"transition_groups", "formalism"}:
if keys == {"transitions", "formalism"}:
return _dict.build_reaction_info(definition)
if keys == {"topology", "states", "interactions"}:
return _dict.build_state_transition(definition)
if keys == {"transitions"}:
return _dict.build_stc(definition)
if keys == {"topology", "edge_props", "node_props"}:
return _dict.build_stg(definition)
if keys == __REQUIRED_TOPOLOGY_FIELDS:
Expand Down Expand Up @@ -153,7 +142,7 @@ def asdot(
node_style=node_style,
)
return _dot.insert_graphviz_styling(dot, graphviz_attrs=figure_style)
if isinstance(instance, (ReactionInfo, StateTransitionCollection)):
if isinstance(instance, ReactionInfo):
instance = instance.to_graphs()
if isinstance(instance, abc.Iterable):
dot = _dot.graph_list_to_dot(
Expand Down
27 changes: 6 additions & 21 deletions src/qrules/io/_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
)
from qrules.quantum_numbers import InteractionProperties
from qrules.topology import Edge, StateTransitionGraph, Topology
from qrules.transition import (
ReactionInfo,
State,
StateTransition,
StateTransitionCollection,
)
from qrules.transition import ReactionInfo, State, StateTransition


def from_particle_collection(particles: ParticleCollection) -> dict:
Expand Down Expand Up @@ -79,7 +74,7 @@ def _value_serializer( # pylint: disable=unused-argument
return {k: v.name for k, v in value.items()}
return dict(value)
if not isinstance(
inst, (ReactionInfo, State, StateTransition, StateTransitionCollection)
inst, (ReactionInfo, State, StateTransition)
) and isinstance(value, Particle):
return value.name
if isinstance(value, Parity):
Expand Down Expand Up @@ -114,13 +109,11 @@ def build_particle(definition: dict) -> Particle:


def build_reaction_info(definition: dict) -> ReactionInfo:
transition_groups = [
build_stc(graph_def) for graph_def in definition["transition_groups"]
transitions = [
build_state_transition(transition_def)
for transition_def in definition["transitions"]
]
return ReactionInfo(
transition_groups=transition_groups,
formalism=definition["formalism"],
)
return ReactionInfo(transitions, formalism=definition["formalism"])


def build_stg(definition: dict) -> StateTransitionGraph[ParticleWithSpin]:
Expand All @@ -145,14 +138,6 @@ def build_stg(definition: dict) -> StateTransitionGraph[ParticleWithSpin]:
)


def build_stc(definition: dict) -> StateTransitionCollection:
transitions = [
build_state_transition(graph_def)
for graph_def in definition["transitions"]
]
return StateTransitionCollection(transitions=transitions)


def build_state_transition(definition: dict) -> StateTransition:
topology = build_topology(definition["topology"])
states = {
Expand Down
Loading