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

Concrete GridPandas #44

Merged
merged 46 commits into from
Aug 4, 2024
Merged

Concrete GridPandas #44

merged 46 commits into from
Aug 4, 2024

Conversation

adamamer20
Copy link
Collaborator

@adamamer20 adamamer20 commented Aug 1, 2024

This PR adds the GridPandas class, a concrete Pandas-based implementation of GridDF, with unit-tests for all public methods and properties. The remaining capacity of cells is stored in a np.array where only vectorized operations are applied.

Key changes in this PR:

SpaceDF

  • Distinction between place_* and move_* methods for abstract SpaceDF. place methods raise a Warning if agents are already placed in the grid, move methods raise a Warning if agents are not placed in the grid.
  • Implementation of swap_agents directly in SpaceDF

DiscreteSpaceDF

  • Implementation of set_cells directly in DiscreteSpaceDF
  • Addition of remaining_capacity property in DiscreteSpaceDF
  • Added 'respect_capacity' parameter to 'sample_cells'. If with_replacement is True, the flag make sure to sample cells only the allowed total capacity number of times.

GridDF

  • Changed coordinate system for hexagonal grids. The coordinate system is axial. The axes (q and r) are at 60 degrees to each other. This allows for symmetric offsets across cells (more performant) and it's easier to think about.
  • Added 'get_neighborhood' implementation directly to GridDF. If the radiuses are different across positions/agents, neighborhoods are generated for the maximum radius for all positions / agents and are later dropped. This allows the use of vectorized operations (for time-efficiency) but may be space inefficient.
  • Added 'get_cells' implementation directly to GridDF. Each cell row contains exactly one agent, thus there may be multiple rows with the same cell and different agents. This is space inefficient but more time-efficient and intuitive (Series of lists are not easy to manipulate).

Requires merging #43.

- create set_cells at DiscreteSpaceDF level
- created concrete swap in SpaceDF
- update due to changes in mixin
- add remaining capacity property
- branching _update_capacity in cells and agents
…nts are already present, the second if agents aren't already present

- Fixes to the logic of some methods of SpaceDF (random_agents, swap_agents),
DiscreteSpaceDF (__repr__, __str__)
GridDF (__init__, get_directions, get_distances, get_neighbors, get_neighborhood, get_cells, out_of_bounds, remove_agents, torus_adj, _compute_offsets, _get_df_coords)
- added custom _empty_cell_condition
- fixed the logic of some methods (_generate_empty_grid, _sample_cells, _update_capacity_agents, remaining_capacity)
@adamamer20 adamamer20 linked an issue Aug 1, 2024 that may be closed by this pull request
@adamamer20 adamamer20 marked this pull request as draft August 1, 2024 19:37
@adamamer20 adamamer20 requested a review from rht August 1, 2024 19:37
@adamamer20 adamamer20 self-assigned this Aug 1, 2024
@adamamer20 adamamer20 added the enhancement Improvements to existing features or performance. label Aug 1, 2024
@adamamer20 adamamer20 added this to the 0.1.0 Alpha Release milestone Aug 1, 2024
@adamamer20 adamamer20 marked this pull request as ready for review August 2, 2024 08:08
@rht
Copy link
Contributor

rht commented Aug 4, 2024

Sorry for the delay in reviewing. Hope it's not blocking the other issues.

@rht rht merged commit 69297a1 into main Aug 4, 2024
6 checks passed
@rht rht deleted the 34-concrete-gridpandas branch August 4, 2024 10:10
@rht
Copy link
Contributor

rht commented Aug 4, 2024

It looks like there is a test flake on the latest main CI.

@adamamer20
Copy link
Collaborator Author

Sorry for the delay in reviewing. Hope it's not blocking the other issues.

Do not worry, I was working on PolarsMixin and GridPolars.

It looks like there is a test flake on the latest main CI.

You're right, failure on ubuntu is related to the sampling operation. Should be an easy fix.
Windows on the other hand seems to have trouble building matplotlib(?). I need to dig deeper.

@adamamer20 adamamer20 linked an issue Aug 4, 2024 that may be closed by this pull request
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features or performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring mesa.space Concrete GridPandas
2 participants