I let an AI agent rewrite my master's thesis code
In 2023 I handed in my master's thesis at NTNU, Trade-off between accuracy and time consumption in optimization algorithms for thrust allocation. It came with a Python solver and later a small website on top of it, and I wrote all of the thesis code without any AI help. Three years later I wanted to see how much that has changed, so I gave both repositories and the thesis PDF to Claude Code with more or less one instruction: measure the old version first, then rewrite it however you see fit, in Rust if that makes it faster. This is what came back, and what I checked before believing it.
The 2023 version
A dynamically positioned vessel holds its position with nothing but its thrusters while wind, waves and current push it around. The question the thesis answers is how much weather a given vessel can take before it loses position, for every direction the weather can come from, and the answer is a capability plot: 36 headings, and for each one the highest of the twelve DNV-ST-0111 weather levels the thrusters can still cancel.
Every point on that plot is an optimisation problem. My solver was a Sequential Quadratic Programming loop on top of CVXOPT, with each thruster's circle of possible forces approximated by a 24-sided polygon. Forbidden sectors, the angles an azimuth thruster may not push in, split a thruster's region into separate convex pieces, and every combination of pieces is a problem of its own. The drillship in the thesis has six azimuths with three pieces each, which makes problems per point. A "subset qualifier" threw away pieces pointing away from the weather to keep that number down, at the cost of yet another tuning angle.

Fun detail: my last commit to the old site's backend is called "Remove forbidden zones", and it took them off the drillship, which is the one vessel where they matter most.
Measuring it first
Nothing was rewritten until the old code had been timed on the same machine as the new one, with the original moved into a legacy/ folder and left alone.
The first surprise was that my code ran twice as slow on my current M5 Pro as on the 2023 laptop in the thesis. Thesis Case 3, the drillship with every sector combination, took 12 min 30 s in the thesis and 22 min 31 s here. The culprit is CVXOPT's linear algebra, which starts a team of OpenMP threads for every tiny matrix operation, and setting OMP_NUM_THREADS=1 brought it down to 45.9 s. That is one environment variable for about a 30 times speedup, and it was in my thesis timings the whole time.
The second surprise was about correctness. At 15 of the 720 recorded headings CVXOPT stopped with status unknown on a problem that was in fact feasible, my code read that as "cannot hold position", and so the 2023 plots were sometimes one level too pessimistic. A few more issues came out of reading the thesis against the code:
- Power was charged on the thrust left after losses, so with a loss factor of 0.9 the real power was 17 percent higher than the model said.
- Rudder forces were limited at the rudder angle instead of at the angle of the force the rudder produces, which gave about 2.5 percent too much side force.
- The binary search over weather levels assumed that a vessel that cannot hold level 6 cannot hold level 7 either, which is usually but not always true.
- The website ran with a 50 degree subset qualifier, which cost the supply vessel a whole level at two headings.
When it asked where the vessel data came from, I honestly did not remember, beyond having tweaked some of it until SQP stopped complaining. The presets on the new site are labelled as representative layouts.
A different method
The new engine drops SQP altogether and looks at the problem geometrically. For one fixed choice of piece per thruster, the set of surge forces, sway forces and yaw moments the vessel can produce is convex. Holding position against a load means lies inside that set , so capability becomes a question of how far you can go along the weather direction before you leave it:
The engine probes that set through its support function, the furthest the set reaches in a given direction, which has a closed form: one term per thruster, plus a water-filling step for thrusters that share a switchboard. Each probe gives an upper bound, a few probes combined give an explicit thruster allocation as a lower bound, and when the two meet the answer is proven from both sides.
Forbidden sectors are handled with branch and bound. A thruster with sectors is first allowed the convex hull of its pieces, which can only make the set bigger, and if the answer only uses real pieces it is the true answer. Otherwise the search splits on that one thruster and tries again, which ends up giving exactly what enumerating all 729 combinations gives without visiting them.

Blue is every force and moment the supply vessel can produce intact, and orange is what is left after losing a switchboard. The black line is the weather load from 090°, one dot per level, and where it leaves a set is that set's limit. The red dot is level 8.5, outside both.
On top of that the thruster regions are exact circles and sectors again, the limit between whole weather levels comes out as a wind speed, every level is tested so non-monotone cases get flagged, and power is the real in place of thrust squared.
The numbers
Thesis Case 3, one capability plot of 36 headings:
| version | time |
|---|---|
| thesis, as printed (Python, i9-13900H) | 12 min 30 s |
| 2023 code as written, M5 Pro | 22 min 31 s |
2023 code with OMP_NUM_THREADS=1 |
45.9 s |
| new engine, 2023 model, one thread | 541 µs |
| new engine, exact model, one thread | 3.3 ms |
| new engine, exact model, 15 threads | 748 µs |
The fair comparison is the third row against the fourth, the same model with the same answers, and it comes out at 84,802 times faster. Two things multiply to get there: the 2023 code solved 116,029 quadratic programs for that plot where the new one solves 248 small convex problems, and each of those takes about 2 µs instead of about 400. The exact model does more work, about six times as many weather demands, and still finishes in under a millisecond across 15 threads.

On the 720 headings recorded from the Python code, the new engine running the 2023 model agrees at 705. At the other 15 it is the Python that is one level low, for the unknown reason above, and the tests prove each of those 15 feasible with an explicit allocation.
The website
The old site sent a request to a Python backend on Cloud Run and waited 2 to 7.5 seconds for it, or 12 on a cold start. The new engine is compiled to WebAssembly and runs in the visitor's browser, so there is no backend at all. A full analysis of the drillship, intact plus every single switchboard and thruster failure at 36 headings each, takes 10 to 30 ms, which is fast enough to recompute on every mouse move. You can drag thrusters around the hull and watch the plot follow.

The worst-case failure, which in 2023 was a vessel file I edited by hand, is now computed from every single bus and thruster failure and the envelope of all of them. A Compare page overlays up to four plots, the 2023 model against the exact one for example, and the Method page has the 3D view from earlier to play with.
Checking the work
To check the answers, the engine is tested four ways: layouts with a known answer, an independent conic solver on random vessels, brute-force enumeration of every sector combination, and the recorded Python output.
After that a second agent was set loose on the engine with one job, finding correctness bugs. It wrote its own checks and found six real ones, and the worst of them turned out to be mine: forbidden sectors that overlap across north were merged along a line instead of around a circle, which turned "blocked from 340 to 10 degrees" into "free almost everywhere". That logic came straight from my 2023 sector code, and the old Python gives the same wrong answer. All six are fixed, each with a test that failed first. While taking the screenshots for this post I found one more, where the 3D view drew the set after a failure in its own units so it looked bigger than the intact set it sits inside, and that one is fixed as well.
My own part, apart from answering a handful of questions, was mostly being picky about the interface: panels that moved when an option changed, a table that jumped whenever a number gained a digit, and a focus ring that framed the plot on every click. That took a few rounds.
Three years later
The title of my thesis is a trade-off between accuracy and time, and for this problem that trade-off has mostly gone away, since the exact method is both more accurate and faster than the approximation it replaces. The rewrite, from my first prompt to merged pull requests, took one working day.
A few limits carry over from 2023. It is a static analysis with no vessel dynamics, the loads are the DNV-ST-0111 Level 1 formulas as I implemented them back then and have not been checked against DNV's own tool, and it is not a class-approved tool.
Try it at thrust-allocation-f3fcc.web.app. The 2023 version and the new one both have project pages.