Coding Period GSoC'23 | Week 7+8
Tags: gsoc, javascript, webdev, circuitversesimulator
Published: 2023-07-25 13:55:36

Welcome back to another progress update on my GSoC' 2023 journey.

### **Journey So Far**
My GSoC journey so far has been absolutely amazing.
I am delighted to share that I have successfully passed the mid-term evaluation, and I couldn't be happier with the progress made so far! My journey has been a fulfilling one, with ample support from my mentor, making this experience smooth and enjoyable. :dancer::partying_face:

![Pikachu-Happy_dance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zkjhz9onuehb20oxz0d7.gif)

### **Work Done (11th July - 25th July):**

After the mid-term evaluation, I began working on the state machine task, following the valuable suggestions provided by my mentors. The primary objective was to implement a modal that opens whenever an uncaught exception error occurs during the simulation. Inside the modal, I endeavored to create a simulation area similar to the one found in the simulator canvas. This task has progressed significantly, but I encountered some challenges during testing, leading to several failed tests. To ensure a robust solution, I have decided to put this task on hold temporarily.

Moving forward, I aim to focus on loading the error circuit on the modal, implementing delete and undo functionality to remove the erroneous component within the modal, and closing the modal once the circuit is back to its normal state. I plan to discuss this with my mentors and aim to complete it within the upcoming two weeks.

#### **Identifying and Modifying Currently Selected Components:**

After that, I started working on the following task:
There should be a way to identify the currently selected component on the canvas and modify that component's object in the globalScope.

For achieving this, I created two functions:

- `getCurrentlySelectedComponent()`: This function is responsible for returning the currently selected component on the canvas.

- `modifyCurrentlySelectedComponent(property, value)`: This function takes two parameters. The first parameter is the property of the currently selected component that needs to be modified, and the second parameter is the new value that will replace the existing value of the specified property. This function effectively modifies the specified property of the currently selected component within the globalScope.

Currently, identifying a specific component in a circuit and modifying its property in globalScope is challenging. However, with the implementation of these functions, we can now easily find and modify the currently selected component.
Let me provide you with an example to illustrate how this functionality can be utilized. Consider a circuit, and now select any component whose properties you want to modify. Suppose we want to modify the bitWidth property of a particular node from 1 to 10. We can do this by running the following command in the console.

```
globalScope.getCurrentlySelectedComponent();
globalScope.modifyCurrentlySelectedComponent('bitWidth', 10);
```

#### **Find and fix Data Integrity Issues:**

Next, I took on the challenge of resolving data integrity issues that were causing data corruption for many users. These issues were crucial to address for a smoother user experience. 

Under this task, I worked on [Issue #103] (https://github.com/CircuitVerse/CircuitVerse/issues/103)

In this, The previous implementation of simulation queue uses a linear implementation for managing the priority queue, which involves sorting the elements in an array to maintain the priority order. As a result, the `add` method uses linear time complexity (O(n)) to find the correct position for adding an element based on its timestamp.

To make the performance better, I have worked on decreasing it's complexity to O(log n), I am making use of a binary heap data structure to manage the priority queue. A binary heap is a specialized tree-based data structure that maintains the heap property, where the parent node has a higher priority (smaller timestamp) than its child nodes. In this implementation, the `add` method uses heapify-up to find the correct position for adding an element, and the `remove` method uses heapify-down to maintain the heap property after removing an element. These heapify operations have logarithmic time complexity (O(log n)), which makes the binary heap implementation much more efficient for managing a priority queue compared to the linear implementation.
It will be leading to better performance for larger event queues due to the more efficient O(log n) time complexity for insertion and removal operations.

### **Pull Requests:**

 - [Change the implementation of the priority queue to use a heap data structure](https://github.com/CircuitVerse/CircuitVerse/pull/3916)
 - [Added helpful functions for debugging of circuit](https://github.com/CircuitVerse/CircuitVerse/pull/3870)

### **What's Next?**

As I look ahead to the next two weeks:

- I will continue to focus on addressing data integrity issues and aim to resolve the remaining issues.

- Completing Pull Request [#3781](https://github.com/CircuitVerse/CircuitVerse/pull/3781) is another priority, and I will ensure the proposed changes are thoroughly reviewed and integrated.

- Next, I will start working on the task of identifying areas in the codebase where we can implement more defensive coding practices, reducing dependencies on data always being in the correct format.

The journey through Weeks 7 and 8 of GSoC'2023 has been both challenging and rewarding. 

Stay tuned for more updates and progress in the coming weeks!