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

Change agent image size during simulation #329

Open
1 of 7 tasks
rsverhagen94 opened this issue Nov 1, 2022 · 7 comments
Open
1 of 7 tasks

Change agent image size during simulation #329

rsverhagen94 opened this issue Nov 1, 2022 · 7 comments
Assignees
Labels
question Further information is requested

Comments

@rsverhagen94
Copy link

What is your question?
Is it possible to change image size of agents while the simulation is already running? I tried using self.agent_properties, but without success.

To what is your question related?

  • I am not sure if I should use MATRX.
  • I have a question about the idea behind MATRX.
  • I don't know how to do something with MATRX.
  • I don't know where to find something.
  • I think I found a bug, but I am not sure.
  • I want to contribute, but don't know where to start.
  • Something else.
@rsverhagen94 rsverhagen94 added the question Further information is requested label Nov 1, 2022
@jwaa
Copy link
Member

jwaa commented Nov 1, 2022

Hey @rsverhagen94! Adjusting visualization properties on the fly can indeed be a hassle. Can you provide a bit of a code snippet on what you tried with the self.agent_properties attribute? Also include where you make the adjustments (i.e., in the decide_on_action method).

@rsverhagen94
Copy link
Author

@jwaa thanks for the quick reply! I tried the following code in the decide_on_action method of the agent class:
self.agent_properties["visualization"]["size"] = 5.0. When printing self.agent_properties it actually shows the changed size, but no differences are visually noticeable in the simulation.

@jwaa
Copy link
Member

jwaa commented Nov 3, 2022

Now a bit later reply, sorry for that. It seems that changing the visualization properties is a bit of as hassle since an update. Could you try this:

self.agent_properties["visualize_size"] = 5.0

All of the visualization properties are in their nested dictionaries, but the part that modifies it throughout MATRX cannot handle such nested properties. So the solution MATRX now uses is to translate all of them to "visualization_<property name>".

Let me know if this works!

@rsverhagen94
Copy link
Author

Now a bit later reply, sorry for that. It seems that changing the visualization properties is a bit of as hassle since an update. Could you try this:

self.agent_properties["visualize_size"] = 5.0

All of the visualization properties are in their nested dictionaries, but the part that modifies it throughout MATRX cannot handle such nested properties. So the solution MATRX now uses is to translate all of them to "visualization_<property name>".

Let me know if this works!

This returns the following error:

Traceback (most recent call last):
  File "main.py", line 51, in <module>
    carry_together_case.run(scenario)
  File "/home/ruben/Downloads/moving_out/case/carry_together_case.py", line 196, in run
    world.run(builder.api_info)
  File "/home/ruben/.local/lib/python3.8/site-packages/matrx/grid_world.py", line 246, in run
    is_done, tick_duration = self.__step()
  File "/home/ruben/.local/lib/python3.8/site-packages/matrx/grid_world.py", line 697, in __step
    agent_obj._set_agent_changed_properties(agent_properties)
  File "/home/ruben/.local/lib/python3.8/site-packages/matrx/objects/agent_body.py", line 237, in _set_agent_changed_properties
    raise Exception(f"Agent {self.obj_id} tried to remove the property {prop}, which is not allowed.")
Exception: Agent robot tried to remove the property visualize_size, which is not allowed.

When adding the agent using builder.add_agent, I included visualize_size in customizable_properties. I am using MATRX version 2.2.0 btw.

@jwaa
Copy link
Member

jwaa commented Nov 7, 2022

This returns the following error:

Ah, that is too bad. It seems there is a bug there. A workaround is to add the visualize_size property when you make the agent with the WorldBuilder with the original size as value. No guarantees that this will work though. I made #330 to fix it and with a more detailed description why it fails.

When adding the agent using builder.add_agent, I included visualize_size in customizable_properties. I am using MATRX version 2.2.0 btw.

Also good to know. The past few hotfixes did altered the property mechanism, so it might be worthwhile to upgrade and test it with a newer version.

@jwaa
Copy link
Member

jwaa commented Nov 7, 2022

@rsverhagen94 I wrote a solution for MATRX here, although it is a hacky one you could try and see if it fixes it for you. Alternatively, you can wait until we implemented a hotfix and update your MATRX version.

As a side note; size needs to be an integer as it is a multitude of a grid square :)

@rsverhagen94
Copy link
Author

@rsverhagen94 I wrote a solution for MATRX here, although it is a hacky one you could try and see if it fixes it for you. Alternatively, you can wait until we implemented a hotfix and update your MATRX version.

As a side note; size needs to be an integer as it is a multitude of a grid square :)

This indeed works! Thanks a lot @jwaa :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants