I got the idea the other day to see if I could get Visula wrapped in Python using PyO3. Last time I played around with PyO3 I was very impressed by how easy it was to use. And once again, making a Python wrapper with PyO3 was a lot of fun.

Visula is my experimental visualization library written in Rust using WebGPU. The goal of the library is to make it easy to create high-performance visualizations from data. And in particular, dynamic visualizations where you can efficiently modify the parameters or data without re-computing all the modifications on the CPU. With Visula, I want to speed up this process by performing the modifications on the GPU instead.

Take for instance this parametric function definition:

def points(t, a, b, c):
    x = cos(a * t) + cos(b * t) / 2.0 + sin(c * t) / 3.0
    y = sin(a * t) + sin(b * t) / 2.0 + cos(c * t) / 3.0
    z = t
    return x, y, z

Here I have visualized the function by placing a number of points along the curve and by changing the parameters:

If the input value t was a NumPy array and the functions cos and sin come from the NumPy library, then the output always needs to be recomputed on the CPU for every change to the parameters a, b and c. This is no problem if you have a few thousand points, but if you want it to update smoothly in real time for millions of points, you it is way more efficient to perform this on the GPU. Otherwise, the updates are simply too slow to render as a nice animation.

To achieve this in Visula, the above cos and sin functions are lazily evaluated. Their evaluation is postponed all the way to the shader code, such that I only need to upload the values for t to the GPU once. The evaluation of the output happens fully on the GPU from there on. This makes the animation way smoother.

By making Visula available as a Python library, I hope it can become even more useful for me personally (and others once it is a bit more stable). I often come across some data that I want to quickly visualize and explore by modifying various parameters.