<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saransh Chopra on Medium]]></title>
        <description><![CDATA[Stories by Saransh Chopra on Medium]]></description>
        <link>https://medium.com/@whiteviolin?source=rss-273d2033adac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mOVNOXJgBIGyCntRrDTIYA.jpeg</url>
            <title>Stories by Saransh Chopra on Medium</title>
            <link>https://medium.com/@whiteviolin?source=rss-273d2033adac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:45:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@whiteviolin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[My experience working as a Technical Writer with FluxML]]></title>
            <link>https://blog.devgenius.io/my-experience-working-as-a-technical-writer-with-fluxml-2c19ab814089?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c19ab814089</guid>
            <category><![CDATA[flux]]></category>
            <category><![CDATA[julia]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[technical-writing]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Wed, 27 Jul 2022 17:22:20 GMT</pubDate>
            <atom:updated>2022-08-01T20:05:38.623Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“One thing that open-source can’t get enough of is documentation” — Anonymous</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lKBsvZlO7OvUuBhM" /></figure><p>This summer, I started working as a technical writer with FluxML under Julia Season of Contributions, and as expected, this experience was very different from writing code.</p><p>During the beginning of the summer, I decided to take up a technical writer’s job that involved writing documentation and tutorials for Machine Learning. At the same time, I was learning Julia, and the FluxML ecosystem sounded like a perfect place for me. I applied for the position through Google Season of Docs but unfortunately couldn’t get in because of limited openings. Fortunately, Julia Language decided to fund me for the next few months to work on FluxML under Julia Season of Contributions!</p><p>In the following blog, I will share my experience and the work I have done so far as a part of Julia Season of Contributions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*q6JXOCVKV1iFaSdF.jpg" /></figure><h3>Doctests</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/0*8GSRfjMTA_bTMlYF.jpg" /></figure><p>Flux’s documentation lacked doctests, making its code examples stale after each release. Further, many current examples thought to be covered by doctests, were already outdated.</p><p>Some of the doctests were straightforward to add, but most of them require in-depth discussions with the mentors and the community members. In addition, the documentation written in markdown format also required periodic testing to ensure that the changing API does not break the examples.</p><p>Flux.jl now has doctests written for every single public API, and most of the markdown example are also covered under these doctests. Some of these changes haven’t been merged yet, but they are under review!</p><h3>Missing docstrings</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/0*8kn0CXy4r7I1OXw6.jpg" /></figure><p>Some of Flux’s public API is also undocumented, or has a relatively less clear documentation. For example, most of the neural network layers provided by Flux have two constructors — one for initializing layers with pre-defined weights and biases and another for generating weights and biases from a distribution. In most cases, only one constructor was documented, and the other was not.</p><p>Other such instance of missing docstrings was Flux‘s manual. Here the docstrings were present in the codebase, but they were not present in the manual. Such cases were solved by adding the docstrings to the manual or creating a new section for such missing docstrings.</p><p>In addition to Flux, other packages under FluxML also had a similar problem. Some of these packages like NNLib.jl, Zygote.jl, Optimisers.jl, Functors.jl, and MLUtils.jl (under JuliaML) were also referenced in Flux‘s documentation. The missing docstrings in these packages were transmitted to Flux‘s docs, resulting in even more missing docstrings.</p><p>All the missing docstrings have now been added to the respective manuals and functions, including that of other FluxML packages!</p><h3>Broken documentation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*MarZNCzdnOb8c2vy.jpg" /></figure><p>Documentation is incomplete without cross-references, and Julia’s wonderful documentation package makes this easy. Flux has these cross-references in place, but some of them lead to nowhere.</p><p>Additionally, some of the docstrings were not rendered correctly in the manual. These instances of broken documentation have been fixed, and once the PR is merged, users should not see 404 pages or un-rendered docstrings anymore!</p><h3>CI/CD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*k6C11T4CR0B75GMy.jpg" /></figure><p>The user-facing documentation is facilitated by a CI/CD service, which keeps this documentation deployed and available to users at all times. It is also common for open-source projects to open-source their deployment recipes.</p><p>FluxML‘s ecosystem had some minor issues in this CI service. Zygote.jl had doctests running twice, using twice the CI time and resources, and on the other hand, Flux.jl specified different versions of Julia in its CI and make.jl file.</p><p>Further, Documenter.jl allows a user to generate documentation previews for pull requests, and Flux.jl had a bot set up to facilitate this, but it was down for a long time. In addition, these documentation previews are collected in the gh-pages branch, which was getting very bulky and had to be cleaned up with an automated workflow. I restarted this bot and added a workflow for cleaning these generated previews periodically!</p><p>Finally, I also fixed some issues in Optimisers.jl‘s documentation that were causing its CI to fail.</p><h3>FluxML’s ecosystem</h3><p>The FluxML ecosystem, in addition to Flux.jl, also had some documentation problems. For instance, Optimisers.jl and Zygote.jl had shortcomings in their CI suite, which have been discussed above. Similarly, Functors.jl and MLUtils.jl had broken documentation, missing docstrings, and an incomplete manual, which has also been discussed in great detail above!</p><p>Lastly, the “ecosystem” pages present on Flux‘s website and documentation were out of sync and had redundant information. The “ecosystem” page was completely revamped and updated with the latest advancements related to Machine Learning in Julia!</p><h3>Minor code changes</h3><p>Yes! The documentation changes were also accompanied by minor code changes!</p><p>Flux‘s public and internal API is very hard to differentiate if you are new to the codebase; hence, newcomers used to find it hard to navigate through this. The API was made clear by removing internal instances from the documentation and prepending an underscore to the internal API.</p><p>Furthermore, I also stumbled upon a bug while writing doctests for tversky loss. The tversky loss has two parameters, <em>α</em>, and <em>β</em>, and Flux internally calculates the value of <em>α </em>as 1-<em>β</em>. The loss mathematically is defined as 1-tversky index, and the tversky index mathematically is defined as:</p><blockquote>S(P, G; α, β) = |P G| / (|P G| + α|P \ G| + β|G \ P|)<br>where α and β control the magnitude of penalties for FPs and FNs, respectively.</blockquote><p>Flux implements the loss in the following way -</p><pre>1 — sum(|y .* ŷ| + 1) / (sum(y .* ŷ + β*(1 .- y) .* ŷ + (1 — β)*y .* (1 .- ŷ)) + 1)</pre><p>with the following code -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60987f679d38093693060cf6cd2c154c/href">https://medium.com/media/60987f679d38093693060cf6cd2c154c/href</a></iframe><p>Notice how the term (1 .- y) .* ŷ (False Positives) is multiplied by <em>β</em>, whereas it should be multiplied with <em>α</em> (which is 1-<em>β</em>). Similarly, the term y .* (1 .- ŷ) is multiplied with <em>α</em> (that is 1-<em>β</em>), whereas it should be multiplied with <em>β</em>.</p><p>This detail makes the loss function behave in a manner opposite to its documentation. For example -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdd7be2a3975aa15d1ea610f6a018566/href">https://medium.com/media/cdd7be2a3975aa15d1ea610f6a018566/href</a></iframe><p>Here the loss for ŷ_fnp, y should have been larger than the loss for ŷ_fp, y as the loss should give more weight or penalize the False Negatives (default <em>β</em> is 0.7; hence it should give more weight to FN), but the exact opposite happens.</p><p>Changing the implementation of the loss yields the following results -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1092d95204c9aa163a3736bd3b8f14d1/href">https://medium.com/media/1092d95204c9aa163a3736bd3b8f14d1/href</a></iframe><p>which looks right!</p><p>(This bug has not been confirmed by someone other than me yet, and the fix is still under review.)</p><h3>Getting started section</h3><p>Flux has a lot of tutorials and examples, but they are scattered around and very hard to navigate through. The current “Getting Started” section, “Overview” section, and “Basics” section have valuable information for beginners, but the information is scattered among these three sections.</p><p>Additionally, one of these three sections is on Flux’s website, and two are available on the documentation website, making it difficult for newcomers to navigate between these hackable yet basic examples. Instead, these three tutorials could be moved out of their current places and combined under a single section named “Getting Started”, which could then be added to the documentation and linked on the website.</p><p>I have started working on this section, and two extensive tutorials have already been added as PRs: one on linear regression (with and without Flux) and one on logistic regression (with and without Flux). These PRs are currently under review and should be merged in the upcoming weeks.</p><p>I have had an incredible time contributing to Flux and its neighbor repositories, and I hope to continue these contributions with the same momentum. I have also learned a lot, including that documentation additions require more discussions than code additions.</p><p>This work wouldn’t have been possible without my mentor <a href="https://github.com/DhairyaLGandhi">@DhairyaLGandhi</a> and a lot of other FluxML’s maintainers (<a href="https://github.com/ToucheSir">@ToucheSir</a>, <a href="https://github.com/mcabbott">@mcabbott</a>, <a href="https://github.com/CarloLucibello">@CarloLucibello</a>, <a href="https://github.com/darsnack">@darsnack</a>). They have been very patient with my questions and messy PRs😆</p><h3>Appendix</h3><h4>Pull requests</h4><p><strong>Flux.jl</strong></p><ul><li>Add a ton of doctests + fix outdated documentation in .md files: <a href="https://github.com/FluxML/Flux.jl/pull/1916">https://github.com/FluxML/Flux.jl/pull/1916</a></li><li>Update docstrings of basic.jl and conv.jl: <a href="https://github.com/FluxML/Flux.jl/pull/1978">https://github.com/FluxML/Flux.jl/pull/1978</a></li><li>Update docstrings in upsample.jl, recurrent.jl, and normalise.jl: <a href="https://github.com/FluxML/Flux.jl/pull/1995">https://github.com/FluxML/Flux.jl/pull/1995</a></li><li>Miscellaneous docstring additions and fixes: <a href="https://github.com/FluxML/Flux.jl/pull/1998">https://github.com/FluxML/Flux.jl/pull/1998</a></li><li>Add MLUtils’s docs and fix some missing docstrings: <a href="https://github.com/FluxML/Flux.jl/pull/1910">https://github.com/FluxML/Flux.jl/pull/1910</a></li><li>Turn off doctests while building docs: <a href="https://github.com/FluxML/Flux.jl/pull/1915">https://github.com/FluxML/Flux.jl/pull/1915</a></li><li>Unify ecosystem.md: <a href="https://github.com/FluxML/Flux.jl/pull/1923">https://github.com/FluxML/Flux.jl/pull/1923</a></li><li>Get the DocBot up again!: <a href="https://github.com/FluxML/Flux.jl/pull/1937">https://github.com/FluxML/Flux.jl/pull/1937</a></li><li>Add a workflow to delete PR previews: <a href="https://github.com/FluxML/Flux.jl/pull/1943">https://github.com/FluxML/Flux.jl/pull/1943</a></li><li>Get rid of documentation warnings and 404 pages: <a href="https://github.com/FluxML/Flux.jl/pull/1987">https://github.com/FluxML/Flux.jl/pull/1987</a></li><li>Create a getting started section and add a new linear regression example: <a href="https://github.com/FluxML/Flux.jl/pull/2016">https://github.com/FluxML/Flux.jl/pull/2016</a></li><li>Add a logistic regression example to the Getting Started section: <a href="https://github.com/FluxML/Flux.jl/pull/2021">https://github.com/FluxML/Flux.jl/pull/2021</a></li></ul><p><strong>Zygote.jl</strong></p><ul><li>Run doctests only once: <a href="https://github.com/FluxML/Zygote.jl/pull/1255">https://github.com/FluxML/Zygote.jl/pull/1255</a></li></ul><p><strong>Optimisers.jl</strong></p><ul><li>Fix the doctests and the broken CI: <a href="https://github.com/FluxML/Optimisers.jl/pull/98">https://github.com/FluxML/Optimisers.jl/pull/98</a></li></ul><p><strong>Functors.jl</strong></p><ul><li>Fix missing docs and cross-references: <a href="https://github.com/FluxML/Functors.jl/pull/42">https://github.com/FluxML/Functors.jl/pull/42</a></li></ul><p><strong>MLUtils.jl</strong></p><ul><li>Add missing docstrings to the manual: <a href="https://github.com/JuliaML/MLUtils.jl/pull/95">https://github.com/JuliaML/MLUtils.jl/pull/95</a></li></ul><h4>Issues / discussions</h4><p><strong>Flux.jl</strong></p><ul><li>Missing docstring for Flux.Data.Dataloader: <a href="https://github.com/FluxML/Flux.jl/issues/1909">https://github.com/FluxML/Flux.jl/issues/1909</a></li><li>Different Julia versions at different places for doctests: <a href="https://github.com/FluxML/Flux.jl/issues/1914">https://github.com/FluxML/Flux.jl/issues/1914</a></li><li>Inconsistent “Julia ecosystem” docs: <a href="https://github.com/FluxML/Flux.jl/issues/1922">https://github.com/FluxML/Flux.jl/issues/1922</a></li><li>Add a workflow to clean-up gh-pages branch?: <a href="https://github.com/FluxML/Flux.jl/issues/1940">https://github.com/FluxML/Flux.jl/issues/1940</a></li><li>[Discussion]: doctests, docstrings, documentation manual, and unclear internal API (for newcomers): <a href="https://github.com/FluxML/Flux.jl/issues/1990">https://github.com/FluxML/Flux.jl/issues/1990</a></li><li>[Bug]: Swapped alpha and beta in tversky loss?: <a href="https://github.com/FluxML/Flux.jl/issues/1993">https://github.com/FluxML/Flux.jl/issues/1993</a></li><li>[Discussion]: Revamped Getting Started guide: <a href="https://github.com/FluxML/Flux.jl/issues/2012">https://github.com/FluxML/Flux.jl/issues/2012</a></li></ul><p><strong>Zygote.jl</strong></p><ul><li>Doctests running twice: <a href="https://github.com/FluxML/Zygote.jl/issues/1199">https://github.com/FluxML/Zygote.jl/issues/1199</a></li></ul><h3>Bonus</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*2SLqKWtR_dGZwRAm.jpg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c19ab814089" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/my-experience-working-as-a-technical-writer-with-fluxml-2c19ab814089">My experience working as a Technical Writer with FluxML</a> was originally published in <a href="https://blog.devgenius.io">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“execvp” system call in Python: Everything you need to know!]]></title>
            <link>https://blog.devgenius.io/execvp-system-call-in-python-everything-you-need-to-know-c402fe6886eb?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/c402fe6886eb</guid>
            <category><![CDATA[system-call]]></category>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[multiprocessing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Sat, 05 Mar 2022 19:51:58 GMT</pubDate>
            <atom:updated>2022-03-05T19:59:59.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/665/0*HkBTIFOl_pfD8i9z.jpg" /></figure><p>The exec family of the system calls is used to run a command or a code file in a new process. In Linux, this new process is created by replacing the process that made the exec call, but in Windows, things are a bit different. In this blog, we will be covering the execvp system call in Python. We will also be solving an interesting problem using the stuff learned throughout this blog!</p><h3>Problem statement and the motivation</h3><p>I was recently assigned an assignment for Operating Systems, which had an interesting question dealing with the execvp system call. Now, there are some implementations for this question available on the internet, but all of them are written in C. In pursuing a pythonic implementation, I went on a journey of exploration, and I will use it here as motivation! We will be applying the theoretical knowledge of execvp to solve this particular question at the end of this blog! The question -</p><blockquote>Write a collection of programs p1, p2 and p3 such that they execute sequentially with the same PID and each program should also print its PID. The user should be able to invoke any combination of these programs to achieve the required functionality. For example - Consider three programs twice, half and square which accept only one integer as argument and does some specific operation. These operations may be like -</blockquote><blockquote>$twice 10 prints 20 and some number which is its PID<br>$half 10 prints 5 and some number which is its PID<br>$square 10 prints 100 and some number which is its PID<br>Now the user should be able to combine these programs in any combination to achieve the desired result.</blockquote><blockquote>For example -<br>$twice square half twice half 10<br>should calculate <em>half(twice(half(square(twice(10)))))</em> and print <strong>200</strong> as result. It should also print the process ids of each program as it executes. <strong>Note that the process-id printed by each of these programs should be the same, in this case.</strong></blockquote><blockquote>$square twice 2<br>should calculate twice(square(2)) and print <strong>8 </strong>as result, and the process id of square and twice, which should be the same.</blockquote><blockquote>The evaluation order is from left to right</blockquote><blockquote>Note that the last argument is integer, and the remaining arguments are the programs to be invoked.</blockquote><blockquote>This should be generally applicable to any n number of processes, all of which are written by you.</blockquote><h3>Documentation!</h3><p>Let us start by going through the documentation of execvp -</p><pre>os.execvp(file, args)</pre><pre>These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process id as the caller. Errors will be reported as OSError exceptions.</pre><p>Key takeaways -</p><ol><li>All the exec calls are implemented in the os library.</li><li>os.execvp takes in 2 arguments, file and args.</li><li>The new process is not a child process but rather the new process substitutes the current process.</li><li>No return value.</li><li>On UNIX systems, the process ID (PID) remains the same as the caller.</li><li>Saving you some time, I discovered that the file is supposed to be an executable file and the args are supposed to have the executable file name too. We will look into this in more detail below!</li></ol><h3>A minimal example</h3><p>Now that we know some stuff about execvp, let us try using it in our code. The tradition is to start with a “Hello world” program, and we cannot go against the tradition. Further, we will be needing 2 Python files, a caller, and a file that prints “Hello world” -</p><h4>caller.py</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f13a4a1c7efdc0f502da49df28d8c33b/href">https://medium.com/media/f13a4a1c7efdc0f502da49df28d8c33b/href</a></iframe><h4>hello.py</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ec6512cfe6603d6d10a32c8c88ca6df/href">https://medium.com/media/4ec6512cfe6603d6d10a32c8c88ca6df/href</a></iframe><p>Notice how execvp in caller.py takes in the name of an executable file (python) as the first argument and the complete command (including the executable file’s name) as the second argument. Running caller.py gives us “Hello world”, everything as expected!</p><h3>Internals of execvp and playing with process IDs</h3><p>According to the documentation, execvp should replace the caller process with the new process instead of creating a subprocess in UNIX systems. This means that the process ID should not change when the system call is made. Let us try this out, but first, let us create 3 different files for 3 different functions — square, half, and double —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2166a5c01f611eeab87ad5c1780f6cd5/href">https://medium.com/media/2166a5c01f611eeab87ad5c1780f6cd5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b27fa83add9bdd49944f1580de43f7dd/href">https://medium.com/media/b27fa83add9bdd49944f1580de43f7dd/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b4479839f319eb51feb8f389044346e/href">https://medium.com/media/5b4479839f319eb51feb8f389044346e/href</a></iframe><p>The only new thing in these files is os.getpid(), which would return the process ID of the process running these files. Let us also modify our caller to execute one of these files —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fed523f8ec557efb22312689c515fef/href">https://medium.com/media/2fed523f8ec557efb22312689c515fef/href</a></iframe><p>We now check the process ID in our caller too. Additionally, to avoid making a mistake in the executable file’s name, we will be using sys.executable now! Executing caller.py in Windows gives us the following output -</p><pre>CALLER PID: 3156</pre><pre>DOUBLE PID: 20940 | RESULT: 20</pre><p>The results are definitely weird as the process IDs are not the same. Let us try the same code in WSL (Windows Subsystem for Linux) -</p><pre>CALLER PID: 34<br>DOUBLE PID: 34 | RESULT: 20</pre><p>The results match with the documentation! As the process IDs are the same, the caller process must’ve been replaced with a new process through the execvp system call. Note that we did not have to change the executable file’s name from python to python3 as sys.executable automatically picked it up!</p><p>Thus, os.execvp behaves differently on Windows and on UNIX systems. On Windows, it spawns or creates a new process (a child or a subprocess) whereas, on a UNIX system, it replaces the original process with a new process!</p><h3>Developing a CLI</h3><p>Now that we know how to use execvp in Python let us move on to our original question! Let us create a file to control everything through the command line —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e8656f9e7080306c7b56610130a1307/href">https://medium.com/media/2e8656f9e7080306c7b56610130a1307/href</a></iframe><p>This file, when executed, accepts a list of CLI arguments which are the function names and a number. The last CLI arg must be a number that has to be processed through various operations. A usage example for this file would be —</p><pre>python cli.py -l twice square half twice half 10</pre><p>which should internally translate to —</p><pre>half(twice(half(square(twice(10)))))</pre><p>and should print all the results and relevant process IDs.</p><p>Remember, os.execvp does not return anything. Hence, once a new python file is called for execution, the flow of control won’t come back to our CLI file. To tackle this we must add additional code in our operation functions which would call the next file without returning back to cli.py.</p><h3>Modifying the operation files</h3><p>The code in every operation file should be modified by adding —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64cd757b3e128d93998f6318a2d28219/href">https://medium.com/media/64cd757b3e128d93998f6318a2d28219/href</a></iframe><p>where operation is either double, half, or square.</p><p>The code takes in the last CLI argument using sys.argv[-1] and passes it into the relevant operation function. This last argument is then replaced with the obtained result, and all the CLI args except the first one are passed into os.execvp, which calls the next operation file!</p><p>In between, we also need to add a condition to exit if we have reached the last argument, which is a number. This last argument would be the final result as we would have processed all the arguments (function names) before that!</p><p>Let us modify every operation file —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/898d717003fda0e27c84bc8b354b73ed/href">https://medium.com/media/898d717003fda0e27c84bc8b354b73ed/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bd8ed52bebea03a778df0f8e96f2deb/href">https://medium.com/media/2bd8ed52bebea03a778df0f8e96f2deb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d38d0bbf0c350a13dcba95891b2f468e/href">https://medium.com/media/d38d0bbf0c350a13dcba95891b2f468e/href</a></iframe><p>These files will now call each other repeatedly and the whole system would work without returning to a previous file!</p><h3>Final results</h3><p>Running the following —</p><pre>python cli.py -l double square half double half 10</pre><p>on Windows results in —</p><pre>CLI PID: 7376<br>[&#39;double&#39;, &#39;square&#39;, &#39;half&#39;, &#39;double&#39;, &#39;half&#39;, &#39;10&#39;]</pre><pre>DOUBLE PID: 32496 | RESULT: 20.0<br>SQUARE PID: 15144 | RESULT: 400.0<br>HALF PID: 4860 | RESULT: 200.0<br>DOUBLE PID: 24928 | RESULT: 400.0<br>HALF PID: 27868 | RESULT: 200.0</pre><pre>FINAL PID: 27868 | FINAL RESULT: 200.0</pre><p>IT WORKS! The program gives us the desired output! Notice how the PIDs are not the same, something that was discussed in great detail above.</p><p>Running the following —</p><pre>python3 cli.py -l double square half double half 10</pre><p>on Windows Subsystem for Linux results in —</p><pre>CLI PID: 33<br>[&#39;double&#39;, &#39;square&#39;, &#39;half&#39;, &#39;double&#39;, &#39;half&#39;, &#39;10&#39;]</pre><pre>DOUBLE PID: 33 | RESULT: 20.0<br>SQUARE PID: 33 | RESULT: 400.0<br>HALF PID: 33 | RESULT: 200.0<br>DOUBLE PID: 33 | RESULT: 400.0<br>HALF PID: 33 | RESULT: 200.0</pre><pre>FINAL PID: 33 | FINAL RESULT: 200.0</pre><p>THIS WORKS TOO! The program gives us the desired output again! This time the PIDs stay the same as no subprocesses were created!</p><h3>Summary</h3><p>In the above blog, we understood how to use a system call belonging to the exec family of system calls. We further saw how the behavior of execvp differs in Windows and UNIX systems. In the end, we solved a question that had no Pythonic solution on the internet! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c402fe6886eb" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/execvp-system-call-in-python-everything-you-need-to-know-c402fe6886eb">“execvp” system call in Python: Everything you need to know!</a> was originally published in <a href="https://blog.devgenius.io">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ingesting Reddit memes into Elasticsearch using node.js: Locally and on Google Cloud]]></title>
            <link>https://blog.devgenius.io/ingesting-reddit-memes-into-elasticsearch-using-node-js-locally-and-on-google-cloud-d9ec61ccba95?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9ec61ccba95</guid>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[reddit]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 20:58:24 GMT</pubDate>
            <atom:updated>2022-01-17T06:59:03.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*nD6dbSJh5DLE0EVysqy5OA.png" /></figure><p>Elasticsearch is a relatively new and open-source search engine available for use to anyone in the world! It is blazingly fast and is surprisingly written in java! It uses the JSON format to store data that can be accessed by various HTTP methods. The service is also scalable, making it a perfect choice for big tech companies. Currently, companies like Uber, Netflix, Slack, and Microsoft use Elasticsearch to integrate searching functionality into their products. Elasticsearch recently changed its open-source license which resulted in Amazon releasing OpenSearch, a search engine created by forking Elasticsearch.</p><p>Elasticsearch uses something called an index to store all the information. Quoting the documentation -</p><blockquote>An index is like a ‘database’ in a relational database. It has a mapping which defines multiple types.</blockquote><blockquote>The easiest and most familiar layout clones what you would expect from a relational database. You can (very roughly) think of an index like a database.</blockquote><blockquote>MySQL =&gt; Databases =&gt; Tables =&gt; Columns/Rows<br>Elasticsearch =&gt; Indices =&gt; Types =&gt; Documents with Properties</blockquote><blockquote>An Elasticsearch cluster can contain multiple Indices (databases), which in turn contain multiple Types (tables). These types hold multiple Documents (rows), and each document has Properties(columns).</blockquote><p>Summarising the documentation, we need an index to store any kind of data in Elasticsearch. There can be multiple indeces, which can then store different data.</p><p>Additionally, Elasticsearch also comes with a family of other products which seamlessly integrate with it. The original members of this family were Logstash and Kibana, together creating the famous ELK stack!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/0*LaU4LXMBasjVhmFW.png" /></figure><p>In 2015, Elastic came up with a new family member called Beats, but unfortunately, this new stack has no official name :( We won’t be covering these family members in this article, but we might touch on kibana at the end ;)</p><h3>Firing up Elasticsearch (locally)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*7dwP5sAGpE5Yonyh.jpg" /></figure><p>Let us begin by firing up Elasticsearch locally, using our classic command prompt -</p><ol><li>Install Elasticsearch if you haven’t already from <a href="https://www.elastic.co/downloads/elasticsearch">here</a>.</li><li>Navigate to the downloaded file and unzip it if required.</li><li>Fire up your command prompt or terminal in the downloaded file and launch the Elasticsearch service by running bin/elasticsearch.</li></ol><p>The service will start running on <a href="http://localhost:9200/">http://localhost:9200/</a> or on a port mentioned in your command prompt/terminal!</p><h3>A new node.js project</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*98WUyZT7fRL1-3oc.jpg" /></figure><p>We can now create a new node.js project to code out our server -</p><ol><li>Create a new empty folder. I will be naming it node_elastic.</li><li>Run npm init and select your configurations. I will be putting my entry point as server.js instead of the default index.js.</li><li>This will create a package.json file in your current directory. In my case, the package.json file looks like this -</li></ol><pre>{<br>  &quot;name&quot;: &quot;node_elastic&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Scraping and ingesting Reddit memes into Elasticsearch using node.js&quot;,<br>  &quot;main&quot;: &quot;server.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;author&quot;: &quot;Saransh-cpp&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p>As a final step, let us add a new script to make the development process a bit smoother -</p><pre>&quot;start&quot;: &quot;node server.js&quot;</pre><p>The complete json file now -</p><pre>{<br>  &quot;name&quot;: &quot;node_elastic&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Scraping and ingesting Reddit memes into Elasticsearch using node.js&quot;,<br>  &quot;main&quot;: &quot;server.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,<br>    &quot;start&quot;: &quot;node server.js&quot;<br>  },<br>  &quot;author&quot;: &quot;Saransh-cpp&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><h3>Creating Elasticsearch client</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/0*1mNxPsWy-er1XbeD.jpg" /></figure><p>We will be using a javascript library named elasticsearch to interact with our local deployment of Elasticsearch. Let us install it in our working directory -</p><pre>npm i elasticsearch</pre><p>Now, we can create a Client object through which we will be able to access various HTTP methods. Here, I create a new javascript file named client_local.js (replace the &quot;host&quot; value if your deployment in on a different port number) -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caf323ebbe7298882b12b30795383dff/href">https://medium.com/media/caf323ebbe7298882b12b30795383dff/href</a></iframe><h3>Creating an index</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*w1cAPYoLH2pmJAFL.jpg" /></figure><p>We can now use the client created above to create an index. Let us code a new file create.js -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e82fb51cfac7f998b0ca19e655fc056/href">https://medium.com/media/6e82fb51cfac7f998b0ca19e655fc056/href</a></iframe><p>Running the file coded above using node create.js should create a new index in your local deployment of Elasticsearch and should not give any output. If running the code for the first time gives you an error then your deployment might not be right, or you might have switched the local deployment off. Running the file again should give you an error saying -</p><pre>index [memes/&lt;index_uuid&gt;] already exists</pre><p>This confirms that our index has been created! You can also delete the created index by simply replacing create with delete in the create.js file.</p><h3>Fetching a meme from Reddit</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*BjS1WXBwOzn2BcGo.jpeg" /></figure><p>Before ingesting our meme data into Elasticsearch we actually need some data. Let us fetch a meme’s URL through Reddit’s open API and another javascript library called axios. Let us quickly install the library -</p><pre>npm i axios</pre><p>We will be sending an http get request to Reddit’s meme subreddit through the URL — <a href="https://reddit.com/r/memes.json.">https://reddit.com/r/memes.json.</a> After digging (you can use any popular chrome extension to prettify the json) a bit through the massive json displayed at this URL, I was able to figure out that a meme’s URL is present at -</p><pre>[&quot;data&quot;][&quot;children&quot;][num][&quot;data&quot;][&quot;url_overridden_by_dest&quot;]</pre><p>and a meme’s title is present at -</p><pre>[&quot;data&quot;][&quot;children&quot;][num][&quot;data&quot;][&quot;title&quot;]</pre><p>where num is any positive integer less than the maximum number of memes displayed. We can now create a new js file to scrape meme URLs and titles -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25d485b725a9f44687f063d5cc55001a/href">https://medium.com/media/25d485b725a9f44687f063d5cc55001a/href</a></iframe><h3>Ingesting our data into Elasticsearch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*wnNOqwYdhf4EZ3x5.jpg" /></figure><p>Now we combine everything we coded above to create server.js, which will ingest the scraped meme data into our locally deployed Elasticsearch. We will scrape 100 such URLs and titles and store them in the index memes (that we created above).</p><p>We can append our data into the associated index using the index method of our client -</p><pre>client.index({  <br>     index: &#39;memes&#39;,<br>     body: {<br>         url: memeURL,<br>         title: memeTitle<br>     }<br>}, (err, resp, status) =&gt; {<br>     console.log(resp);<br>});</pre><p>In the code, I will also be clearing (using deleteByQuery and setting match_all to {}) the index before the ingestion takes place, just to make sure that we don’t have any old data stored.</p><p>The final code (limit query in the URL is the number of memes we want) -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b63151392779648de31caabb9ee28660/href">https://medium.com/media/b63151392779648de31caabb9ee28660/href</a></iframe><p>If you remember, we created a “start” script when we were creating our npm project. Let us use that to run our server -</p><pre>npm start</pre><p>As soon as you run this, you should see about 100 records being printed to your terminal as and when they are appended to your index’s body! We have finally added some data to our local Elasticsearch deployment! Hooray!</p><p>Running the following code -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17175674fa08590af12785af096b8174/href">https://medium.com/media/17175674fa08590af12785af096b8174/href</a></iframe><p>should give you a positive output (as we are searching everything there is in the index memes) -</p><pre>{<br>  took: 60,<br>  timed_out: false,<br>  _shards: { total: 1, successful: 1, skipped: 0, failed: 0 },<br>  hits: {<br>    total: { value: 100, relation: &#39;eq&#39; },<br>    max_score: 1,<br>    hits: [<br>      [Object], [Object],<br>      [Object], [Object],<br>      [Object], [Object],<br>      [Object], [Object],<br>      [Object], [Object]<br>    ]<br>  }<br>}</pre><p>We’re done! Now we can use this data anywhere!</p><h3>Deploying and ingesting data on Google Cloud</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/0*_LyroUKVhp285hJk" /></figure><p>We’re in the endgame now! Let us deploy Elasticsearch on Google Cloud -</p><ol><li>Go to <a href="https://www.elastic.co/pricing/">https://www.elastic.co/pricing/</a> and select the free 14-day trial (Note: Save the ID and password displayed somewhere safe).</li><li>Select the option “Explore on my own”.</li></ol><p>You will be redirected to a screen looking similar to -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRN5XxA3DxTNMY2VwVPkdQ.png" /></figure><p>Now, click on the hamburger icon and select go to “Manage this deployment”. You should be redirected to a screen containing Elasticsearch‘s endpoint and your &quot;Cloud ID&quot;. Copy and store both of them!</p><p>Finally, we’re ready to write some javascript to ingest data in Google Cloud deployed Elasticsearch -</p><ol><li>Store the Cloud ID, username, and password in your environment variables with the names CLOUD_ID, USERNAME, and PASSWORD respectively.</li><li>Go to your Elasticsearch‘s endpoint and make sure that you are able to log in with the copied username and password.</li><li>Create a new javascript file client_cloud.js -</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ee6bd177436e7ed748646bcc0e0aaf2/href">https://medium.com/media/4ee6bd177436e7ed748646bcc0e0aaf2/href</a></iframe><p>Note: the URL should be your Elasticsearch‘s endpoint.</p><p>Hooray! Our client is now available for creating indexes and for ingesting data. Running the code above should give you no errors.</p><p>We can now replace our require statements -</p><pre>var client = require(&#39;./client_local.js&#39;);</pre><p>to -</p><pre>var client = require(&#39;./client_cloud.js&#39;);</pre><p>in create.js and server.js.</p><p>To create a new index, simply run the code present in create.js and BOOM! We have a whole new index now! We can use kibana to check if our index was created successfully. A complete kibana tutorial will be out of the scope of this blog but we can still touch upon it ;) -</p><ol><li>Open the hamburger menu in your Elasticsearch deployment.</li><li>Navigate to management and click on devtools.</li></ol><p>You should be redirected to a screen looking like this -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIAeSmMUSbHbr-rUb4uBYw.png" /></figure><p>Add the following lines in the left panel and hit run -</p><pre>GET memes/_search<br>{<br>  &quot;query&quot;: {<br>    &quot;match_all&quot;: {}<br>  }<br>}</pre><p>The output, on the right panel, should look something like this -</p><pre>{<br>  &quot;took&quot; : 0,<br>  &quot;timed_out&quot; : false,<br>  &quot;_shards&quot; : {<br>    &quot;total&quot; : 1,<br>    &quot;successful&quot; : 1,<br>    &quot;skipped&quot; : 0,<br>    &quot;failed&quot; : 0<br>  },<br>  &quot;hits&quot; : {<br>    &quot;total&quot; : {<br>      &quot;value&quot; : 0,<br>      &quot;relation&quot; : &quot;eq&quot;<br>    },<br>    &quot;max_score&quot; : null,<br>    &quot;hits&quot; : [ ]<br>  }<br>}</pre><p>No errors! You can explore more such commands through kibana‘s documentation!</p><p>Let us now run our server.js by editing the require statement. You should again see around 100 meme URLs and titles being printed on your terminal, and then being ingested into Elasticsearch!</p><p>Running the same query again in kibana should now get you the ingested data of the first 10 memes!</p><pre>{<br>  &quot;took&quot; : 89,<br>  &quot;timed_out&quot; : false,<br>  &quot;_shards&quot; : {<br>    &quot;total&quot; : 1,<br>    &quot;successful&quot; : 1,<br>    &quot;skipped&quot; : 0,<br>    &quot;failed&quot; : 0<br>  },<br>  &quot;hits&quot; : {<br>    &quot;total&quot; : {<br>      &quot;value&quot; : 100,<br>      &quot;relation&quot; : &quot;eq&quot;<br>    },<br>    &quot;max_score&quot; : 1.0,<br>    &quot;hits&quot; : [<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;DtBrWn4B1NYkqWeI3ZWx&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/b6rraassqnb81.gif">https://i.redd.it/b6rraassqnb81.gif</a>&quot;,<br>          &quot;title&quot; : &quot;The sword will not cut&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;FdBrWn4B1NYkqWeI3ZXI&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/vxp1izvzfob81.jpg">https://i.redd.it/vxp1izvzfob81.jpg</a>&quot;,<br>          &quot;title&quot; : &quot;that&#39;s my first post here, hope you like It :)&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;z3xrWn4BGc7VZGO83X6t&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/b12i54rfgmb81.gif">https://i.redd.it/b12i54rfgmb81.gif</a>&quot;,<br>          &quot;title&quot; : &quot;Very sadge&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;0nxrWn4BGc7VZGO83X6w&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/tpor5kmpjmb81.gif">https://i.redd.it/tpor5kmpjmb81.gif</a>&quot;,<br>          &quot;title&quot; : &quot;Its always clickbait&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;JdBrWn4B1NYkqWeI3pUZ&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/1cw59ws6qmb81.gif">https://i.redd.it/1cw59ws6qmb81.gif</a>&quot;,<br>          &quot;title&quot; : &quot;He&#39;s here to raise hell and grab some candles&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;JtBrWn4B1NYkqWeI3pUb&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/r3y9o89tiob81.jpg">https://i.redd.it/r3y9o89tiob81.jpg</a>&quot;,<br>          &quot;title&quot; : &quot;best feeling in the world&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;6XxrWn4BGc7VZGO83n4g&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/o5qoysvw2pb81.jpg">https://i.redd.it/o5qoysvw2pb81.jpg</a>&quot;,<br>          &quot;title&quot; : &quot;You wanna know how I got these scars?&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;KNBrWn4B1NYkqWeI3pUk&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/fbcr779kznb81.png">https://i.redd.it/fbcr779kznb81.png</a>&quot;,<br>          &quot;title&quot; : &quot;If I disappear soon you&#39;ll know why&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;J9BrWn4B1NYkqWeI3pUj&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/wfa8jks39mb81.png">https://i.redd.it/wfa8jks39mb81.png</a>&quot;,<br>          &quot;title&quot; : &quot;Literally happens everyday&quot;<br>        }<br>      },<br>      {<br>        &quot;_index&quot; : &quot;memes&quot;,<br>        &quot;_type&quot; : &quot;_doc&quot;,<br>        &quot;_id&quot; : &quot;63xrWn4BGc7VZGO83n4l&quot;,<br>        &quot;_score&quot; : 1.0,<br>        &quot;_source&quot; : {<br>          &quot;url&quot; : &quot;<a href="https://i.redd.it/98dhrdna3nb81.jpg">https://i.redd.it/98dhrdna3nb81.jpg</a>&quot;,<br>          &quot;title&quot; : &quot;Wait, what?&quot;<br>        }<br>      }<br>    ]<br>  }<br>}</pre><p>Again, you can play with these queries more by referring to the official documentation.</p><p>YAY! Everything worked! This deployment will stay alive for the next 14 days, hence, you can play with it as much as you want!</p><h3>A quick recap</h3><p>We started by getting familiar with Elasticsearch and hosting the same locally. Then we learned how to interact with the local deployment via javascript and ingested some random meme data in it! Next, we decided to take this to the next level by hosting it on Google Cloud. Finally, we interacted with this Google Cloud deployment using our javascript code! As a bonus, we also took a quick look at the powers of kibana and how it complements the Elasticsearch deployment!</p><p>Thanks for sticking till the end! Hope you enjoyed it!</p><p>Psst, the complete code is available here — <a href="https://github.com/Saransh-cpp/elastic-node-reddit">https://github.com/Saransh-cpp/elastic-node-reddit</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9ec61ccba95" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/ingesting-reddit-memes-into-elasticsearch-using-node-js-locally-and-on-google-cloud-d9ec61ccba95">Ingesting Reddit memes into Elasticsearch using node.js: Locally and on Google Cloud</a> was originally published in <a href="https://blog.devgenius.io">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Covering unit-tests running in sub-processes/threads on GitHub Actions using coverage.py]]></title>
            <link>https://blog.devgenius.io/covering-unit-tests-running-in-sub-processes-threads-on-github-actions-using-coverage-py-825c3c4e08c1?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/825c3c4e08c1</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[coverage]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 14:31:49 GMT</pubDate>
            <atom:updated>2021-12-30T16:22:43.858Z</atom:updated>
            <content:encoded><![CDATA[<p>The “Code coverage” value of a codebase depicts how much of the production/development code is covered by the running unit tests. In the world of open-source, all the maintainers try their best to keep this percentage high, and this process is often automated through tools like GitHub Actions and Codecov. Hence, code coverage becomes a good metric (not always) to check if a particular codebase is well tested and reliable.</p><p>The unit tests often run in spawned sub-processes or threads. Sub-processes or multi-threading allow them to run in parallel. They also make it easier to stop the tests midway if they are taking too much time (probabilistic tests).</p><p>However, running unit tests in a sub-process creates a problem in the local repository as well as in the remote repository. As the documentation of coverage.py says — “Measuring coverage in those sub-processes can be tricky because you have to modify the code spawning the process to invoke coverage.py.”</p><p>In the following blog, we will first try to use coverage.py in the default mode to cover the code tested through unit tests running in a sub-process. After going through the results, we will build up a solution to cover the “un-covered” code in the local repository. As a final step, we will also configure GitHub Actions to perform this task in our remote repository.</p><h3>Creating a dummy project</h3><p>Let us create a new folder named Calculator and a new python file calc.py. I will be creating 4 simple functions in the same file that will then be tested -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d20e8cff90c03b4c21b8ff65d0c022a/href">https://medium.com/media/8d20e8cff90c03b4c21b8ff65d0c022a/href</a></iframe><p>Now let us create some unit tests for the functions written in calc.py in a new file, named test_calc.py —</p><ul><li>We will be using the unittest library for writing tests.</li><li>We need 4 separate test methods in a single class to test our code.</li><li>We will try to take care of the edge cases while testing.</li><li>While testing the divide function, we will need to test if the ValueError is being raised properly.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1370e37b231ffb1249d3ac5075511f9/href">https://medium.com/media/a1370e37b231ffb1249d3ac5075511f9/href</a></iframe><h3>Running the unit tests with coverage.py</h3><p>We can now run our tests using the command (-v is for a better-looking output) —</p><pre>python -m unittest -v</pre><p>The output —</p><pre>test_add (test_calc.TestCalc) ... ok     <br>test_divide (test_calc.TestCalc) ... ok  <br>test_multiply (test_calc.TestCalc) ... ok<br>test_subtract (test_calc.TestCalc) ... ok</pre><pre>----------------------------------------------------------------------<br>Ran 4 tests in 0.001s</pre><pre>OK</pre><p>The tests are working fine! Now we are ready to measure the coverage of our tests, but first, let us create a .coveragerc file to omit the code written in test_calc the file from the coverage report. The contents of the file would be —</p><pre>[run]<br>omit=*/test*</pre><p>The root directory should now have 3 files — calc.py , test_cal.py , and the .coveragerc file.</p><p>Executing the following command should run the tests and create a new .coverage file in your root folder (-v is for a better-looking output) —</p><pre>coverage run -m unittest -v</pre><p>The .coverage file can be used to check the coverage of our code using the command —</p><pre>coverage report</pre><p>The coverage —</p><pre>Name      Stmts   Miss  Cover<br>-----------------------------<br>calc.py      10      0   100%<br>-----------------------------<br>TOTAL        10      0   100%</pre><p>Hooray! The code coverage works, and is 100%!</p><h3>Running the unit tests in a sub-process with the default settings of coverage.py</h3><p>We really don’t need to run these tests in a sub-process as they are very simple, but for the sake of this tutorial, let us run them in a sub-process using multiprocessing. First, let us edit our functions to capture the return values in a queue instead of simply returning them —</p><ul><li>We cannot simply return a value through a multiprocessing.Process() call.</li><li>We can use shared variables to communicate between the processes.</li><li>Here we use a Queue to complete this task (well, now you know how to use a data structure in development).</li><li>Another such data structure that can be used to complete this task is Dictionary or multiprocessing.Manager().dict() (well, now you know how to use 2 data structures in development).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74fee0506e2014605fa8f931d6d47172/href">https://medium.com/media/74fee0506e2014605fa8f931d6d47172/href</a></iframe><p>To keep the example simple, I will be creating only a single test for each function —</p><ul><li>We create a new Queue and pass it as an argument of the function, which is then populated in the function, and the value is used in the tests.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aa2700703079be00e40506cbce15938/href">https://medium.com/media/7aa2700703079be00e40506cbce15938/href</a></iframe><p>That was a lot to take in, but now let&#39;s fire up our tests and see if the multiprocessing calls bring any changes in the coverage —</p><pre>coverage run -m unittest -v</pre><p>Output —</p><pre>test_add (test_calc.TestCalc) ... ok<br>test_divide (test_calc.TestCalc) ... ok<br>test_multiply (test_calc.TestCalc) ... ok<br>test_subtract (test_calc.TestCalc) ... ok</pre><pre>----------------------------------------------------------------------<br>Ran 4 tests in 0.986s</pre><pre>OK</pre><p>The tests still work! Now time for the coverage —</p><pre>coverage report</pre><p>Output —</p><pre>Name      Stmts   Miss  Cover<br>-----------------------------<br>calc.py      14      8    43%<br>-----------------------------<br>TOTAL        14      8    43%</pre><p>As expected, the coverage went down, even if the whole code is covered using the tests. The following command will help us visualize the coverage better -</p><pre>coverage html</pre><p>This command will create a folder named htmlcov in our root directory. HTML files in this directory can be opened up in our regular web browsers, and as expected, the lines executed in sub-processes are not covered using coverage.py —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*fikHd4jdZCnvEitrg5SdBQ.png" /><figcaption>Visual for code coverage</figcaption></figure><h3>Running the unit tests in a sub-process with coverage.py (the right way this time)</h3><p>This time, we will specifically tell coverage.py that we are running the tests in a sub-process. The steps described below are the general steps that a user should go through if one is using sub-processes or multi-threading. However, using coverage.py with multiprocessing comes with a shortcut, which we will be discussed ahead. For now, the commands needed to “activate” coverage in sub-processes can be specified in our .coveragerc file. The files take 2 commands — concurrency and parallel — under the [run] argument. According to the documentation —</p><ol><li>concurrency</li></ol><blockquote>concurrency (multi-string, default “thread”): the name concurrency libraries in use by the product code. If your program uses multiprocessing, gevent, greenlet, or eventlet, you must name that library in this option, or coverage.py will produce very wrong results.</blockquote><p>2. parallel</p><blockquote>parallel (boolean, default False): append the machine name, process id and random number to the data file name to simplify collecting data from many processes</blockquote><p>So now our .coveragerc will look something like this -</p><pre>[run]<br>concurrency=multiprocessing<br>parallel=True<br>omit=*/test*</pre><p>Additionally, we also need to add a sitecustomize.py file in our root directory with the following code —</p><pre>import coverage<br>coverage.process_startup()</pre><p>The last step would be to set up an environment variable —</p><pre>export COVERAGE_PROCESS_START=$PWD/.coveragerc</pre><p>BUT! As we are using multiprocessing, we don’t have to specify all of this, rather, we can pass concurrency directly in our terminal command. We will still keep the parallel command to simplify collecting data from many processes.</p><p>Now our .coveragerc should look like this —</p><pre>[run]<br>parallel=True<br>omit=*/test*</pre><p>We can use the following command to run our tests and specify to coverage.py that we are running the tests in a sub-process using multiprocessing —</p><pre>coverage run --concurrency=multiprocessing -m unittest -v</pre><p>Once this command is executed, coverage.py will create a separate coverage file for each sub-process in our root directory. To combine the files, we can execute -</p><pre>coverage combine</pre><p>And finally, for the coverage report, we can execute —</p><pre>coverage report</pre><p>Output —</p><pre>Name      Stmts   Miss  Cover<br>-----------------------------<br>calc.py      14      0   100%<br>-----------------------------<br>TOTAL        14      0   100%</pre><p>IT WORKS!!!! Our coverage is back to 100% even after running the tests in sub-processes.</p><h3>Running the unit tests in a sub-process with coverage.py on GitHub Actions</h3><figure><a href="https://www.seifbassem.com/blogs/posts/bicep-and-github-actions/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1tXo2MWkaZZF9m1L.jpg" /></a></figure><p>Finally, we can now push our code to GitHub and run the unit tests with coverage using GitHub Actions, coverage.py, and Codecov.</p><p>We start by creating a new repository on GitHub and pushing our existing code (create a new Codecov account if you don’t have one). Next, we navigate to the Actions tab present in our repository and create a new action for a Python Application (we could’ve also done this locally). The yaml code would look something like this -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab1aa126028efc799bde164fa3341151/href">https://medium.com/media/ab1aa126028efc799bde164fa3341151/href</a></iframe><p>The tests should automatically run once this file is committed, and the coverage should get available on Codecov.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKgbt1ErqMs2BAvO354JVw.png" /></figure><p>THE COVERAGE IS 100%!!</p><p>The full code can be found here — <a href="https://github.com/Saransh-cpp/Covering-unit-tests-running-in-subprocesses">https://github.com/Saransh-cpp/Covering-unit-tests-running-in-subprocesses</a></p><p>Additionally, you can also keep a track of the coverage using the README badges (which can be generated from Codecov) —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*2D3e4yKCS_Y3bau1oamP5A.png" /></figure><p>Ending this blog with a meme (I like memes) —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*Mg3IK9mwghZDah9a.png" /></figure><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=825c3c4e08c1" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/covering-unit-tests-running-in-sub-processes-threads-on-github-actions-using-coverage-py-825c3c4e08c1">Covering unit-tests running in sub-processes/threads on GitHub Actions using coverage.py</a> was originally published in <a href="https://blog.devgenius.io">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GSoC’21 — Week 7 and 8 — Setting up the reply functionality]]></title>
            <link>https://whiteviolin.medium.com/gsoc21-week-7-and-8-setting-up-the-reply-functionality-be5ac6897a9d?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/be5ac6897a9d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[numfocus]]></category>
            <category><![CDATA[gsoc]]></category>
            <category><![CDATA[gsoc2021]]></category>
            <category><![CDATA[pybamm]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Thu, 05 Aug 2021 17:14:35 GMT</pubDate>
            <atom:updated>2021-08-05T17:14:35.697Z</atom:updated>
            <content:encoded><![CDATA[<h3>GSoC’21 — Week 7 and 8 — Setting up the reply functionality</h3><p>Well, I know I am late, but the last 2 weeks were super hectic because of my University examinations. The examination board suddenly decided to give out grades on the basis of internal examinations and I was burdened with projects, presentations, assignments, and vivas. I did manage to set up a base for the replying functionality. Here are some of the major things I added to the bot -</p><h3>Refactored random part of the codebase</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*PW-xO0GzpErTwPT7DqUEag.jpeg" /></figure><p>The codebase was very messy in the parts where random configurations were being generated for the bot and <a href="https://github.com/pybamm-team/BattBot/pull/48">refactoring</a> it solved 2 issues together. One, the code quality improved by a lot, and two, now that the randomness was separated from the functions that created simulations, it became very easy to pass down configurations into these functions which in turn paved the way for integrating the Reply functionality into the existing codebase. The comparison_generator function was also converted to a class named ComparisonGenerator to split up the comparisons into 2 parts — &quot;model comparison&quot; (comparing 2 or more models with an experiment or with a constant discharge) and &quot;parameter comparison&quot; (comparing a single model but varying a specific parameter).</p><h3>Infinite reply issue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*s8qf5fQU-hhPoby9.jpg" /></figure><p>The recent Heroku deployment was working well but the bot was replying to the tweets every time the scheduled workflows ran. The replying feature worked on the following logic —</p><ol><li>Read all the tweets in which the bot is mentioned ID &gt; stored ID.</li><li>Store the tweet’s ID in a text file.</li><li>Iterate over these tweets and reply.</li><li>Repeat 1–3</li></ol><p>This does create a chicken-egg problem for the bot with the tweet IDs, hence the first tweet ID was manually stored in the text file. All of this was happening on Heroku , i.e. the text file on GitHub was not updated with every new mention.</p><p>Now coming to the bug, we had enabled automatic deployment on Heroku which meant that every time theCI passed on the main branch (which happened on every scheduled run), the bot was continuously deployed on Heroku where it was built again with the outdated text file (that had the tweet ID) and the bot started reading and replying to tweets from that old ID.</p><p>To tackle this, a new <a href="https://github.com/pybamm-team/BattBot/pull/51">function</a> was added to sync the tweet IDs stored in GitHuband in Heroku .</p><p>The CI is failing currently due to some issues, but again, it is very hard to test it on a PR as most of it won’t even run on a PR. It will be fixed probably by tomorrow and the first simulation request will be out by this weekend!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be5ac6897a9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GSoC’21 — Week 5 and 6 — BattBot is live!]]></title>
            <link>https://whiteviolin.medium.com/gsoc21-week-5-and-6-battbot-is-live-91831dd2e5a4?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/91831dd2e5a4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gsoc]]></category>
            <category><![CDATA[gsoc2021]]></category>
            <category><![CDATA[pybamm]]></category>
            <category><![CDATA[numfocus]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Mon, 19 Jul 2021 12:20:43 GMT</pubDate>
            <atom:updated>2021-07-19T12:20:43.605Z</atom:updated>
            <content:encoded><![CDATA[<h3>GSoC’21 — Week 5 and 6 — BattBot is live!</h3><p>With half of the coding period coming to an end, the bot is finally live! You can find it, tweeting Battery Simulations twice a day, here — <a href="https://twitter.com/battbot_">BattBot</a>. Once the <a href="https://github.com/pybamm-team/BattBot">repository</a> was moved to <a href="https://github.com/pybamm-team/BattBot">pybamm-team</a>’s account, and once the bot went live, a lot of things broke, and a lot of bugs surfaced up. Fixing these broken things was the main agenda for the last two weeks. Apart from the fixes, I also did make some substantial improvements in the bot in terms of reliability and user experience.</p><h3>Starting the week with degradation comparisons</h3><p>As I mentioned in my last and my last to last blog post, I wanted to implement the degradation comparisons in the 5th week which I did manage to, but the resultant plots were still coming out a bit weird. For instance, “Capacity [A.h]” was going up in some of the GIFs (with Marquis2019 parameter sets) instead of going down, and this was something that was not ideal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*nnsDT8caZkm6sEo4H9R5_A.png" /><figcaption>“Capacity [A.h]” going up with Marquis2019 parameter sets</figcaption></figure><p>Interestingly, while simulating one random experiment, the degradation mechanisms started behaving even more weirdly. It seemed like the model had degradation for a cycle and then didn’t have one for the subsequent cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_1qpeMLY7Tpy6-aAl75NQ.png" /><figcaption>Plotting Single Particle Model with Chen2020 parameters and reaction limited SEI, for the experiment: [(‘Discharge at 3 C until 3.3 V’, ‘Charge at 3 C until 3.8 V’, ‘Hold at 3.8 V until 63 mA’)]</figcaption></figure><p>We decided to pause with the degradation mechanisms branch to make sure that the bot doesn’t tweet out wrong or misguiding tweets. The <a href="https://github.com/pybamm-team/BattBot/tree/implement-degradation-comparisons">branch</a> is almost complete, and it will be merged whenever the plots start coming out without such errors (whenever the degradation mechanisms are fixed in PyBaMM).</p><h3>BattBot is born</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*V5aJ2JTg4I6WyO_rFfw8yg.jpeg" /><figcaption>BattBot!</figcaption></figure><p>A lot of new accounts were created in the last two weeks, a new Gmail account for the bot, a new Twitter account for all the tweets, a new Twitter Developer Account, and finally, a new Heroku account to deploy the replying functionality. The repository was also transferred to pybamm-team’s account where all the existing API keys were replaced with the bot’s API keys. A lot of issues started coming up after the bot started tweeting out, which were somehow related to moving the repository. These issues were fixed immediately but, the CI started failing and kept on failing for almost a week which I will be discussing in the next section.</p><h3>The failing CI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*JCqjAMPwnH5rJ1FuxA6vog.png" /></figure><p>The CI initially started failing because of a missing __init__.py file in the PyBaMM repository which was fixed in a couple of days. But after that, the CI unexpectedly started failing again and the two major reasons for this were my repository access rights and 2 misplaced lines in the YAML file. Both of them were fixed and a PERSONAL_GITHUB_TOKEN was added to push directly to the protected branch but the tests were still failing. The main reason for this was the inaccessibility of repository secrets to a forked repository, as now I was making PRs from a fork. We never wanted to pass the repository secrets to a fork as they could then be exploited by writing a malicious script and creating a PR. Hence, to tackle this, we decided to run only the tests that don’t need Twitter API keys on PRs from a fork, and to achieve this, the tests directory was bifurcated into two sub-directories which were with_keys and without_keys . After this, the YAML file was again updated to account for these changes and finally, the tests started passing, after failing for almost a week.</p><p>A lot of other small changes were also made. Listing some of them here -</p><ul><li><a href="https://github.com/pybamm-team/BattBot/pull/34">Randomising Tweet time to some extent and changing the frequency</a></li><li><a href="https://github.com/pybamm-team/BattBot/pull/38">Fixing </a><a href="https://github.com/pybamm-team/BattBot/pull/38">parameter_value_generator to include functional parameters too</a></li><li><a href="https://github.com/pybamm-team/BattBot/pull/44">Fixing a bug in the tweet text</a></li><li><a href="https://github.com/pybamm-team/BattBot/pull/40">Varying “Ambient temperature [K]” and “Current function [A]” while tweeting out constant discharge plots</a></li><li>And finally, <a href="https://github.com/pybamm-team/BattBot/pull/41">adding a base for the replying functionality</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91831dd2e5a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GSoC’21 — Week 3 and 4 — Getting the bot ready for official deployment]]></title>
            <link>https://whiteviolin.medium.com/gsoc21-week-3-and-4-getting-the-bot-ready-for-official-deployment-3c56c06844be?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c56c06844be</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gsoc]]></category>
            <category><![CDATA[gsoc2021]]></category>
            <category><![CDATA[pybamm]]></category>
            <category><![CDATA[numfocus]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 08:13:07 GMT</pubDate>
            <atom:updated>2021-07-05T11:16:19.681Z</atom:updated>
            <content:encoded><![CDATA[<h3>GSoC’21 — Week 3 and 4 — Getting the bot ready for official deployment</h3><p>The last two weeks were all about making small but important changes in the bot before it goes live. We also decided on the bot’s name through a fun <a href="https://twitter.com/pybamm_/status/1410937073494904837">Twitter poll</a>:). Here are some of the relatively big additions I made during this period —</p><h3>Degradation comparisons</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SSju2VvOCiRQMvRHGPdW1Q.png" /><figcaption>Summary variables for the experiment [(‘Discharge at 1 C until 3.3 V’, ‘Charge at 3 C until 3.8 V’, ‘Hold at 3.8 V until 43 mA’, ‘Rest for 7 minutes’)] * 20 with Doyle-Fuller-Newman model having reversible lithium plating with Chen2020_plating parameter sets varying “Initial plated lithium concentration [mol.m-3]”.</figcaption></figure><p>The first half of the third week was all about modifying the already existing code to make way for the degradation comparisons. The code was modified successfully but while checking the sensitivities for the shortlisted parameters, the summary variable plots were coming out a bit weird. This was later discussed in a meeting and was eventually fixed by my mentors, but, I couldn’t continue with that branch because I started working on other parts of the codebase (which I will be talking about below). I will be continuing with the branch this week, adding the sensitive parameters and implementing the degradation comparisons.</p><h3>Playing with the time-out and removing some plots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*F2UfQHnmjbykTgy8FRgs-A.gif" /><figcaption>Check out this tweet with the configuration <a href="https://twitter.com/saranshchopra7/status/1411889214564806660">here</a>. (The quality was reduced while uploading to Medium)</figcaption></figure><p>After the degradation comparisons, I tried to implement a dynamic time-out for the simulations (I mentioned this in my last blog as well) but there was no progress even after trying out various different options. At last, we decided to implement a time-out based on what simulation is going on but that was discarded when it was decided to remove some plots. Now the plots that the bot will be tweeting will be of the comparison type and they have been given a time limit of 1200 seconds.</p><h3>Adding sensitive parameters and Tweet status</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*wNtFgWnlrcZyDygeStZyjQ.png" /><figcaption>A recent tweet by the bot</figcaption></figure><p>At the end of the third week, we decided to give the bot a good and dynamic description, to go with the plots that were being tweeted, and also added all the sensitive parameters which will be varied in the comparison plots. After this, the bot was almost ready for the first deployment and the new plots+decription tweets started getting better attention than the only plot tweets.</p><h3>Storing the random configurations and letting anyone play with it</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*dEzJkVMAkJHXzOh6G2uEKQ.png" /></figure><p>All the random configurations that we were tweeting, were not stored anywhere (except the Tweet status) and the configurations were something that we wanted to store somewhere for the following reasons —</p><ol><li>Creating a database of such configurations for future studies</li><li>Letting the users see what configuration was tweeted</li><li>Creating a notebook for the user to play with the tweeted configuration</li></ol><p>This was worked upon in week 4, where I added a config.txt file to store the latest Tweet configuration and a data.txt file to store all the data with date and time. The data present in config.txt was then pulled in the Notebook which after going through a lot of if-else conditions showed the user the latest Tweeted plot. This also meant changing the workflows to push the changes which were made in these txt files after every Tweet, which was a problem as it would have resulted in an infinite loop on the main branch (A Tweet happens — txt files are updated — these changes are committed and pushed by the workflows — this push triggers the CI again — everything repeats). To tackle this, I decided not to run CI on the commits made by the workflow by editing the workflow itself and after a lot of YAML errors, it worked! Once the branch is merged, you will be able to run the latest tweeted configuration on your local environment as well as on Google Colab.</p><p>Other than these changes, some issues and bugs like the “<a href="https://github.com/Saransh-cpp/PyBaMM-Twitter-Bot/pull/12">Twitter API issue</a>” and the “<a href="https://github.com/Saransh-cpp/PyBaMM-Twitter-Bot/pull/21">Deleting the leftover plots</a>” were also worked upon. Documentation was also added to make this repository more suited for contributions and the repository will be moved to the official pybamm-team account in the next couple of days!</p><p>For the fifth week, I plan on adding the degradation comparisons and completing the “Tweeting” capability of the bot so that I can move to the “Replying” feature for the second half of the coding period.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c56c06844be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GSoC’21 — Week 1 and 2 — Twitter API, GitHub Actions, and Sensitive Parameters]]></title>
            <link>https://whiteviolin.medium.com/gsoc21-week-1-and-2-twitter-api-github-actions-and-sensitive-parameters-9d7e79de183a?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d7e79de183a</guid>
            <category><![CDATA[numfocus]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gsoc2021]]></category>
            <category><![CDATA[pybamm]]></category>
            <category><![CDATA[gsoc]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Tue, 22 Jun 2021 15:57:25 GMT</pubDate>
            <atom:updated>2021-06-22T18:51:36.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>GSoC’21 — Week 1 and 2 — Twitter API, GitHub Actions, and Sensitive Parameters</h3><p>The First 2 weeks of Google Summer of Code 2021 are now over and spoiler alert — these 2 weeks were more about development and lesser about battery mathematical modeling compared to the community bonding time (if you missed that blog, read it <a href="https://whiteviolin.medium.com/my-gsoc21-experience-community-bonding-f31ea7bb624c">here</a>). Here is every major thing, I did in these two weeks while working on my project (“<a href="https://summerofcode.withgoogle.com/projects/#5045812318437376">Automated Twitter Bot to run PyBaMM Simulations</a>”) —</p><h3>GIF Tweets and the Twitter API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_AwTGIVYneAzpzwPUGDxw.gif" /><figcaption>Marquis2019 parameter set, solved using CasADi solver with ‘safe’ mode with the experiment - [(‘Discharge at 3 C until 3.3 V’, ‘Rest for 1 minute’, ‘Charge at 3 C until 4.1 V’, ‘Hold at 4.1 V until 7 mA’, ‘Rest for 10 minutes’)]</figcaption></figure><p>At the end of the community bonding time, I and my mentors (their suggestion) decided to tweet GIFs of the plots rather than a single picture at some random time and though it wasn’t that tough to generate them, it was tough to keep them in a certain boundary condition so that they can be tweeted using the Twitter API. While doing this, I learned a lot about image processing, resizing, and manipulation using Pillow and Imageio. I was able to tweet small GIFs or a big GIF but compressed to a smaller size using Tweepy but we eventually thought of switching to the traditional way, where we can tweet bigger files by directly interacting with the API (without using a wrapper library like Tweepy) and implemented that.</p><h3>The infinite crash issue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/0*VQeOrjv9Ym9lAiCG.jpg" /><figcaption>Me and the CI/CD pipeline I built using GitHub Actions for a couple of days</figcaption></figure><p>While working on random configurations, it didn’t take long for everyone to realize that a very small amount of these randomly put-together configurations crashes the solver in a way that the program starts printing warnings/statements infinitely, and never stops. This causes the tests to fail (as the integration tests do produce some random simulations) on GitHub Actions because of the 360-minute timeout. Two, it also causes the Tweeting functionality to fail sometimes in a similar fashion. A few measures using threading and multiprocessing have been implemented but I am still trying to implement an ever smarter time-out functionality. With this, coverage.py was also extended to account for the tests being run using a subprocess or a thread (initially, it did work on my machine but it took me another day to figure out why it was failing on GitHub Actions).</p><h3>Comparison plots and the Sensitive Parameters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GFqyonhQUIlTEjE7Nq24cw.png" /></figure><p>These are the plots I find the most interesting and they were implemented in these 2 weeks (working on the degradation comparison plots), with these a lot of sensitive parameters and degradation parameters were also discussed which will most probably be added to the bot in the upcoming weeks. And finally, some bugs and some small issues were also resolved, you can find the developing repository <a href="https://github.com/Saransh-cpp/PyBaMM-Twitter-Bot">here</a>.</p><p>In the next 2 weeks, I will be implementing the degradation comparisons, working more on the sensitive parameters with my mentors, maybe shifting the bot to an official Twitter account, and much more! Follow <a href="https://twitter.com/saranshchopra7">me</a> and <a href="https://twitter.com/pybamm_">PyBaMM</a> on Twitter to keep an eye on the bot’s official announcements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d7e79de183a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My GSoC’21 experience — Community Bonding]]></title>
            <link>https://whiteviolin.medium.com/my-gsoc21-experience-community-bonding-f31ea7bb624c?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/f31ea7bb624c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gsoc2021]]></category>
            <category><![CDATA[gsoc]]></category>
            <category><![CDATA[numfocus]]></category>
            <category><![CDATA[pybamm]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 11:16:32 GMT</pubDate>
            <atom:updated>2021-08-18T20:21:56.546Z</atom:updated>
            <content:encoded><![CDATA[<h3>My GSoC’21 experience — Community Bonding</h3><p>Today marks an end to the community bonding period of Google Summer of Code 2021, and hence I decided to document my journey in the form of a blog. I’ll try to make this blog fun, short and to the point, buckle up!</p><h3>Back story!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*-lu4y38aol_3JkPFkG2nyA.gif" /></figure><p>I entered the open-source world in December 2020 as a complete beginner, I knew some high school C++, python in bits and pieces, and had some experience with hybrid-app development, and honestly, at that point, I just wanted to contribute to some open-source software.</p><p>While contributing to some Flutter apps, I stumbled upon a project that was participating in <a href="https://mexili.org/winter_of_code/#/winter_of_code">Mexili Winter of Code</a>, long story short - I participated and learned a lot about open-source, and this in the end, motivated me to look for some bigger projects in which I can contribute.</p><h3>PyBaMM (Python Battery Mathematical Modelling)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1lykkorvszpYz-UOmKtAQ.gif" /><figcaption>“<em>PyBaMM (Python Battery Mathematical Modelling) solves physics-based electrochemical DAE models by using state-of-the-art automatic differentiation and numerical solvers.</em>”</figcaption></figure><p>I discovered <a href="https://www.pybamm.org/">PyBaMM</a> through <a href="https://numfocus.org/">NumFOCUS</a>’ sub-organizations list and though the huge codebase was intimidating at first, some of the terms looked familiar as I had electromagnetism and electrochemistry in my high school from which I graduated a few months back. I decided to take up a small issue with no prior knowledge of the codebase and the whole PyBaMM community turned out to be very supportive and welcoming. Soon the example notebooks started making some sense to me and I started communicating regularly with the community by solving some more small issues.</p><p>With some progress in understanding PyBaMM’s codebase and the things it is capable of, I decided to work on a project idea that was listed in the discussions tab for GSoC. This again resulted in me learning a lot of new things with the help provided by the organization and the mentors.</p><p>Fast forward to the result day, all the hard work from my side and the organization’s side paid off, and I was finally selected for a project named “<a href="https://summerofcode.withgoogle.com/projects/#5045812318437376">Automated Twitter bot to run PyBaMM simulations</a>”!</p><h3>Community Bonding time</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*9GJWUvET3it_2XPX9CAUXw.gif" /></figure><p>The community bonding period started with some discussions on which simulations should be added to the bot initially, and I realized that the discussions would go in vain if I don’t actually try out the features that are being discussed, in the code. This took some extra time but in the end, I enjoyed the whole process and did somehow manage to construct a basic structure for the “Tweeting” functionality of the bot.</p><p>I was also invited to be a part of the GitHub organization (this was really exciting) and, I was also invited to the weekly PyBaMM meeting and weekly project standup/discussion meeting. I was actually scared to attend these meetings initially but it all went away after attending the first meeting, where I introduced myself and learned about how a meeting in PyBaMM usually proceeds.</p><p>Last but not the least, I will list out some major things that were discussed or some major things that I worked on during the community bonding period -</p><ol><li>Discussed the simulations that should be added to the bot.</li><li>Refactored and updated the already written code.</li><li>Added tests and documentation for the already written code to make the project ready for test-driven development.</li><li>Integrated codecov and wrote workflows for continuous integration and continuous deployment.</li><li>Decided that using GitHub actions for the “Tweeting” functionality and Heroku for the “Replying” functionality would be a better deployment structure.</li><li>Added degradation to the models and introduced summary variables in the bot.</li><li>Replaced the plot PNGs with GIFs for better clarity and understanding.</li><li>Replaced the Twitter API wrapper tweepy with built-in python libraries.</li><li>Added a way to resize GIFs and to upload them in chunks before finally tweeting them out.</li><li>Discussed some possible comparisons with and without degradation mechanisms.</li><li>Learned some battery related terminologies and concepts :D</li></ol><p>The repository can be found <a href="https://github.com/Saransh-cpp/PyBaMM-Twitter-Bot">here</a>.</p><p>Overall, the experience has been great:), it actually feels good to contribute and collaborate on a project that is being used by people worldwide, and also where the mentors and every organization member is so welcoming and is always ready to help!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f31ea7bb624c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automatically changing pages using the PageView widget]]></title>
            <link>https://whiteviolin.medium.com/automatically-changing-pages-using-the-pageview-widget-4557b3b7503?source=rss-273d2033adac------2</link>
            <guid isPermaLink="false">https://medium.com/p/4557b3b7503</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Saransh Chopra]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 10:43:53 GMT</pubDate>
            <atom:updated>2021-06-06T11:39:53.361Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why PageView?</h3><p>PageView widget can be used in a lot of situations, one such situation is when the user starts the app for the first time. If you want to provide your user with some information, instructions, or some tips and then redirect him/her to the actual sign-in/sign-up screen then this is for you!</p><h4>Coding our app!</h4><ol><li><strong>Create a new flutter project</strong></li></ol><p>Use Android Studio or your terminal to create a new flutter project and run your project in any IDE like Android Studio or Visual Studio Code and delete all the default code written in the project.</p><p><strong>2. Setting up our files</strong></p><p>Here, I create a package named pages in which I create 3 stateless widgets named Page1.dart, Page2.dart, and Page3.dart for the page view, then I created a package named screens which contains a stateful widget for the PageView screen called PageView.dart and a stateless widget for the Sign In screen which is named SignIn.dart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*CoIyNhLHQSaQ4r-YgG7TWg.png" /><figcaption>Here is how my files look like</figcaption></figure><p><strong>3. Coding our screens</strong></p><ol><li>Coding Page1, Page2 and Page3</li></ol><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class Page1 extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        backgroundColor: Colors.<em>white</em>,<br>        elevation: 0,<br>      ),<br>      body: Center(<br>        child: Text(<br>          &#39;Page 1&#39;,<br>          style: TextStyle(<br>              color: Colors.<em>black</em>,<br>              fontSize: 20<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Similarly coding the rest 2 screens with classes named as Page2.dart and Page3.dart</p><p>2. Coding the PageView screen</p><pre>import &#39;package:medium_article1/pages/Page1.dart&#39;;<br>import &#39;package:medium_article1/pages/Page2.dart&#39;;<br>import &#39;package:medium_article1/pages/Page3.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br><br><br>class PageViewScreen extends StatefulWidget {<br>  @override<br>  _PageViewScreenState createState() =&gt; _PageViewScreenState();<br>}<br><br>class _PageViewScreenState extends State&lt;PageViewScreen&gt; {<br>  <br>  PageController pageController = PageController();<br>  int currentIndex = 0;<br>  var currentTabs = [<br>    Page1(),<br>    Page2(),<br>    Page3()<br>  ];<br>  <br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      body: PageView(<br>        children: currentTabs,<br>        controller: pageController,<br>        onPageChanged: (int index) {<br>          setState(() {<br>            currentIndex = index;<br>          });<br>        },<br>      ),<br>    );<br>  }<br>}</pre><p>3. Coding the SignIn screen</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class HomePage extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        elevation: 0,<br>        backgroundColor: Colors.<em>white</em>,<br>      ),<br>      body: Center(<br>        child: Text(<br>          &#39;Sign In Screen&#39;,<br>          style: TextStyle(<br>            color: Colors.<em>black</em>,<br>            fontSize: 25<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Note- Add PageViewScreen() in the home property of MaterialApp() in main.dart file.</p><p><strong>3. Adding Timer in PageViewScreen</strong></p><p>Here we add a periodic timer to change the pages after every 5 screens. Additionally, you can also use NeverScrollablePhysics() in the physics property of PageView to stop users from scrolling between pages.</p><p>First, we need to import dart:async to use the Timer.</p><pre>import &#39;dart:async&#39;;</pre><p>The Timer is used to create a periodic timer which after every 3 seconds increases the currentIndex if it is less than 2 or makes it 2 if it is 2, additionally you can also make it 0 in the else statement once it becomes 2 to restart the whole carousel-like effect again. Then I use pageController to access animateToPage and pass in the current index, duration of animation, and an animation.</p><p>Further, I disposed of the pageController to prevent any memory leaks.</p><pre>@override<br>void initState() {<br>  super.initState();<br>  Timer.periodic(Duration(seconds: 3), (Timer timer) {<br>    if (currentIndex &lt; 2) {<br>      currentIndex++;<br>      pageController.animateToPage(<br>          currentIndex,<br>          duration: Duration(milliseconds: 350),<br>    curve: Curves.<em>easeIn</em>,<br>      );<br>    } else {<br>      currentIndex = 2;<br>    }<br>  });<br>}</pre><pre>@override<br>void dispose() {<br>  pageController.dispose();<br>  super.dispose();<br>}</pre><p>Now the whole PageViewScreen code looks like this -</p><pre>import &#39;dart:async&#39;;<br>import &#39;package:medium_article1/pages/Page1.dart&#39;;<br>import &#39;package:medium_article1/pages/Page2.dart&#39;;<br>import &#39;package:medium_article1/pages/Page3.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br><br><br>class PageViewScreen extends StatefulWidget {<br>  @override<br>  _PageViewScreenState createState() =&gt; _PageViewScreenState();<br>}<br><br>class _PageViewScreenState extends State&lt;PageViewScreen&gt; {<br><br>  PageController pageController = PageController();<br>  int currentIndex = 0;<br>  var currentTabs = [<br>    Page1(),<br>    Page2(),<br>    Page3()<br>  ];<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    Timer.periodic(Duration(seconds: 3), (Timer timer) {<br>      if (currentIndex &lt; 2) {<br>        currentIndex++;<br>        pageController.animateToPage(<br>            currentIndex,<br>            duration: Duration(milliseconds: 350),<br>      curve: Curves.<em>easeIn</em>,<br>        );<br>      } else {<br>        currentIndex = 2;<br>      }<br>    });<br>  }<br><br>  @override<br>  void dispose() {<br>    pageController.dispose();<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      body: PageView(<br>        children: currentTabs,<br>        controller: pageController,<br>        onPageChanged: (int index) {<br>          setState(() {<br>            currentIndex = index;<br>          });<br>        },<br>      ),<br>    );<br>  }<br>}</pre><p><strong>4. Adding redirecting button on Page3</strong></p><p>Now we need a button on Page3 which the user clicks and he is then redirected to the SignIn screen. We can also do this automatically without any button as explained by me in my previous article. You can find the article <a href="https://whiteviolin.medium.com/creating-splash-screens-in-flutter-apps-8a284d86aa1b">here</a>.</p><p>I use pushReplacement as we don’t want the user to come back to this carousel of screens. Now the code for Page3 looks like this.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:medium_article1/screens/SignIn.dart&#39;;<br><br>class Page3 extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        backgroundColor: Colors.<em>white</em>,<br>        elevation: 0,<br>      ),<br>      body: Column(<br>        mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>        children: [<br>          Center(<br>            child: Text(<br>              &#39;Page 3&#39;,<br>              style: TextStyle(<br>                  color: Colors.<em>black</em>,<br>                  fontSize: 20<br>              ),<br>            ),<br>          ),<br>          MaterialButton(<br>            onPressed: () {<br>              Navigator.<em>pushReplacement</em>(<br>                  context, MaterialPageRoute(builder: (c) =&gt; SignIn()));<br>            },<br>            child: Text(<br>                &#39;SignIn Page&#39;<br>            ),<br>          )<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><h4>Final Output</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*L26_ukJFb7zNuU7rAs_SKA.gif" /><figcaption>Output on my physical device</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4557b3b7503" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>