# Code Initiative Workshop April 2022 - Day 3
## Instructors and Helpers:
- *Heather Andrews*, Aerospace Faculty Data Steward
- *Bianca Giovanardi*, Aerospace Structure and Computational Mechanics Assistant Professor
- *Javier Gutierrez*, Aerospace Structure and Computational Mechanics PhD candidate
- *Sai Kubair Kota*, Aerospace Structure and Computational Mechanics PhD candidate
- *Giorgio Tosti*, Aerospace Structure and Computational Mechanics PhD candidate
## Program
| Time | Activity |
| ------------- | ------------------------------------------------ |
| 09.30 - 09.40 | Introduction to the session (Heather and Bianca) |
| 09.40 - 10.05 | Git recap & Remote repositories |
| 10.05 - 10.20 | Introduction to Exercise |
| 10.20 - 10.25 | autoDocstring |
| 10.25 - 10.50 | Exercise Part I |
| 10.50 - 11.05 | Review Part I |
| 11.05 - 11.25 | Exercise Part II |
| 11.25 - 11.40 | Review Part II |
| 11.40 - 12.10 | Exercise Part III |
| 12.10 - 12.25 | Review Part III |
| 12.25 - 12.30 | Feedback (Mentimeter) |
<img src='https://memecreator.org/static/images/memes/5108001.jpg' width='380' height='250'>
<img src='https://miro.medium.com/max/800/0*dWOQEtbQ3ESrZ5JL.' width='380' height='380'>
## Breaking the Ice
Add +1 next to your response:
### <font color='blue'> Which Operating System are you using today?</font>
* Windows 8
* Linux 6
* MacOS 4
### <font color='blue'> From which faculty are you?</font>
* ABE +1
* AE 7
* AS 1
* CEG 3
* EEMCS 3
* IDE
* TPM 1
* 3mE 1
* Other +1
### <font color='blue'> How are you enjoying the Dutch spring?</font>
* +2+1+1+1
* Spring?+1+1g+1
*
## Exercise Instructions
The objective of this activity is to explore collaborative software development in a safe environment and implement the continuous integration workflow.
In this activity you and your teammate will collaboratively develop, test and troubleshoot Python code in the GitLab repository at https://gitlab.tudelft.nl/code-initiative-april-2022/team_N (please replace the N in the link with your team number).
Before starting, clone the repository on your computer with the command:```git clone https://gitlab.tudelft.nl/code-initiative-april-2022/team_N.git```
You and your teammate will write a function that computes the eigenvalues of a $2 \times 2$ matrix $\mathbf{A}$ with the well-known analytic formula:
\begin{aligned}
\lambda_1 &= \frac{1}{2} \left( A_{00} + A_{11} \right)
+ \sqrt{A_{01}^2 + \frac{1}{2} \left(A_{00} - A_{11}\right)^2} \\
\lambda_2 &= \frac{1}{2} \left( A_{00} + A_{11} \right)
- \sqrt{A_{01}^2 + \frac{1}{2} \left(A_{00} - A_{11}\right)^2}
\end{aligned}
You will then test the implementation by verifying whether your code calculates the exact value of the eigenvalues of two given matrices. By running your tests, the automated testing pipeline will detect a failure in the code!
You will then open an issue describing the failure and discussing potential solutions. Finally, you will fix the issue and restore a healthy testing pipeline.
The student leading each part of this activity will share the screen in the
breakout room.
You are all set to start, follow the detailed instructions below. Happy coding!
### <font color='blue'>Part I: Development and Testing (Lead: Student A, Time: 25 mins) </font>
* **Student A.** Edit file ```lib/algebra/eigenvalues.py```, implementing the calculation of the eigenvalues (use the formulae above) in function ```eigenvalues```. Commit the change, run the tests and push it to the remote repository.
* **Student A.** In file ```tests/algebra/test_eigenvalues.py```, edit function ```test_symmetric```, which checks that the eigenvalues of matrix $A = [[1, 2], [2, 1]]$ are $\lambda_1 = 3$
and $\lambda_2 = -1$. Commit the change, run the tests, push it to the remote repository.
* **Team.** Check the outcome of the testing pipeline (the pipeline should succeed at this point).
* **Student B.** Pull the remote repository to your local repository.
* While the Gitlab runner checks that the tests pass (the job might be queued for a couple of minutes),
* **Student A.** Rename a variable in the expression for $\lambda_1$ and $\lambda_2$. Commit and push. Add comments to make the code readable.
* **Student B.** Change the function to compute the square root from ```np.sqrt``` to ```np.lib.scimath.sqrt```, which is general to complex numbers. Commit and (try to) push.
* **Team.** Discuss the conflict.
* **Student B.** Merge the conflict (```git merge origin/main```), solve the conflict, run the tests, push.
### <font color='blue'>Part II: More Testing and Issue Reporting (Lead: Student B, Time: 25 mins) </font>
* **Student A.** Pull the work of Student B from the remote repository.
* **Student B.** In file ```tests/algebra/test_eigenvalues.py```, add a function ```test_nonsymmetric```, which checks that the eigenvalues of matrix $A = [[1, 2], [0, 1]]$ are $\lambda_1 = 1$ and $\lambda_2 = 1$. Commit the change and push it to the remote repository.
* **Student B.** Check the outcome of the testing pipeline (the pipeline should fail at this point).
* **Student B.** Open an issue (use the ***Issue*** tab in the left-hand bar in GitLab) describing the observed failure, the correct expected behavior and possible reasons for the failure. Assign the issue to Student A.
### <font color='blue'>Part III: Debugging and Pipeline Fixing (Lead: Student A, Time: 25 mins) </font>
* **Team.** Discuss the failure and potential fixes.
* **Student A.** Pull the work of Student B from the remote repository. Checkout a new branch (```git checkout -b issue_1```) and push it to the remote (```git push origin issue_1```). Implement the fix in file ```lib/algebra/eigenvalues.py```.
* **Student A.** Commit the change and push it to the remote repository. Don't forget to mention the issue (```Fix issue #1```) and to acknowledge the reporter (```Thanks @username_student_B for reporting!```) in the commit message!
* **Team.** Check the outcome of the testing pipeline (the pipeline should succeed at this point).
* **Student A.** Create a merge request on GitLab and assign it to Student B.
* **Student B.** Approve the merge request on GitLab and allow the merge.
* **Team.** Check that the issue has been automatically closed by the merge.
## Check Material from previous sessions
[Hackmd Day 1](https://hackmd.io/iyPN89T1SuyTw1FNPuBaqg)
[Hackmd Day 2](https://hackmd.io/ff9guBJeRou0rCx9sOzhBA)
## Tell us how you are doing?
<font color='blue'>**Add a 'X' when you and your team partner are finished with the exercise**</font>
| Team | Helper | Part I | Part II | Part III |
| ---- | ------ | ------ | ------- | -------- |
| 1 | Heather | X | X | |
| 2 | Heather | X | X | X |
| 3 | Heather | x | X | X |
| 4 | Javier | X | X | |
| 5 | Javier | X | X | X |
| 6 | Bianca | X | X | X |
| 7 | Bianca | X | | |
| 8 | Bianca | X | X | X |
| 9 | Kubair | x | x | x |
| 10 | Kubair | X | X | X |
| 11 | Kubair | X | X | |
**Communicate any issues here!**
* pipelines are stuck! (team 11). other teams with the same issue?
They should be fine now, thanks for reporting!
* do we continue with part II after finishing part I? or do we meet in the main room first?
Yes please! Everyone is working at a differenct pace and we will discuss in the end.
* we are having an issue to run the tests under Windows (t7) [SOLVED]
* The pipelines are running. But they are going to take some time. In the mean time you can discuss the next steps!!!
* *Could someone let me in again (knock knock)
* Does student A need to pull the changes from student B after part II before starting part III?
## Questions
<font color='red'>**Add your questions here!**</font>
1.Will you send us course certificates, so that we can ask our faculty graduate school for GS credits?
Hi! Please first ask your faculty Graduate School to see if they would be willing to provide you credits for this course. Then you can email us and we will send you the attendance form.
## Mentimeter
Please go to www.menti.com and use the code **7350 4398**
Great success, thanks for the course!