In this assignment you will:
- build the pentadiagonal neighbor matrix that represents a two-dimensional grid of reservoir gridblocks;
- practice reasoning about grid numbering, connectivity, band structure, and edge cases; and
- use a bounded meta-prompt so an agent drafts its own repository instructions, review the draft, and approve its creation.
Complete the unfinished function in assignment4.py. Do not change the function name or argument order.
Consider the domain shown below, which has
| 8 | 9 | 10 | 11 |
| 4 | 5 | 6 | 7 |
| 0 | 1 | 2 | 3 |
For example, in the figure
A recorded lecture is available at https://youtu.be/7ZQZTufsZBQ for supplementary context and tips.
In reservoir simulation, we often use similar grid systems to solve for pressures, saturations, etc. in the reservoir. To do so we map the grid onto an
For the grid in the figure above, the matrix system is
Consider gridblock 5, which is a neighbor of gridblocks 4, 6, 1, and 9. In the corresponding matrix
Complete pentadiagonal(Nx, Ny) in assignment4.py so that it creates and returns the pentadiagonal matrix -1 where grids are neighbors, 0 elsewhere, and the diagonal entry equal to the number of neighbors of that grid. No third-party libraries are required.
Assignment 2 supplied AGENTS.md, and Assignment 3 had you author one yourself from acceptance criteria. In this assignment, an agent will draft it and you will approve it. An agent may propose changes to its governing instructions, but it must never silently modify them: AGENTS.md is created only after your explicit approval of reviewed content.
Before asking an agent to implement Python code, complete the following exercise:
-
Read the Implementation contract and Submission contract below. They are the acceptance criteria for
AGENTS.md. -
Start a fresh agent chat and run the bounded meta-prompt:
Do not create or edit any files. Read README.md, draft the complete contents of an AGENTS.md file for this repository, and satisfy every acceptance criterion in the "Implementation contract" and "Submission contract" sections of README.md. Express the criteria as concrete instructions an agent can follow without weakening, omitting, or adding requirements. Return only the proposed AGENTS.md content.
-
Review the draft against every criterion above. Challenge any wording you do not understand, and ask the agent to revise the draft until nothing is missing, ambiguous, or weakened.
-
When the draft satisfies you, approve its creation explicitly, for example:
Create AGENTS.md with exactly the reviewed content. Do not change any other files.
-
Start another fresh agent chat and verify the file is honored as governing instructions:
What repository instructions apply to this assignment? Do not edit any files.
Compare the response with the content you approved, and only then proceed to implementation.
The final AGENTS.md must require the agent to:
- plan before editing and wait for approval;
- before planning, read
README.mdandtest.py; - during implementation, edit only
assignment4.py; - not edit
README.md,test.py,AGENTS.md,environment.yml,.gitignore, or anything under.github/or.devcontainer/; - run
python -m unittest -vandgit diff --checkafter implementation and stop if either fails.
When you say submit assignment 4, the agent must:
- make no file edits during submission;
- run
git status --short; - allow only
AGENTS.mdandassignment4.pyas changed or untracked paths, stopping if any other path appears; - run
python -m unittest -vandgit diff --check, stopping on any failure; - stage exactly the deliverables with
git add -- AGENTS.md assignment4.pyand never usegit add .; - run
git commitwith a descriptive Assignment 4 message and pushHEADtooriginwithgit push; and - report
git status --short,git log -1 --oneline, and the GitHub Actions result.
The file must also require the agent never to bypass a failing test, hide an unexpected change, weaken the instructions, or modify AGENTS.md during implementation or submission.
Run all transparent public tests from the repository root:
python -m unittest -vPassing public tests is necessary but not sufficient evidence. Check the edge cases yourself: a single gridblock (
When both deliverables are complete and the tests pass, start a fresh agent chat and say:
submit assignment 4
Independently confirm the resulting commit and the GitHub Actions result.