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

Add a proximity map raw sensor #76

Merged
merged 6 commits into from
Apr 26, 2024
Merged

Add a proximity map raw sensor #76

merged 6 commits into from
Apr 26, 2024

Conversation

clement-moulin-frier
Copy link
Owner

@clement-moulin-frier clement-moulin-frier commented Apr 15, 2024

Description

This PR adds the possibility to access a raw proximity map for each agent. Proximity maps are stored in AgentState.proximity_map_dist and AgentState.proximity_map_theta, which are both of shape (max_agents, max_entities). (edit: actually I think it is (max_agents, nb_neighbors), which is the same if neighbor_radius is the size of the map, to check). The first one indicates the relative distances from all agents to all entities, the second one indicates the relative orientations. For example, AgentState.proximity_map_theta[i, j] is the orientation of entity j relative to agent i (i.e. as perceived by agent i, therefore depending on its current front direction).

This is propagated to the client side in the Configs. For example, using the NotebookController, you can access the proximity maps of agent i with controller.agents[i].proximity_map_dist and controller.agents[i].proximity_map_theta. Here, both maps are of shape (n_entities,), because they are relative a single agent i. For example, controller.agents[i].proximity_map_dist[j] is the distance of agent i to entity j.

The proximity maps will be useful for:

  • Add selective sensors on server side  #66 , where selective sensing could potentially be implemented from these proximity maps
  • Defining custom sensors on the client side (typically in a notebook). Not the highest priority but it case @Marsolo1 has time before he leaves, he could try to implement a sensor that only perceives entities of a given type (e.g. only objects).

However it might introduce a scaling issue, see #78

Related Issue (if applicable)

Closes #7
Opens #77 #78

How to Test

Launch the server

python3 scripts/run_server.py

Launch the Panel interface

panel serve scripts/run_interface.py --autoreload

Check that agents behaves as expected, because now the prox activations are computed from these proximity maps. I.e. check that aggression, fear, shy, love works correctly.

Then, in a Jupyter notebook, check that the proximity map values are consistent wrt to the relative agent positions. For this, you can first set the behavior of agents to noop, so that they don't move. Then you can use this code in the notebook:

from vivarium.controllers.notebook_controller import NotebookController
controller = NotebookController()

ag_id = 4
ag = controller.agents[ag_id]

# Pull state from server (to do each time the state changes)
controller.update_state()
controller.pull_configs()

# To access the distance map
ag.proximity_map_dist

# To access the relative orientation map 
ag.proximity_map_theta

Check that values in the distance and orientation maps are consistent with the relative positions of the agents in the interface. For example, if entity j is on the left of agent i, then controller.agents[i].proximity_map_theta[j]should be roughly equal to pi / 4(modulo 2.pi).

I haven't tested how it behave if some agents/entities do not exist, please check this as well.

Will be also useful to test with a smaller simualtor_state.neighbor_radius to see if rebuilding the neigbor matrix doesn't break it.

Screenshots (if applicable)

# Conflicts:
#	vivarium/controllers/converters.py
#	vivarium/simulator/grpc_server/protos/simulator.proto
#	vivarium/simulator/grpc_server/simulator_pb2.py
#	vivarium/simulator/grpc_server/simulator_pb2.pyi
#	vivarium/simulator/sim_computation.py
@clement-moulin-frier clement-moulin-frier marked this pull request as ready for review April 16, 2024 16:17
@clement-moulin-frier clement-moulin-frier changed the title WIP: Add a proximity map raw sensor Add a proximity map raw sensor Apr 18, 2024
Copy link
Collaborator

@corentinlger corentinlger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distance and theta maps also works for non existing entities. I kept them as they are at the moment, but to prevent having non existing entities detected in these maps, we can replace them with dicts (with only the idx and values of existing entities) or mask the values of non existing entities in the maps.

@corentinlger corentinlger merged commit 0f43534 into main Apr 26, 2024
2 checks passed
@corentinlger corentinlger deleted the clement/neighbor-map branch April 26, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add raw sensor to server and client
2 participants