Skip to content

Commit

Permalink
feat: make Topology ordered (#137)
Browse files Browse the repository at this point in the history
* fix: make Topology ordered
* test: assert unique, deterministic Topology ordering
  • Loading branch information
redeboer authored Jan 20, 2022
1 parent e84670a commit d1bbcff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qrules/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _to_optional_int(optional_int: Optional[int]) -> Optional[int]:
return int(optional_int)


@attr.frozen
@attr.frozen(order=True)
class Edge:
"""Struct-like definition of an edge, used in `Topology`."""

Expand All @@ -167,7 +167,7 @@ def _to_frozenset(iterable: Iterable[int]) -> FrozenSet[int]:


@implement_pretty_repr()
@attr.frozen
@attr.frozen(order=True)
class Topology:
"""Directed Feynman-like graph without edge or node properties.
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ def test_swap_edges(self, two_to_three_decay: Topology):
topology = topology.swap_edges(4, 6)
assert topology != original_topology

@pytest.mark.parametrize(
("n_final_states", "expected_order"),
[
(2, [0]),
(3, [0]),
(4, [1, 0]),
(5, [3, 2, 4, 1, 0]),
(6, [13, 9, 7, 10, 6, 5, 14, 11, 8, 15, 3, 2, 12, 4, 1, 0]),
],
)
def test_unique_ordering(self, n_final_states, expected_order):
topologies = create_isobar_topologies(n_final_states)
sorted_topologies = sorted(topologies)
order = [sorted_topologies.index(t) for t in topologies]
assert order == expected_order


@pytest.mark.parametrize(
("n_final", "n_topologies", "exception"),
Expand Down

0 comments on commit d1bbcff

Please sign in to comment.