This assignment will explore a toy use case of git as a version control tool for scientific computing. Each part will have at most one short-answer question, which should be written in a file called responses.txt in the root directory of the repository. You may commit this file as you go, or you may opt to commit all of your responses at the end -- grading will not be affected by this choice. There is no minimum on what you are expected to write.
A fictional group of students are writing a package for computing the quadrature rules for Gaussian quadrature on the interval mpmath package, but you do not have the heart to tell them that.
Without it, these students require arbitrary precision arithmetic to compute roots of Legendre polynomials, the foundation of which can be built from the native decimal module.
They were fortunate enough to have the foresight of using a git repository to organize and combine their code contributions. However, due to inexperience, they are struggling to recombine all of their work back on the main branch for the upcoming milestone. Your task is to walk them through it.
Outside any merge conflicts (or personal interest, if you so wish), you do not need to know any contents or formats of the files.
Examine the rootfind branch (git checkout rootfind). Carla explains to you that when she finished implementing a different root finding algorithm, she accidentally committed her notes polynomial_zeros.ipynb to the repository. Once she figures out how to undo that, she wants to merge the branch into main. Frank complains that he also uses python notebooks and has to manually choose which files to commit, instead of using git add .. The group agrees to exclude .ipynb files from the repository.
Make a commit on rootfind that
- adds all
.ipynbfiles to.gitignore(including subdirectories) - removes Carla's
polynomial_zeros.ipynb
Then, combine this commit with the previous one labelled "now using newton's method for rootfind".
You may name this new commit however you like.
Tip
The commands git merge --squash and git checkout [branch/HEAD]~[N] may be helpful to you.
For the latter, [N] is the number of commits prior to the given branch (or HEAD if that was specified). Alternatively, you can use git checkout [HASH].
Finally, merge (or rebase) from that commit into main. You may want to create a new branch at the combined commit or move rootfind to it beforehand. Your goal for this part is to have the repository resemble the following:
┄ ─[A]┬───[C]──┰───[Z]─────┲[G] < main
└─[B]┬───┺[E]───[F]──┚
└[D]─ ┄ (gaussquad)
| Commit | Description ("message" or details) |
|---|---|
| A | "Started report" |
| B | "added zero finding, moved precision to conftest" |
| C | "layout / delegation of report" |
| D | "gauss quadrature + tests to 5-point" |
| E | "Merge branch 'main' into rootfind" |
| F | (combined commits) change legroot.py and report.md for Newton's method; add notebooks to .gitignore |
| G | merge from [F] into main (If you rebased, the line from [F] to [G] will be absent.) |
| Z | commit(s) involving these instructions (pretend they're not there) |
You may keep the two initial commits (before the squash) after [E] in rootfind, or you may delete them.
Both squashed commits involve the
polynomial_zeros.ipynbfile, however,[F]does not, which can be verified withgit show. Explain why this is the case inresponses.txt.
checkout the rational-legendre branch. Iris had realized that the Legendre polynomials could be written with exact arithmetic, using rational numbers in the fractions module.
Frank added a new test to verify the orthogonality, branching from the previous commit before Iris fixed the tests from that change. He also made a fix. They get into a small argument over which fix to employ.
Merge (or rebase) orthotest into rational-legendre. You will need to resolve the conflict (both merge, and interpersonal). Provide your reasoning for your choice in responses.txt.
You should have a layout similar to
┄ ─[A]┬ ┄
└─[B]┬─[C]────┲[E]
└─[D]────┚ ^
^ rational-legendre
orthotest
| Commit | Description ("message" or details) |
|---|---|
| A | "added zero finding, moved precision to conftest" |
| B | "egendre polynomials to fractions, section in report" |
| C | "fixed tests" |
| D | "added orthogonality test, fixed legendre test" |
| E | merge [D] onto [C] (If you rebased, the line from [D] to [E] will be absent.) |
With orthotest and rational-legendre combined, merge (or rebase) rational-legendre into the main branch. The result should have a report.md file with sections in the following order:
- Legendre Polynomials
- Finding the Roots of
$P_n$ - Exterior Newton's Method
- Deflation
- Gaussian Quadrature
By the end, you should have a layout similar to
┄ ───[F]─────┲[G] < main
┄ ─[A]┬ ┄ ┃
└─[B]┬─[C]────┲[E]─┚
└─[D]────┚ ^
^ rational-legendre
orthotest
| Commit | Description ("message" or details) |
|---|---|
| A | "added zero finding, moved precision to conftest" |
| B | "egendre polynomials to fractions, section in report" |
| C | "fixed tests" |
| D | "added orthogonality test, fixed legendre test" |
| E | merge [D] onto [C] (If you rebased, the line from [D] to [E] will be absent.) |
| F | commit on main from part 1 |
| G | merge [E] onto main (If you rebased, the line from [E] to [G] will be absent.) |
Frank remarks that they should have used
$\LaTeX$ for the report with theimportpackage to combine files. Inresponses.txt, explain Frank's reasoning.
checkout the gaussquad branch. Frank implemented gauss.py along with a compute_pi.py example code. Before merging the latter into main, Frank mentions that he wants to make some more changes, since he is not happy with just printing out estimates for gauss and the tests should be good to go.
Iris remarks that the commits can be pretty easily sorted between features:
| Commit message | Gauss quadrature feature | compute_pi / composite quadrature |
|---|---|---|
| "gauss quadrature + tests to 5-point" | ✅ | ❌ |
| "type hinting to legroot" | ✅ | ❌ |
| "added example code for computing pi" | ❌ | ✅ |
| "add explicit function integration function" | ✅ | ❌ |
| "change compute_pi example code" | ❌ | ✅ |
| "formatting, add degree of exactness test" | ✅ | ❌ |
| "add composite quadrature" | ❌ | ✅ |
| "rename my tests files so pytest actually sees them" | ✅ | ❌ |
She then asks if it would be possible to split gaussquad into two branches -- one for each set of features.
Demonstrate how to do that by creating a new branch at "type hinting to legroot" or earlier, and cherry-picking or rebaseing commits into that new branch, selecting only those with a ✅ in the "Gauss quadrature feature" column. You do not need to write anything to responses.txt unless you would like to. Merge (or rebase) this branch into main.
Then, create another branch called composite anywhere at or after "rename my tests files so pytest actually sees them" with the remaining commits so that Frank may continue working on his code. The tests should pass at the head of this new branch -- that is, you should be able to run
git checkout composite; pytestwithout any failures (apart from activating the environment or invoking uv). If a test fails, then you have not properly split the features.
The main branch, however, will fail, since Decimal and Fraction are incompatible, and gauss.py was not changed to account for that. Normally, we would perform the test before merging (or rather, making a pull request). This will be discussed when we cover CI.
While you may do it a different way, rebase --interactive can be used to handle both steps at the same time (minus the merge and new branch creation). Additionally, specifying [branch/HEAD]~[N] may be helpful.
Once you are done, gaussquad, main, and composite should look like
┄ ───[I]───────┲[J] < main
┄ ─[A]──[B]──[D]──[F]──[H]┬┚
└─[C]──[E]──[G] < composite
| Commit | Description ("message" or details) |
|---|---|
| A | "gauss quadrature + tests to 5-point" |
| B | "type hinting to legroot" |
| C | "added example code for computing pi" |
| D | "add explicit function integration function" |
| E | "change compute_pi example code" |
| F | "formatting, add degree of exactness test" |
| G | "add composite quadrature" |
| H | "rename my tests files so pytest actually sees them" |
| I | commit on main from part 3 |
| J | merge H into main (If you rebased, the line from [H] to [J] will be absent.) |