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

Interaction update #4

Merged
merged 1 commit into from
Mar 12, 2024
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
19 changes: 7 additions & 12 deletions src/popcore/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __repr__(self) -> str:


PlayerLike = Union[Player, str]
PlayerType = TypeVar("PlayerType", bound=PlayerLike)


@dataclass
Expand Down Expand Up @@ -85,7 +86,7 @@ def __repr__(self) -> str:
def order(self) -> int:
return self._players.shape[-1]

def as_pairs(self) -> 'List[Interaction]':
def to_pairwise(self) -> 'List[Interaction]':
"""
Use this method to converts the current, possibly multiplayer,
multioutcome interaction into a set of pairwise interactions.
Expand Down Expand Up @@ -167,9 +168,6 @@ def __repr__(self) -> str:
return f"TimedInteraction(step={self.timestep}, interaction={rep})"


PlayerType = TypeVar("PlayerType", bound=PlayerLike)


class Population(Generic[PlayerType]):
"""
The Population class implements a storage for any collection
Expand Down Expand Up @@ -221,7 +219,7 @@ def size(self):
return self._size

def __iter__(self):
return self.players
return iter(self.players)

def __str__(self) -> str:
return self.uid
Expand Down Expand Up @@ -259,13 +257,10 @@ def from_players_uid(
"""
# TODO: implement exception handling here.
assert cls == Population, "Do not call from subclasses"

population = Population[PlayerType](uid)
for player_id in players_uid:
population.add(
Player(player_id)
)
return population
return Population[PlayerType](
uid,
[Player(player_id) for player_id in players_uid]
)

@classmethod
def from_players_interactions(
Expand Down
4 changes: 2 additions & 2 deletions test/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_conversion_to_pairwise_should_keep_order_2(self):

self.assertEqual(
[interaction],
interaction.as_pairs()
interaction.to_pairwise()
)

def test_conversion_to_pairwise_should_split(self):
Expand All @@ -30,5 +30,5 @@ def test_conversion_to_pairwise_should_split(self):

self.assertListEqual(
pairwise,
interaction.as_pairs()
interaction.to_pairwise()
)
Loading