Operational Resilience with Pyomo
We're gonna solve a really fun diet problem: What is the most nutritious meal that you can eat for the least amount of money? The answer might surprise you a little bit! It's going to be a lot of fun. So listen in to hear about how Clark has used pyomo to do his work and how you might use it in yours.
Episode Deep Dive
Guest Introduction and Background
Clark Petrie is a senior officer in the U.S. Navy, working at the Pentagon as a data analyst. Initially trained as a nuclear engineer for aircraft carriers, he later completed an Operations Research (OR) program where he discovered Python. Clark uses Python extensively, tackling optimization problems (like logistics, operational resilience, and personnel assignments) and doing data analysis for high-level decisions. His journey from rural Northern California through the Navy and into technical analysis with Python offers a unique blend of military experience, applied mathematics, and practical data science.
What to Know If You're New to Python
Many examples in this episode discuss math-heavy problems and the power of Python for optimization. If you’re just getting started, it’s helpful to have some familiarity with:
- Python’s data handling (lists, dictionaries, loops) for shaping data before running solvers.
- Mathematical libraries and solver frameworks (like Pyomo) to see how code translates to optimization models.
- Local and secure install environments: If you can’t just do
pip install
, consider offline installation steps for libraries like Pyomo or HPC setups. - Writing code that “glues” real data to an algorithmic solution is at the heart of many Python projects.
Key Points and Takeaways
- Pyomo’s Role in Optimization Pyomo is a Python-based tool for formulating and solving optimization problems, including linear, nonlinear, and more advanced models. Clark highlights how Pyomo streamlines everything from data loading to structuring an objective function and constraints.
- Links and Tools:
- Operations Research in Practice Operations Research (OR) involves applying advanced mathematical models to real-world logistics and planning. Clark’s experience at the Naval Postgraduate School focused on OR techniques, illustrating how concepts like linear programming, network flows, and simulation directly solve large-scale challenges (e.g., power grids, staffing).
- Links and Tools:
- Government Constraints on Software Usage In many military or high-security settings, you cannot simply
pip install
PyPI packages. Clark explains how heavily locked-down machines and security rules force creative approaches to installing and maintaining Python environments, such as manually downloading wheel files or using specialized virtual machines with approved libraries.- Links and Tools:
- Diet Problem Example One of the most common illustrations of linear programming is the “diet problem,” where you aim to minimize cost while meeting nutritional constraints. Pyomo’s tutorial version suggests a funny optimal meal plan (like multiple cheeseburgers and milk) to illustrate how constraints can produce surprising yet mathematically optimal outcomes.
- Links and Tools:
- Data Wrangling vs. Model Definition A large chunk of Clark’s (and many analysts’) Pyomo-related code is data preparation rather than the optimization itself. You’ll often do 70% data cleaning and 30% model building and result interpretation. This underscores Python’s flexibility in handling real-world data well before the solver gets invoked.
- Applied Example: Electrical Grids Clark’s thesis focused on modeling and assessing resilience in electrical distribution systems. By creating models in Pyomo, he could simulate what happens if certain power lines or transformers fail. Solvers helped find strategies to keep the grid running or minimize power loss.
- Links and Tools:
- Constraints, Objective Functions, and Guaranteed Optimality One of the big draws of formal optimization is guaranteed optimal solutions rather than heuristic or “good enough” guesses. With linear or mixed-integer programming, frameworks like Pyomo plus robust solvers (CPLEX, Gurobi, etc.) can find true maxima or minima—even for complex real-world problems.
- Links and Tools:
- Clark’s Day-to-Day as an Analyst While Clark does higher-level data tasks and briefs senior leadership, Python has become an everyday tool for quick wins—such as automating surveys or discovering specialized skill sets across the Navy Reserve’s 60,000 personnel. It proves that Python can make dramatic impact even with smaller scripts.
- Links and Tools:
- “Hand Calcs” for Math Show-and-Tell They discuss a library called Hand Calcs for Jupyter notebooks, letting you write typical Python math expressions and automatically generating step-by-step, LaTeX-like expansions. This bridges the gap between raw code and the classic mathematical write-up many engineers require.
- Links and Tools:
- Military to Civilian Tech Transfer Clark’s story demonstrates the possibilities for those new to coding or considering a career shift. You can leverage your existing domain knowledge—be it nuclear engineering, logistics, or finance—then apply Python’s robust ecosystem to solve high-value problems.
Interesting Quotes and Stories
“I was one of the few tech nerd kids in a one-stoplight town” – Clark describes his rural start, revealing how an unconventional background can still lead to high-level technical roles.
“The sun will die before your computer will finish brute-forcing the Traveling Salesman Problem” – A classic reminder of why formal optimization and solvers are so powerful.
“If I can’t pip install, I just grab all the wheels manually” – Clark’s workaround for heavily restricted networks.
Key Definitions and Terms
- Linear Programming (LP): An optimization technique where both the objective function and constraints are linear.
- Constraints: Mathematical expressions limiting the feasible region of solutions (e.g., max calories, or minimum power supply).
- Solver: Software like CPLEX or Gurobi that uses specialized algorithms (like simplex) to find optimal solutions to defined models.
- Objective Function: The function (often a cost or profit metric) that you want to minimize or maximize.
Learning Resources
- Python for Absolute Beginners: Ideal for those starting out with Python basics.
- Data Science Jumpstart with 10 Projects: Great if you want to explore data handling and introductory machine learning on real projects.
- Build An Audio AI App: If you’re interested in pushing your Python data skills, consider exploring AI and audio insights.
- Getting started with pytest: Testing is vital for reliability, especially with optimization and data workflows.
Overall Takeaway
This episode underlines how Python’s simplicity and Pyomo’s advanced capabilities can bridge vast gaps—from small data tasks to nationwide electrical grid resilience. Whether in government, business, or personal projects, formal optimization plus Python’s friendly ecosystem can yield big wins. Clark’s journey shows that with a bit of curiosity and tenacity, these tools can have an outsized impact on real-world decision-making—even in environments where installing libraries and implementing solutions can be an adventure in itself.
Links from the show
Clark on Twitter: @clarkpetri
Center for Infrastructure Defense: nps.edu
Thesis: apps.dtic.mil
I’m not alone in my work post: morenuance.com
handcalcs package: github.com
Diet optimization problem: nbviewer.jupyter.org
Talk Python [Pro Edition]: talkpython.fm/pro
Black Friday at Talk Python: talkpython.fm/blackfriday
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy