Articles on hamzah's Bloghttps://blogs.python-gsoc.orgUpdates on different articles published on hamzah's BlogenThu, 28 Jul 2022 21:07:27 +0000PyElastica: Simulation Visualization - Week 6 - 25/07/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-6-25-07-2022/<h1><u>Week 6 Status Update - 25/07/2022</u></h1> <p>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. </p> <p>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.</p> <p>You can find the repo <a href="https://github.com/hh-19/PyElasticaVisualizer">here</a>.</p> <p>See you in a few weeks :)</p>hamzah1906@gmail.com (hamzah)Thu, 28 Jul 2022 21:07:27 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-6-25-07-2022/PyElastica: Simulation Visualization - Week 5 - 18/07/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-5-18-07-2022/<p>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.</p>hamzah1906@gmail.com (hamzah)Thu, 28 Jul 2022 19:56:31 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-5-18-07-2022/PyElastica: Simulation Visualization - Week 4 - 11/08/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-4-11-08-2022/hamzah1906@gmail.com (hamzah)Thu, 28 Jul 2022 19:51:24 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-4-11-08-2022/PyElastica: Simulation Visualization - Week 3 - 04/07/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-3-04-07-2022/<h1><u>Week 3 Status Update - 04/07/2022</u></h1> <p>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.</p> <h2><u>What I Did This Week</u></h2> <p>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.</p> <p>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.</p> <p>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:</p> <p><iframe height="360" src="https://www.youtube.com/embed/zMVmaF_rgWc" width="640"></iframe></p> <h2><u>What I Plan To Do Next Week</u></h2> <p>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.</p> <p> </p> <h2><u>What Issues I Faced</u></h2> <p>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.</p> <p> </p> <p> </p> <p>  </p>hamzah1906@gmail.com (hamzah)Thu, 28 Jul 2022 19:50:44 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-3-04-07-2022/PyElastica: Simulation Visualization - Week 2 - 27/06/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-2-27-06-2022/<h1><u>Week 2 Blog Post - 27/06/2022</u></h1> <p>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 <code>nonlocal </code>statement.</p> <h2><u><code>Nonlocal</code></u></h2> <p>The nonlocal statement is a less well know feature in Python, which is used non-local, non-globally scoped variables. As described in the <a href="https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement">Python documentation</a>:</p> <blockquote> <p>The <a href="https://docs.python.org/3/reference/simple_stmts.html#nonlocal"><code>nonlocal</code></a> 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.</p> </blockquote> <p>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 <code>global</code> 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:</p> <pre><code class="language-python">def f(): x = 0 def increment_x(): x += 1 increment_x() return x print(f()) </code></pre> <p>Running the above code, you will get the error, <code>UnboundLocalError: local variable 'x' referenced before assignment.</code> This is where the nonlocal statement can be used. By modifying the above code using the nonlocal statement, we have </p> <pre><code class="language-python">def f(): x = 0 def increment_x(): nonlocal x x += 1 increment_x() return x print(f())</code></pre> <p>and the program now works as we would like it to.</p> <h2><u>Why use the nonlocal statement</u></h2> <p>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.</p> <p>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.</p> <p> </p>hamzah1906@gmail.com (hamzah)Thu, 28 Jul 2022 19:49:02 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-2-27-06-2022/PyElastica: Simulation Visualization - Week 1 - 20/06/2022https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-1-20-06-2022/<h1><u>Week 1 Status Update - 20/06/2022</u></h1> <p>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.</p> <h2><u>Project Overview</u></h2> <p>PyElastica is an open-source Python library that can be used to assemble cosserat rods into structures and simulate their behaviour. </p> <p>As best explained by the <a href="https://www.cosseratrods.org/">PyElastica documentation</a>:</p> <blockquote> <p>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.</p> </blockquote> <p>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</p> <p>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.</p> <p>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.</p> <h2><u>What I Did This Week</u></h2> <p>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.</p> <p>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.</p> <h2><u>What I Plan To Do Next Week</u></h2> <p>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.</p> <p>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.</p> <h2><u>What Issues I Faced</u></h2> <p>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.</p> <p>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 :).</p>hamzah1906@gmail.com (hamzah)Mon, 27 Jun 2022 20:25:05 +0000https://blogs.python-gsoc.org/en/hamzahs-blog/pyelastica-simulation-visualization-week-1-20-06-2022/