hamzah's Blog

PyElastica: Simulation Visualization - Week 6 - 25/07/2022

hamzah
Published: 07/28/2022

Week 6 Status Update - 25/07/2022

Having discussed it with my mentors, I will be taking some time off and extending project, so I can focus on some upcoming things I have over the next few weeks outside of GSoC. 

This week I cleaned up a lot of the core visualization code into a stable library that can be used to visualized PyElastica simulations, and move it into a new repo that I will build upon for the rest of this project with some examples. A lot of the main features and code have been excluded and are still in my development repo for stability, so the visualization tool is pretty basic at the moment, but seems to work well with various PyElastica simulations, and should serve as a good foundation to build upon for the second half of the project when I return.

You can find the repo here.

See you in a few weeks :)

View Blog Post

PyElastica: Simulation Visualization - Week 5 - 18/07/2022

hamzah
Published: 07/28/2022

Owing to some personal reasons, I was unfortunately unable to spend any significant time on the project this week. I have discussed with my mentors, and given that I will unlikely be able to commit to this project to the level I would like to over the next few weeks, we have decided it would be best to extend the project so I can focus on some of the other stuff I have going on right now, and comeback to the project in a few weeks when I will have more time and continue the work I have done in the project so far.

View Blog Post

PyElastica: Simulation Visualization - Week 3 - 04/07/2022

hamzah
Published: 07/28/2022

Week 3 Status Update - 04/07/2022

The third week of GSoC has now passed, and I feel as if the project is going well so far. With the first two weeks of GSoC mainly involving a lot of testing of different ways of approaching how to visualize PyElastica simulations, mainly what libraries to use, if any, and how to approach visualizing the simulations, this week was more focused on getting some visualisations up an running, and expanding the visualization code so it can be used in a more general plug-and-play fashion.

What I Did This Week

As mentioned above, most of this time this week was spent visualizing different PyElastica simulations, focusing on what and how data should be passed to the visualisation method, in order to eventually progress towards a general visualisation function. A lot of time was also spent on delving deeper into the workings of the visualisation library that I will be using for this project, VisPy, to work on two things; improving the speed and efficiency of the visualization, and adding more features.

Some of the key features that were implemented this week is the ability to save the visualization as a video, which is of course a crucial feature, and things like adding a timer to the visualization to show the simulation time and different camera modes to give greater interactivity during the visualization.

Here is a simple PyElastica simulation that has been visualised, it's not super interesting and quite basic but gives an idea for what the visualization looks like:

What I Plan To Do Next Week

Having made some good progress this week, the aim over the next week or two is to get the visualization code wrapped into a class that provides a good foundation to build the various planned features on. A key aim for this project is that the visualization function should be easy to use, easily integrable into existing PyElastica code, and able to work with any PyElastica simulation. Deciding on the design of the visualization class will be important to achieving these goals, so will need to be given consideration, and different methods tested.

 

What Issues I Faced

There were not any significant issues that came up this week. The main complications I would say was ensuring the visualization terminates properly during saving it as a video, and as more features were added, how best to update the different parts of the visualization between each frame so as to have it running as smoothly and efficiently as possible, These are not really issues, but just require some thought on how to tackle them and go about it.

 

 

  

View Blog Post

PyElastica: Simulation Visualization - Week 2 - 27/06/2022

hamzah
Published: 07/28/2022

Week 2 Blog Post - 27/06/2022

For the second week of the GSoC 2022 and the second post, I think it would be nice to do a bit more of a blog post on a python feature that I have been experimenting with this week, which is the nonlocal statement.

Nonlocal

The nonlocal statement is a less well know feature in Python, which is used non-local, non-globally scoped variables. As described in the Python documentation:

The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope excluding globals. This is important because the default behavior for binding is to search the local namespace first. The statement allows encapsulated code to rebind variables outside of the local scope besides the global (module) scope.

While the use-cases are not plentiful, it can be used in nested functions, where you need to access a variable in the "parent" function from a nested "child" function within it. While this can be done using global variables, giving local variables global scope may cause unwanted issues. The best way to illustrate the usage of the nonlocal statement is with an example:

def f():
    x = 0
    def increment_x():
        x += 1
    increment_x()
    return x

print(f())

Running the above code, you will get the error, UnboundLocalError: local variable 'x' referenced before assignment. This is where the nonlocal statement can be used. By modifying the above code using the nonlocal statement, we have 

def f():
    x = 0
    def increment_x():
        nonlocal x
        x += 1
    increment_x()
    return x

print(f())

and the program now works as we would like it to.

Why use the nonlocal statement

In my project of creating a visualizer for PyElastica simulations, we use a visualization library. When updating the visualization, a function is called between each frame to run the code to calculate what the next frame should be visualizaing (in our case it is used to update the new position of the simulation objects in that frame). Now if the main code for the visualization is in the global scope of the python file, ie. outside of any function and in the main body of the python script, then this update function works fine. But as we would like for the visualization code to be wrapped in a function to be imported by users of the library into their own scripts, we have to deal with scoping issues, which in this case can be sorted using the nonlocal statement.

It is unlikely that I will be using the nonlocal statement, as there are better ways of achieving what I want in this particular case, namely using classes. However, I thought it was an interesting, less-common Python feature that I myself was not too familiar with, and would make a nice topic for the blog post for this week.

 

View Blog Post

PyElastica: Simulation Visualization - Week 1 - 20/06/2022

hamzah
Published: 06/27/2022

Week 1 Status Update - 20/06/2022

Today marks one week since the official start of GSoC 2022 and I thought I should start off the project blog by giving a quick rundown on the proposed project, and the progress made so far in the first week.

Project Overview

PyElastica is an open-source Python library that can be used to assemble cosserat rods into structures and simulate their behaviour. 

As best explained by the PyElastica documentation:

The theory of Cosserat rods is a method of modeling 1D, slender rods accounting for bend, twist, stretch, and shear; allowing all possible modes of deformation to be considered under a wide range of boundary conditions. It models the rod as a deformable curve with attached deformable vectors to characterize its orientation, and evolves the system using a set of coupled second-order, nonlinear partial differential equations.

These cosserat rods can be used to build up complex and dynamic systems, from birds’ nests made of twigs to living creatures made of bones, tendons, fibers and muscles

With the large scale of systems that can be simulated in PyElastica, and the difficulty in understanding the behaviour of these systems from the large amounts of numerical data, visualization tools can be invaluable in helping to debug, understand and improve these simulations.

This Summer, I will be working on the PyElastica library to build a set of visualization tools that can be used to visualize the varying systems that can created and simulated in PyElastica.

What I Did This Week

As my project is quite open in the sense that there has not been much prior work on visualization in PyElastica and that I have a lot of control over the design and features of the visualization tools, it is very important to spend time to explore the different ways of approaching the project.

One important choice is the which visualization library to use. From discussions with my mentors, I am currently exploring two main libraries: VisPy and FURY. Both have their advantages and disadvantages, which are important to understand and evaluate to help decided on which to use going forward. Having spent some time during the community bonding period gaining familiarity with the two libraries, I spent this week working on visualizing some of the different example simulations found in the PyElastica documentation, and exploring some of the different features that could be included into the visualizations such as keyboard interactivity.

What I Plan To Do Next Week

Next week's plan is to continue on the progress made during this week, working on getting a better understanding of the respective visualization libraries. I also plan on making progress towards generalizing the visualization code, so we are able to visualize a variety of different systems through the same functions and tools.

Some consideration will also be given to the design of the visualization functions as we begin to build the general visualization tools for the library, and how we would like for PyElastica users to use the tools to easily and robustly visualize their respective systems with minimal effort.

What Issues I Faced

Fortunately, this week was mostly smooth sailing. I did face some minor issues with dependency issues and installation errors with the visualization libraries, however these were easily fixed. This did however raise a point to be aware of, which is to ensure that installation of the visualization tools and its dependencies are as straightforward as possible for PyElastica users, and will need some consideration as we get closer to release of the visualization tools.

Overall, however, it was a productive and useful first week, and I look forward to continuing the progress and working on the project in the coming weeks :).

View Blog Post
DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (28 rendered)

Cache calls from 1 backend

Signals

Log messages