How to change the color of ant inside the step function #413
Replies: 2 comments 1 reply
-
Hi @eleninisioti , please include the full code and the stack-trace, it's tricky to debug traced conversion errors without the full context. You might also try adding the color to FYI: the visualizer uses a static rgba when the scene gets created https://github.com/google/brax/blob/main/brax/visualizer/js/system.js#L164 |
Beta Was this translation helpful? Give feedback.
-
Ok thanks for offering to help @btaba ! I include the code and the trace below. I have created a new environment where I add a sphere and I want to change the color of the sphere when the speed of the ant is above 50 (before I said I want to change the color of the ant but I switched to this cause I found it easier to implement, I was not sure how to access the color of the ant. in any case if any of the two works it should be easy to generalize). So I have created an ant_change_color.py under brax/envs (pasted below) which differs from ant.py in that:
Code for the environment:
Modified
The code for running training and evaluation:
|
Beta Was this translation helpful? Give feedback.
-
Let's say I would like to make the ant red if its speed exceeds a certain lower threshold (this is just a simple example of the general setting I have in mind where multiple bodies would change color under certain conditions).
I am not sure what is the correct way to implement this. I have thought of modifying the step function in the following way:
Maybe this is wrong to begin with and I should better introduce an additional variable in the pipeline_state? But I am not sure how once can do that.
For now my issue with my current implementation is jax-related: new_color is a traced array and inside modify_sys I am modifying the elementtree by instantating a string that has the new color value (e.g. "0 0 1 0"). So I have a list of string that I need to index based on the value of new_color and that throws an error. I tried converting new_color to a numpy array and then use it to index a list of string (using
jax.pure_callback
) but it remained traced.Beta Was this translation helpful? Give feedback.
All reactions