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

Bug in jax_md.colab_tools.renderer: The renderer does not plot time varying per particle parameters (e.g. diameter) #123

Closed
AlmaDalco opened this issue Feb 11, 2021 · 1 comment

Comments

@AlmaDalco
Copy link

The renderer has a bug: It cannot plot time varying parameters per particle.

Description of problem:
renderer.Disk can take as arguments time varying per particle parameters. See snippet of documentation:

 position: An array of shape `(steps, count, dim)` or `(count, dim)` 
 specifying possibly time varying positions. Here `dim` is the spatial dimension.
 size: An array of shape (steps, count)`, `(count,)`, or `()` specifying
 possibly time-varying / per-disk diameters.
 color: An array of shape `(steps, count, 3)` or `(count,)` specifying
 possibly time-varying / per-disk RGB colors.
 count: The number of disks.

However it seems to not be able to plot time varying parameters. It plots the parameter value at first timepoint and does not change the parameters at later timepoints.

How to reproduce bug: run following script

import numpy as onp
from jax import random
from jax_md.colab_tools import renderer
from jax.ops import index_update,index, index_add

n_timepoints = 4
n_particles = 10
#make a random array of positions with size: (n_timepoints,n_particles,2)
pos = 10* onp.random.rand(n_timepoints,n_particles,2)
#make an array of diamaters with size: (n_timepoints,n_particles)
#the diamaters of all particles could vary in time, in this example is always equal to one
diameter = np.ones((n_timepoints,n_particles))
#set one particle's diamater equal to 2 at first timepoint 
diameter = index_update(diameter,index[0,0],2)

#the renderer should plot the diamaters in time, but actually only plots diamaters at first timepoint 
#and indeed one particle has diameter 2 for all timepoint rather than just for first timepoint
renderer.render(box_size, 
                { 'particles': renderer.Disk(pos, diameter)},
                buffer_size=50)

renderer.render(box_size, 
                { 'particles': renderer.Disk(position, diameter, color)})```
sschoenholz added a commit that referenced this issue Feb 11, 2021
Fixes a bug identified by #123. 

Previously, the rendering code erroneously indexed into `FRAME_COUNT * stride` in dynamically varying attributes. The correct index is `CURRENT_FRAME * stride`.
@sschoenholz
Copy link
Collaborator

Thanks for identifying this bug. The rendering code is probably some of the lightest tested. I implemented a fix; if you continue to see any problems don't hesitate to let me know!

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

No branches or pull requests

2 participants