ChatGPT's Python Programming Skills on Display with Educational EOQ Model
ChatGPT could have big implications for supply chain and operations leaders. I've included five lessons and links to the code
My Twitter feed has been full of statements like “I’m not a coder. ChatGPT + Replit allowed me to build and ship a product in 45 minutes.”
I wanted to test this out with a simple program. I’m not a coder, but I can write some Visual Basic for Excel, simple Python in a Jupyter1 notebook, and do some basic debugging— but that is the limit.
Over the last two days, I’ve spent about 6 hours doing just this. Here are my observations.
First, ChatGPT is good.
I started my prompt by stroking ChatGPT’s ego— I’ve heard this may help.
Then I described what I wanted in plain English:
You are a great programmer. Write a python program that I can run in Replit for analyzing the EOQ model. The model should do the following: Ask the user for the values for the inputs, including decimal places, calculates the optimal value of the EOQ and rounds the answer to the user-defined input, and then iterates on the order quantity from 1 to 2X the optimal Q value and graphs the annual holding cost, annual set-up cost, and annual total cost.
The output was a fully Python model that could almost run (see the next section). ChatGPT knew all the correct syntax, what the EOQ model was, it knew how to calculate the costs, it knew to round the answers, it knew to get user input, and it figured out the graph I wanted.
Later, I saw that the graph wasn’t scaled right because the costs increase dramatically as you get to an order size of one. So, I had ChatGPT give me the code to change the scaling, and it did.
I could look at lines of code and ask questions like “why did you put brackets on this code?” and it gave me good answers.
I wanted to add a few simple things to the code. I could have either asked ChatGPT to help. However, what I wanted to add was simple, and I could copy other lines ChatGPT wrote for me.
Second, ChatGPT isn’t perfect (yet)
We hear how great ChatGPT is; what I saw above confirmed that. But, the initial code did have a bug in it. The graph wouldn’t draw. The code returned some confusing “overflow” error.
I asked ChatGPT to help debug. I gave it the exact error message. But it only thought the error was with the map and didn’t find the bug.
To help debug, I added a line to print out the values I was asking it to graph. I saw that one variable’s value shot up past infinity. So, that was the problem. As I looked at the code, I noticed that ChatGPT used the same variable name for what should have been two different variables. (It needed a variable for unit_holding_cost and one for total_holding_cost).
I described the bug in plain terms:
I think I know what is wrong with the code. It is not the plot. You have re-used the variable names in the calculate_costs function. So, the values grow exponentially
It apologized and fixed the code.
The code was now running in Replit and a Jupyter Notebook. It wasn’t fancy, but I was impressed with what it did.
You can see and run the code online at Kaggle or download the Jupyter notebook. See footnote for directions.2
This took about an hour and a half. Then, I spent another 30 minutes adding text and simple calculations to the code.
It would have been running in 10 minutes if it didn't create the bug. But, in fairness to ChatGPT, I would have created ten bugs, and my total time would have been over ten hours.
Third, deployment, even for a toy app, may still be hard for a non-coder
I failed to deploy a toy app. Instead of the code I shared above, I wanted to be able to share something that looked like an app.
I initially used Replit. The CEO discusses how Replit makes coding and deployment much easier for non-coders.
Four hours after the code worked, I had to show a blank screen with a run button. When you click the run button, you just get a blank screen. You can see the blank screen here. ChatGPT tried to help me— It gave me something like 8 to 10 complicated steps, but then it would crash and not complete the answer. Even if it had finished, I was intimidated by the steps I saw3.
Fourth, ChatGPT is going to make deployment platforms more valuable for business.
It may be too early, but my quick conclusion from the above points is that building business algorithms is much easier with ChatGPT, and deployment into production may still be hard.
Business leaders and their teams can build more algorithms that help the business run well. This also means that taking this code into production and creating robust applications will become more valuable. That is, the business leaders will need ways to allow the business to use these algorithms.
Fifth, to take advantage of ChatGPT, we need to think about coding differently.
Many people are already talking about this technology will change coding. I’m only framing the observations for people in businesses with a supply chain or significant operations.
We can convert the algorithms buried in spreadsheets and create new business algorithms.
ChatGPT takes away the need to understand syntax. Instead, we’ll need to think more abstractly about the programs (create more functions and modules), think more about testing, and think more about algorithm edge cases. In other words, we’ll need to be better prompt engineers.
I’ve caught the excitement of ChatGPT. A good business opportunity exists to translate this excitement into practical steps for Supply Chain and Operations teams.
If you aren’t familiar, a Jupyter Notebook is one of the common ways to write Python. It is a text editor allowing you to run code and see the results. If you work in friendly apps and good spreadsheets, a Jupyter Notebook won’t look that impressive.
The online version is hosted by Kaggle. You can see this even if you don’t have an account. If you want to run it yourself, click the “Copy & Edit” button. Then, you’ll have 15 minutes to try it out. Next, click the Run or Run All button to run it. It takes a few minutes to warm up. Then, it takes you to the bottom of the code and asks for inputs. If you download the Jupyter Notebook, I put the file on my Network Design Book website; Substack doesn’t allow me to upload Zip files.
I’m willing to admit that the problem might be me: maybe I should have spent many more hours learning Replit, perhaps the steps that looked complicated weren’t, or maybe I should have hired someone to help me. If it wasn’t me, maybe Replit isn’t built for the types of apps I want to make: supply chain, operations, and business algorithms. When I looked at other examples on their website, I found many games resembling amateur Atari games from the early 80s. I’m unsure if I should spend more time learning Replit or keep looking.
I think your points on abstraction and deployment are both good. Abstraction in particular seems to be the skill that will be valuable for copiloted programmers. To generalize from the EOQ example, it seems like anything with a Wikipedia page or known reference implementations could be implemented in a variety of programming languages by a LLM, but doing something novel will be more of a stretch. So, the way to do something novel (or, more likely, domain-specific) will be to break it down into well-known pieces that compose into something new.
That’s not too different from the way good programming is done now, but as anyone who’s maintained research code knows, we often don’t live up to that goal. I’m cautiously optimistic that GPT-era models can improve overall code quality while also raising the total amount of code in the world.
Enjoyed the article. Interesting world we are evolving into. I wonder how different a solution would have been produced if you said "write an R program"?