Monitor errors and performance issues with Sentry.io

#291: Operational Resilience with Pyomo Transcript

Recorded on Thursday, Oct 1, 2020.

00:00 Do you have a scientific system that needs optimization or solving our guest on this episode, Clark Petri is here to tell us all about bio Mo. This is the library that can solve all sorts of cool problems, linear programming, nonlinear equations, and many other things that you can throw at it. We're going to 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 gonna be a lot of fun. So listen in to hear about how Clark has used Python to do his work and how you might use it in yours. This is talk Python to me, Episode 291, recorded October 1 2020.

00:47 Welcome to talk Python to me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter, where I'm at m Kennedy, and keep up with the show and listen to past episodes at talk python.fm and follow the show on Twitter via at talk Python. This episode is brought to you by linode and talk Python training. Please check out the offers during their segments. It really helps support the show. Hey everyone, two quick announcements before we jump into the show. Number one, I really appreciate everything that many of you are doing to support us here at talk Python and make it possible for this to be my full time job. Our primary means of support is through the courses over at talk Python training. And I've been thinking about how I can offer you something special in return. What I've come up with is something I'm calling talk Python to me, bro edition. It's like regular talk Python, but it comes with two perks. It is ad free so you can listen without any interruptions. And you'll have the entire history going back five years to episode zero in your podcast player. Talk Python me Pro is available exclusively to listeners who haven't everything bundle over at talk Python training. If this sounds like something you want, Learn more at talk python.fm slash Pro. And if you already have a course bundle, just visit that link for details on how to add the pro edition to your podcast player. announcement number two, somewhat related to talk Python Pro, Black Friday is just around the corner. If you're listening to this episode, right when it comes out, we'll be offering major discounts on our brand new fast API course. And on our everything course bundle over at talk Python training for just four days. So visit talk python.fm slash Black Friday, to get notified when the deals go live. Thanks so much for your support. Even if you're just listening, it really means a lot. Thank you. Now, let's optimize some things with Python. Clark, welcome to talk Python to me. All right. Thank you, Michael. Happy to be here. Yeah, I'm happy to have you here. And we're going to talk about operational resilience and using a package called Pio Mo, which is about solving all these constraint problems. Which brings me back to my math roots, right. Like I didn't do that much applied math. But I definitely studied a ton of math before I got deep into programming. So it'll be a fun journey. I think happy to have you. Here. This is a lot of fun for me. I've been a fan on the show for a while. And it's a kind of surreal to be sitting here talking to you right now. So this is exciting and fun. And I'm happy to spread the joy of piombo to the audience. Yeah, and honestly, I had not heard of Pio, Mo. I obviously know about some of these like solver type systems and the general concept. But I've never used Pio Miller and it looks really cool. We have a really fun and slightly comedic but honestly serious example to go through as well to give people a sense of like the kinds of problems we're solving. But you know, that's not where we start the show, right? We start with your story. So let's start there. How'd you get into programming and Python? America, I took a really roundabout way to get there. Just for I guess, audience context. I was born in 81. And grew up in rural Northern California, kind of one of the few tech nerds in a one stoplight town. I mean, there was literally a girl that rode a horse to school. I'm not even joking about that. No way. That's crazy. Yeah, we had these like ag fields out back, and she would sometimes ride her horse to school and put the horse out to pasture during the day. So that's actually really cool. It was nice for her. I was not into that. But like, especially looking back now I can go that that's pretty, pretty legit. Yeah. But I was like I said one of the few tech nerd kids and I remember the early days of AOL, and I was actually making money as like a sophomore making webpages for local businesses. Okay, yeah, I guess the HTML that I did all by hand back then, we could say was my first experience programming so to speak, I did a little bit of IRC bot coding. I love trying to make what we now think it was like a chat bot. If I'd had some foresight, I could tell there was a future in that. But it was just for me, it was a toy. And I love that stuff. But I was just mean a single mom predominantly, who, despite her best efforts, didn't really know how to guide me to call it so I kind of stumbled into joining the military, specifically the Navy, right after high school 99 fast forward to actually get to answering your question.

04:46 They cultivated my potential. I eventually got commissioned as an officer and in 2015 I got sent to the Naval Postgraduate School for the operations research curriculum, which that sounds really cool. I often will colloquially Yeah, it was it was a great opportunity.

05:00 I got paid to go to grad school. So I can't like the luckiest guy around, which, you know, for someone that hasn't heard of, or a lot of us will just kind of cheat and it's called applied mathematics compared to open not offending any, you know, actual math masters out there. But from looking at the curriculum, you know, we just kind of drop a few math classes and a few programming classes which answer your question in the first quarter, we took a Python course. And I just, I kind of fell in love and quickly realized that was the main technical tool I wanted to cultivate for my time in school, and also what I wanted to really use and whatever thesis ultimately ended up doing. And yeah, here we are now. Yeah, here you are. You've done your thesis and with Pio, Mo and Python, and we're gonna talk about it. Great. Yeah. So it's never too late to learn to code. I mean, heck, I was, yeah. 35. Yeah. And when I started that, so well, I wasn't quite that far along. But I hear a lot of stories from people like, Oh, I started when I was four, like, as soon as I could sort of kind of read I was on the computer, and why not? And for me, it wasn't that way at all. It was basically grad school, almost grad school, senior college, doing research projects going actually need some programming skills to start answering these questions. But once I got into it, it was like, why am I studying this other stuff? This is way more fun. How do I do more of this and less of what I've actually getting my degree and that that was a bit of a problem. But it worked out? I suppose. Yeah, I did some more stuff where I kind of juggled around electives, to take more programming classes. While I was there, because I was enjoying it so much. I kind of put off other pain till later, I guess you could say, exactly. So what is operational research operations research, like what kind of problems are being solved there, give people a sense of what that means. So from the military perspective, in particular, a lot of it is logistics and optimization. So in that curriculum, there's kind of three main tracks, people tend to fall down. One is the optimization track, you could say, that's where I went. Another is more of a just data analysis, track a lot of lot of regression analysis. And the third would be simulations. And I guess you could say, just trying to drive answers through some kind of simulation theory. So within operations research, we're looking to find the best way to go about doing something. So some of those classic computer science problems exist in that domain, I'd say, you know, the Traveling Salesman Problem is right, an early one. Right. And it's about doing that at scale for the Euler bridge problem. Yeah, that one that Seven Bridges city, I forgot the name of the city. Yeah, you know, we we go through some of the classic use cases during World War Two with like,

07:34 God, like, Ivan post World War Two, I want to say but like, looking at the Soviet railway system, and how what's the minimum cut? Right to essentially disable their railway system if they were to invade? Right Europe? Right. And right, it's okay. A lot of work in that domain. Yeah. Okay. Pretty interesting. And I'm still looking forward to the example we're gonna get to, but I'm so goofy and contrasted with the seriousness of these these things. But how about day to day, like, what are you doing now? So right now, I'm a senior officer working in the Pentagon as a data analyst. Let me just really quick, I got to get the obligatory, obligatory, the views and opinions expressed here are mine and mine alone. They do not represent the US government, the Department of Defense or the US Navy. So there we go. Set it safe. This is the world of Pio, according to Clark, not Yeah, the US. Okay, got it. Yeah. Yep. Got it. So basically, I work for a three star Admiral, which is pretty darn senior. And he is in charge of the entire Navy Reserve. So for kind of civilian context, you could think of that as a multi billion dollar company with 60,000 people. Yeah. Wow. Okay. And he's the CEO, if you will. And at the Pentagon level, and we have, you know, it's a military serving steered, it's very vertical. Yeah. And I'm one of those two data guys, basically. And we have one never ending project, which is we're always analyzing and forecasting our personnel strength. So, which is a multivariate problem in and of itself, we got to look at as the Navy Reserve, we receive people that leave the active duty, Navy, but we also can recruit off the street. So we get folk, they're coming straight into Navy Reserve, those that are leaving active duty, and we have to try to plan out how many people were going to happen. Do we have the right types of people for our different missions across the future years defense program, which is sort of the budgetary outlook, that's our main job, but honestly, we probably spend more of our time just digging into random data for whatever the admiral needs to be educated on the other senior decision makers in the Pentagon, so they can go forth and move out. COVID was a big example of that. It's funny, you have the world shut down with COVID. And literally, the Joint Chiefs of Staff are coming to us wanting answers now. Like right now, right? Yeah, you got to tell us this. So yeah, so it was uh, me and my counterpart got really smart on a pretty thorough analysis and built a unified data project to answer anything about Navy Reserve medicine, because we have doctors and nurses and critical care and all that in the Navy Reserve. So how many do we have and if we pull them out

10:00 To go to New York, are we pulling them from a hospital and another hot spot? Yeah. And their civilian life because they're a reservist. And so that's answering questions like that as a recent example, you could say is what I do. Okay. Yeah. Two things I want to talk about. One is, we saw the nightmare. That was the cruise ship industry, right? Yes. And I think there's still people around the world who are still stuck on these cruise ships, right? Like not cruisers, they were taken and put somewhere I remember like, I guess it varied where you were. But people who worked on the cruise ships, I think there's still a ton of them stuck there. And that's just insane. And yet, I used to live in cornado, California, little island outside of San Diego for a little bit, there was two of the main aircraft carrier station there. I know that pier very, very well. It's It's a beautiful place. But the reason I bring that up is literally the traffic would change. The traffic patterns would change how much traffic there was, and whether or not the aircraft carriers were home or they were gone. Because there are so many there's like 5000 people on an aircraft carrier, something like that.

11:07 So this is you're getting really into my wheelhouse my first 10 years as an officer, I was one of the nuclear engineers for aircraft carrier Raptor plants. Oh, wow. Okay, which is why I had the technical aptitude to do the research program for like eligibility. And yeah, with the carrier has the air wing embark you're looking at five or 6000 people. Yeah. And when the air wing all the planes and everything associated there is not there, you're talking about 3000? Either way, whether a carrier is important changes the quality of life for a computer for sure. Yeah, I mean, it would change would dramatically change. So why do I bring it up? Well, you guys got these. I mean, that's the same size as a cruise ship or bigger, and you've got all these people on there. And that's a huge challenge. I mean, how did you deal with that? What was even the outcome? I know that there was a commander of one of those carriers that was lost his job, basically, because he spoke out about like, this is a serious problem. He was very upset and kind of went above rank or pulled rank or something like that. Right. Yeah. I mean, I can't really like I wasn't there, right. But I can only report what I kind of saw on the news. I don't have much insider information, if you will, but we take rank and reporting at the chain very seriously. And I feel for that gentleman. My job before this was as a commanding officer. And he was facing important credibly tough decisions. And it's just the whole thing's unfortunate. But as far as what you're getting at with, like the cruise ships that are dealing with such rampant code problems, yeah, that's really tough. Because on the ship, where are you going to go? Right? Yeah, but one way that I think we haven't been as decimated the wrong word, but maybe negatively impacted with our ships. Partially because generally, most of the sailors on ships and the average age of a Navy sailor was like, 21 years old. We're talking pretty healthy people, which is probably not the same age as the average cruiser I do

12:56 on a cruise ship. But I if I need to feel young, I can also do that right there. Right. So I think this price, some degree of extra resilience, I would think amongst our personnel and ships that has probably helped mitigate the problem. And I'll tell you this, we have also had for the military, right, and when, and we need to be ready. The restrictions in place on us for doing things that would possibly increase your risk profile are pretty strict. Yeah. Like even though I'm in Northern Virginia, you know, my wife can, she could go out and go eat and hug everyone she wants to hug. But like if I were to go when I'll give an example, one of my big personal hobbies outside of nerd stuff isn't a big Brazilian Jiu Jitsu guy, which is okay. really mean wrestling, if you will. Yeah, it's cool. But it's also kind of up close with other people. Yeah, there's no way to socially distance when you're rolling around with people, right? And egg. If I were to go do that and get COVID technically speaking, I would have disobeyed like a direct order, right? You know, and I'm Senior enough that I probably wouldn't get like in real trouble, if you will. But I know like, I'm a good boy. So yeah, the dope restrictions in place like that are protecting our people more Sure. Well, and also just like what you do on a cruise ship, like you go from port to port, and you go out and experience those places. Whereas you can say, you know what, we're not going to go into port and you guys don't go anywhere. You stay here, which is a different kind of experience, I guess. Yeah. No more pulling into Hong Kong and going wild. I suppose. It's pretty restricted Liberty when the ships do Poland? Yeah, exactly. But I'm a desk jockey. Now my ship going days are way behind me.

14:33 This portion of talk Python to me is sponsored by linode. Simplify your infrastructure and cut your cloud bills in half with linode. Linux virtual machines, develop, deploy and scale your modern applications faster and easier. Whether you're developing a personal project or managing large workloads, you deserve simple, affordable and accessible cloud computing solutions. As listeners have talked Python to me, you'll get a $100 free credit. You can find all the details at talk python.fm slash linode.

15:00 linode has data centers around the world with the same simple and consistent pricing. regardless of location, just choose the data center that's nearest to your users, you also receive 20 473 65 human support with no tears or handoffs, regardless of your plan size. You can choose shared and dedicated compute instances, or you can use your hundred dollars in credit on s3, compatible object storage, managed Kubernetes. clusters. And more. If it runs on Linux, it runs on linode. Visit talk python.fm slash linode. Or click the link in your show notes. Then click that create free account button to get started. Got your land legs back. Okay, so let's talk a little bit about me just asked about Python and the government, our programming and the government. I did 10 years of in person training and how much of that was at places that were like HP, or JPMorgan or something like that. But periodically, we teach classes at military places. And they were a little bit different, right? Like I did a class for the people that ran the launch control for NASA. I think they were technically Air Force. But still, that was pretty cool. And someone Edwards Air Force Base. And I talked about like, Oh, yeah, you just pip install this thing. And you get like, look at this amazing package that are like, that's really awesome. We're never, ever going to be able to do that. We can't just install stuff off the internet. So tell us what programming in this world feels like. So

16:25 that's the tough part, right? Is anyone listening? This show probably knows what pythons capable of. And we're all here because we love it. Right? It's a great language. And then there's the government limitations that you just got to. So there's a group in the Pentagon called nav one that doesn't really mean anything, but they're kind of some of our researchers on the Navy side. And a lot of ops research guys, and a lot of coders. We do in some cases have standalone machines that are able to touch the outside world. But they're just not plugged into like our broader just unclassified internet, which is called nmci. For Navy, Marine Corps internet. Now, some of those nnd one folk, allegedly treading a little bit dangerous water, maybe maybe found a way to kind of get Python working on their machines. But to try to do work. But again, what you got to a truth, which is Oh, you got you need some package. You can't just pip install it. Again. Allegedly, it might be the case that you have to download the wheel dot w HL files. Yeah. Why? Yeah, yeah, you have to download the wheel files. I call them wheel files. I don't actually know what Yeah, yeah, yeah, you have to download those manually and install them. But of course, if one package needs like subservient packages, you have to like backtrack, right? until you have what you need to then get Python running. But even if you go through that heartache, you now we're facing another conundrum, which is, you have Python running Yay, on your government computer, which because because we're so big, and we try to standardize everything. And for good reason, there's a lot of background processes running to keep machines up to date. And to monitor activity in such a core IE five, with eight gigs of RAM that is

18:06 permanently got 80% of that used isn't exactly the like analytical monster you might want. Right? And so and he trying to decrypt the drive and run the three different virus scanners, and then the network monitor it's like at a permanent 60% CPU usage before you touch it, right. Yeah, exactly. You know, too well. So that's the hard part is someone like me, I'm always beating the drum. My last boss, when I was a commanding officer probably got tired of me beating the drum about you know, if we can improve the technology that our sailors have will be so much more efficient. Yeah. And that's one of our limitations. And I understand and get the complexities of that problem. It's not easy. It's not Oh, you just got hired with insert tech company here. Here's your new MacBook. You can't do that with us. Yeah, exactly. But that's sort of the challenge. Now, what's sort of interesting is COVID has changed a lot of that, right? It's changing for I think, for banks, and for all sorts of industries that were like, We can't work from home, you can't access this from your home. But you guys are kind of the far end of that spectrum. Well, yes, comma, I've actually been working from home for six months, which has allowed me to with data that is not sensitive, obviously, the main thing that I would be dealing with would be personally identifiable information that's on my machine. I keep a good delineation. But a lot the main data sources I tend to work with don't have that anyway. So I've been able to move a lot of my analytical work to my personal computer, which I'm a nerd. It's a good machine. Right. So yeah, that has sort of supercharged me with what I've been able to do as an analyst in this work from home environment, which has, at least in my case, but I can just kind of sense that across the broader structure of the military. The higher ups are realizing Oh, wow, our people are more effective in a lot of cases. And they're happier. What Yeah, exactly. Wait a minute, and we're big fans.

20:00 Fancy building we can go to, but they don't want to go to it anymore. Like it's, yeah, it's a really interesting paradox. And what's silly about that is, for anyone listening out there that's doing data work, I work in a secure space. So I can't have my cell phone, and I'm not missing it because I want to play a game. I can't have a podcast going, Yeah, I can't have music going. Right, and just that change alone, just to put on something when I got to really focus on a data problem, and just get some kind of good techno transcoding, if you will. And the classic coder, you know, just have the distractions, right. Yeah, it helps. So COVID changed a lot of that for us. And I can just tell I think like the whole world at large, we're just a microcosm of it. It's, we're never gonna go back to normal, whatever that was, yeah, we're permanently going to be in. So what about like, things that allow whitelisted packages to be vetted? And then, like, local PI, PI Server type of things, as that's something you guys have looked at? Or maybe we'll be looking at? Yeah, there is some of that happening. So government is headed in that direction? The senior people they get it? I mean, it isn't like they don't know. Right? Yeah. And they can recognize that we, from my point of view, anyway, maybe a little bit behind just a little bit behind our civilian peers, and know they need to bring that stuff online. And we're starting to develop some of that I know, some of my counterparts in my office, you know, working for the Admiral of the Navy Reserve. They're helping they're involved the process to develop what we're calling the authoritative data environment, which is going to be sort of a, what's the name for when you have like a kind of a machine and a machine. I'm blanking right now, like a virtual machine or a virtual machine now just just playing, it's basically a virtual environment you can like remote into, and then you're going to have the full suite of packages, and presumably someone would have right whitelisted all the Python packages you could want. Right? So we're trying to get there. It's just we got to get there while navigating the limitations of our government requirements, which are, you know, many which are in congressional law. Right, right. So it's not that that's an easy thing to change an update. It's not like there's just a piggy manager.

22:09 So that's where we're headed. So another thing, I don't want to get too far down this rabbit hole, but it is interesting to me. So let me ask them the question. So have you guys looked at things like VS code has the ability to just like run in the browser and execute code and say, like a Docker environment in Azure or other places? Where if you just have access to the internet, you basically have unbounded compute, like, have you looked at those types of setups or even creating like isolated, something like that internally, but then setting up those kinds of servers? There is something like that, and it actually shows you how much in demand it would be, when that finish got set up. I'm blanking on the name. I haven't tried to use it for almost a year, the demand he was overwhelmed and just killed it. Yeah, yeah. Demand from people like me was so significant, it just it just vomited and died. And it was really hard to use. And then the other problem is, we don't exactly have the fastest pipe up and down to do work like that. So you're gonna be working in a high latency environment, oftentimes, which can make the experience more challenging, but there are setups I know the Air Force has one that's pretty robust. Okay. I think that's kind of ironic, given that our ARPANET and DARPA and all that stuff sort of created the internet. Yeah, right. And I know people here I'm in the Pentagon, they picture some kind of like Jason Bourne control room. Right. And those places exist in the Pentagon. I'm not in it. Yeah, but exactly. Yeah, yeah. Cool. All right. So another thing I want to kind of touch on is you wrote an interesting article that actually touched on an episode with Jacqueline and Emily, about the different branches or potlucks. When you say I'm a data scientist, or I have a career in data science or data engineering, like that actually could mean a whole bunch of different stuff in really interesting ways. kind of map out that world. You want to talk about that a little bit. Sure. Yeah, I have a blog. That's for me, I don't I haven't even done like good. Seo on it, for that matter. But that episode was 262. With Jacqueline and Emily, you know, they described different kind of fictitious companies, and one of them when they got to the ghost is a large company, probably a lot of government contracting, maybe it is government, you know, my ears perk up. Maybe it's Boeing, maybe it's even the Pentagon. Okay, right. And then they perfectly describe some of these challenges we just discussed, which is, wow, you don't have access to the tools you want. But then they really go down the analyst role, which is certainly what I consider myself. I'm technically trained. I have technical skills, but especially at my level, it's, they were so eloquent and how they described it. I'm the one who, almost by virtue of my education, when I speak to numbers, it's gospel. Yeah, if you will, and and that's an important trust, right? My Apple, trust me that I'm right. And I can never betray that. So I'm the one that's kind of in the boardroom, if you will, showing the CEO the charts and breaking down

25:00 What what for them as opposed to the real data engineer in the trenches? Right? Like deploying a machine learning model to production in a very like a fast API implementation, right? Not so much that No, no, not at all. I have done some technical stuff with Python in my current role, and we can talk about that. But I am more the Jacqueline and we talk a lot about can we say Excel and PowerPoint? Oh, my God, that's, that's my life. My PowerPoint skills have become much stronger in the last year of this job than my coding skills. That is the lingua franca of that whole environment, isn't it? Yep, absolutely. I legitimately was joking with my other data, buddy, that just about what a PowerPoint savant I become almost to the point that like, it's like, oh, you want your slides touched up contact Clark. So that's a feather. I remember doing a training course with this group out of the Air Force Academy in Colorado Springs. And like, one of the pinnacle moments was when we found a way to dynamically generate one of the slides in PowerPoint, it was like it would pull in data from where all the planes were flying. And it would dynamically like in real time, or like near real time update, what would be shown in the power, it wasn't like enough to have that on a webpage. It was like, it needs to generate a slide on live data. Like, why would you do that? Doesn't matter why it has to do this? Because this is the world we're in right? Yep, we are. We are beholden to PowerPoint, for sure. It's funny, we talk about PowerPoint, because Tableau was starting to gain traction, people are realizing the power of a good Tableau dashboard. And that has, if nothing else, been named Tableau like is spoken and whispers in the halls of the Pentagon. So you know, maybe we'll get there eventually. Yeah, it's a bit of a step up. It's a bit of a step up. Yep. But yeah, anyone who has not listened Episode 262. And I'll link to it. Jacqueline Emily wrote a really good book. Like, I'm not even that interested in a data science career for myself. And I'm like, this is like a page turner. This is really, I think they really broke it down well, and it. People ask me, like, Oh, I want to get into data science. What should I do? What should I study? I'm like, that's not enough. I don't know enough to answer your question necessarily, because that means kind of different things. So I recommend people check that out. It's a good one. Yeah, definitely. I mean, for me that that episode gave me like validity, I'm the kind of the king of imposter syndrome. And I heard that I was like, oh, like, they describe a legitimate, valuable role that I'm kind of well suited to. Sweet. That's awesome. That's all right. Well, because you might compare yourself against like, the machine learning people deploying machine learning models at Google, you're like, well, I can't do any of that. Like all that is foreign to me. Right. But that doesn't mean you're not doing valid data science. Like you're just doing, like a different slice of it. Yeah, absolutely. And it's important to have someone that can speak to it and translate it into the common vernacular, if you will. And I think that's kind of where I've found myself. Yeah. And hearing them talk about that gave me hope. Because whenever I retired from the service, and a couple of years, potentially, like, Okay, cool. There are roles in the outside world, some kind of weird military, Stockholm Syndrome. I know that there are, yeah, I suspect that a lot of the stuff that you work on it, you can't really share, talk about a bunch. And so it, it doesn't give you that chance to kind of put it side by side with other people. Let's talk about your thesis and this optimization stuff for the Python library. piombo. Sure. So you said you did you work at Los Alamos National Labs, right. Yeah. So I can back that up a little bit. Professor David Alderson who was one of my thesis advisors, he's the head of the post graduate schools, Center for infrastructure defense, I wanna make sure yes, interpreter for infrastructure, defense, making sure that the power grid doesn't go down. And that the internet stays on and things like that. Yeah, absolutely. It's a power water. And then it goes two ways, right? from a military context. It's about protecting our stuff in a potential theater of war, whether we're setting up a forward operating base in theater, as we would say, or domestically. But at the same time, if we know how to protect our stuff, and are smart on that, we also know how to take out the enemy stuff better. Yeah. And, and so it works both ways from a military context. So he's the head of that center, and I got hooked up with him, mainly because he was, uh, he taught me the more advanced coding courses I took while I was there, and I, again, loving the language coming back to how we started. And he was working in conjunction with a researchers at Los Alamos National Labs, which is how I got hooked up with them. Okay, so which, which was a great opportunity that's out there for several weeks to just be in that environment, learn and kind of get hands on with some other data, which is able to bring back for my thesis, which then Panama became kind of the cornerstone of it. Yeah. What was your thesis about? Yes. So is assessing the operational resilience of electrical distribution systems. So yeah, okay. At the time anyway, transmission, you know, think the big power towers that you see when you're in the middle of a highway somewhere. That's the transmission lines. Those are really well understood the white and orange ones that are really high. Yeah, those ones right. Okay.

30:00 Yeah, those are really well understood and modeled as we understood, but distribution like what's in your neighborhood? What's in your town was and obviously distribution works great, right. But from our awareness, no one had really built a model using real world data, taking into account all of the mathematics for three phase AC transmission. That's kind of where some of my nuclear engineering background helped, because I was cursorily familiar with that stuff. I mean, that's basically a power plant as well, right? Yeah, power plant and all the distribution, right. So I was familiar with concepts like real and reactive power, knowing about a model that took in real world data. And what we could basically do is say, hey, if we take out this electrical pole, or that transformer, what will unequivocably happen? Most analysis had been based, it was essentially data analysis and regressions where you look at a disaster that happened, maybe a tornado touchdown in Oklahoma. Right. Okay. We know that the tornado damage here, here and here. Okay, we understand the results of that. Now we're gonna apply those results and think we'll know what will happen somewhere else. But we built a model that allow us to unequivocally state what would happen, yeah. Okay. And so the optimization part of that was working with the distribution system, you know, we kind of made an assumption, if you will, that we want to minimize how much load real than reactive power load is lost if you take out a telephone pole or something, right. So the end, the grid wants to keep power going everywhere the power is being asked for. So what we're trying to do is minimize the amount of power lost when you essentially mess with the network. Right? Okay. I grew up in Kansas City, Tornado Alley is sometimes called we ran experiments like that all the time of what happens if we take out this, this block of thing or whatever, but yeah, not not in that clear sense, right, like stuff, but just get blown over and like, see that little capacitors, wherever it's explosive, those gray cylindrical things that are on the towers? Yep. The Poles. Yeah. All right. So use this library, Pio? Mo, tell us about that. Yes. So what the library does, like we talked about the beginning, I can't talk to what's happening behind the package. Sure. But it allows us to set up an optimization framework as a consumer of it, yeah, I'm, I'm a consumer, right. So allows us to set up in Python and optimization framework to, I guess, structure these problems. So we're talking about an objective function, it can be a multi objective function, and then the various constraints to perform linear or nonlinear optimization in whatever capacity you want to. So using the everything that we love about Python, right, the relatively straightforward syntax, and then all the tools beyond that, which made it unique, we can set up these problems, and then throw a solver at it, like seaplex is what I used, which to me is a bit of a magic black box, though, we went into some of the mathematics behind that, obviously, like the simplex method, and all the dances work back in the 40s. But we throw simplex at it. And then structure in Python, how we want our results. And voila, you know, in the case of my thesis, we get a detailed printout, if you will, of what loads stayed up, what went down, and we can analyze that all within a Python framework. Yeah, as beautiful. To give people a sense of this, let me maybe go through some of the problems that it solves. And then like some examples of using it, then we'll go through a concrete code example. That'll bring it together. So looking through their docs, some of the things you can do is linear programming. And I don't know how many people have done linear programming. It's really simple. It's not necessarily easy to compute. But it's not like a complicated thing. But it really it's incredible the way that that like, this is the exact answer, like all these constraints, here's the optimization. I love it, because it's simplicity plus power. Yeah, well, we always talked about linear programming is guaranteed optimality, right? It's pretty straightforward, or you have a local minimum or a local maximum. That's not the actual answer, right? Yep. Yep, exactly. And in some cases, especially with non linear problems, you can get stuck in a local minimum or maximum depending on where you're going. But generally speaking, if you write a greedy heuristic, you'll you'll get a good answer. But is it optimal? Right, and that's the real sticking point that the professor's there because maybe this comes back to kind of that military background, but we often will not settle, especially in a war context, I suppose, for anything that's suboptimal. Right. And that guaranteed optimally, and I know an example of FedEx, right, right. They gobble up a lot of the ops research graduates out of the post grads out of the Naval Postgraduate School, and because their profit margins hinge on optimality with delivery, right that there's a traveling salesman problem for you, right? Yeah, yeah, the whole ups FedEx Delivery stuff, especially the same with COVID. It's like insane how many those guys are drive around. So we've got linear programming.

35:00 quadratic programming nonlinear programming where it gets really interesting. Let's see stochastic stuff, just junk divx programming or anything about but differential algebraic equations equilibriums, all these different types of problems, it can solve those. And then some of the projects using it that they have listed on their site that I thought was interesting is the display set, which is unit commitment and dispatch model focused on balancing and flexibility problems and European power grids. It seems like it comes back to power a lot, honestly. Yeah, I was actually surprised looking through these seeing me power problems there were which I don't know why would not have expected that. But yeah, yeah, I didn't either. But yeah, that's cool. There's another one, which I don't know how to pronounce. Ida II s. PSA PSE toolkit, which is a open source optimization based framework for chemical processes, which is pretty cool. Min power, which is an open source toolkit for students and researchers in power systems, open energy modeling framework, like I said, it's a lot of energy in here, which is a open framework for developing energy models that emphasize communication, and community involvement. And then open agua, which is a web based app for modeling water systems for water resource planning and management. So I think that gives people a sense of like some of the types of problems This is being applied to. Yeah, and I know, those are kind of, because obviously complex and real world I know, in a learning context, many of the classic computer science problems traveling salesman, the knapsack problem, if you're familiar with data for the audience's essays, basically, I have a bag that can hold 20 units of stuff. And I have 100 units worth of things I want, I would love to try to fit in it. How do I maximize my value by putting in the knapsack? We would structure problems like those in piombo, while we were learning, right, the package, right? So some of those classic problems can be solved here. Yeah, yeah. Cool. All right. So on the payment website, they have this dietary problem, they have a bunch of examples of here's some examples using Do you want to talk us through this, it's a little bit hard to talk about code over the air. So we'll just keep it kind of vague in general, but maybe talk us through this and people go, Okay, I see what this does, and how I might use it. Yeah, this is a great example. Especially, I don't want to spoil it, but it gets a funny result. So what this diet problem is trying to do, and this is a classic optimization problem, is you want to select you have a given group of foods, and you want to select foods to meet your nutritional requirements at minimum cost. And I think nutritional means caloric. Yeah, not necessarily all your vitamins. And I mean, I'm living on the food pyramid.

37:36 Yeah, it's a very similar to toy problem, right? So it's going to be relatively simple. And any optimization problem that will probably go into piombo is going to have either the word minimize or maximize, right. So we're trying to meet certain constraints, these caloric requirements while minimizing cost, although I am really sorry to cut you off, but it does, say, and the amount of vitamins and minerals, fat, sodium and cholesterol, so it's not just calories, so it's a little more nuanced. Okay. All right. Okay. Yeah. So what they do is they set up the mathematical formulation outside of code first, which is how you would do any good linear programming. And so you have a couple sets, right? You have a set of foods and a set of nutrients. And then they have a whole bunch of parameters that need to really read I guess, but like the cost per serving of a given food, the amount of nutrient j and food I said a sub ij. And then you got minimum level of nutrients, right? Like how much sodium, how much fat and so on? Yeah, yep. The amount of the food, I guess, mass or volume? And then how much you can actually consume? See, it was the god, this is great. The number of servings of food to consume. So how much are you eating of any given food? I guess? And then, so here's the meat and potatoes of any good LP, you're going to minimize the cost of the food. So minimizing the sum of four, I have the cost times how much you eat of different foods, right? So is the different foods and it's right, how much you eat of it times the cost of it. Right? So if you're eating $5 milkshakes, and you two of them, right, and you spent 10 bucks, right? We're trying to minimize that cost. Yeah. And you've gotten however much goodness out of that. Yeah. But you're trying to minimize the price. So that would be 10. Your contribution there. Hmm. Okay, good. So then, but now that a frame this, I don't know, this is a little abstract for the audience. But you can think of a lot of these problems and like a multi dimensional framework, if you just have x and y axes and going up in y, and to the right, if you will, an X is both the direction you want to go. Well, the optimal spot of those two constraints is the top right corner. Right. So I hope that that made sense. But yeah, so for the constraints, you're going to limit the nutrient consumption for each one. So you have like a less than set up, you got to limit the amount of food consumed. Like you can't just eat like 100 cheeseburgers ago. We're good. Yeah, we're good. Right. And then you have a max amount of food that gets your stomach can hold that they they have it here right so you can only eat so much of the

40:00 various foods less than or equal to the maximum that you can eat. And then there's also, and this is important, as you'll see, this will get forgotten a lot, because it's so stupid. But you have to have a lower bound with optimization problems, right? So they, the amount of food you eat has to be greater than or equal to zero, right? Because if you don't have that in there, you know, they go infinite negative food, and you're great, right? It's free, you can eat negative milkshakes, right? So exactly get paid to eat it. So that's sort of the the LP setup that they have on this site. And then they go into the actual pile of formulation, where they produce this, they import it, and then you'll see if someone were to look at this link in the show notes today, they define it as an abstract model, you can do a concrete modern abstract model, I'm actually not embarrassing. My, my thesis was concrete, I'm not super informed on what the difference is between those. But we can move along, I suppose. And then they just in their code, they you we define those things, we had the set of food, right, that was F. And so they're going to have, there's an object in piombo, called model, right? So model dot F, is a set of a set of equal to a set. And model dot n, right? Is the nutrients sets and all that and equals a set. Right? Those are just now those are objects in palmos framework in Python, that now just exist for the purpose of these optimization problems. I've been talking a lot want to run with this? No, no, no, no, go ahead. Like you know this better than it is. I mean, we're getting close to the end, that's actually not a whole lot more to it. Yeah. And then we'll get to the fun part at the end. So then they have to define the cost of each food. Right. And this is, as a small aside, this was great about doing this in, in Python, is that you? Can we all know how well Python works with data, right? So half of my thesis code was just taking the real world electrical grid data that we had, and getting it shaped for use, right. So they do something similar here, where they are looking at the data they have, and feeding it in for each food, right? And then you got to keep track of how much of this stuff you're eating. And they have some more code in there, as you like, you've got this params object, you say the parameters come out of this food set, or the nutrition set, the nutrient set, and then here's these are positive reals, or these are non negative reals, or these are integers, they can go up to infinity or whatever, right? Yep, man, thanks for bringing that up. So yeah, so you kind of just lay that I really think it's pretty straightforward. It's got these are the constraints. Yep. And you have these bam. And now now the model, from a mathematical perspective understands what those are. Right. And then, though, the exciting part is they get to where they define the objective function, which as we described is how much is the food cost times how much of that food you eat for a given food, and then minimizing that, so they set that up. And then the same constraints that we discussed a couple minutes ago about, again, the lower bound not going below zero, the nutrient consumption for each food, they set those constraints again, in this, their functions that they set up, and then pass these you will usually in pauma, your write the function just as you would essentially any other Python function, passing it, some of the elements of your model. And then you'll, once you have that function written, you will then pass that to a model dot, whatever you want to name it. And the function contains the constraint. And now passing that to the model dot whatever your name is, will give that piombo object, the inherent mathematical rules of said constraint. Yeah, it's pretty neat. I guess the last bit is there's also a data file, which looks a little bit like yamo. I don't think it's the ML at all, but it looks like that's kind of the visualization is okay, we have cheeseburgers, ham sandwiches, fish sandwiches, chicken sandwiches, sausage biscuits, you're gonna get some serious caloric addict format. And then you know, like how much you're allowed to eat, how much protein you need, how much carbohydrates, and then it lays out like the ingredients. For each one of those, you just define this data file that says the parameter f has this options, the premise in has these options, and so on. Right? So, yep, put those two things together. And you say panormo, solve. Give it a solver, give it the Python code and the data file that has all these parameters. Yes. And it comes up with a beautiful solution. In a actually, I think, an actual yamo file for the output. Yep. mF. So here's the funny part. So how should we like I'm looking to get a little healthier, but also save some money. So what do I do? Yeah, so well, I got some great news for you, my friend for only $15 a day. If you eat for cheeseburgers. Only five french fries. One fish sandwich. Oh, five sorry. Oh, yeah. five servings, french fries, servings of french fries. Definitely one fish sandwich and four milks. You're good. Boom. Yes, yes. Oh, the only thing that would make me happier is if there was like ice cream, shake or

45:00 To in there,

45:02 what you got to do is you have to be sitting there eating that. And just let people that walk by just tell them that your optimal, exactly. This. I've solved it I was solved the nutritional from Yes, I'll include this problem in the show notes. It's, it's pretty interesting. It went really quick and took 9.7 milliseconds to run this. So that's pretty quick, the best. And I mean, I can tell you we had time parameters in my thesis, and we're talking a pretty robust electrical system and some pretty high, high level mathematics to account for all of the three phase AC power flow constraints and everything they're in for from the electro engineering perspective. Yeah. And I did all of it on a fairly middle of the road like 2015 MacBook Pro, and it would knock it out in 20 seconds. Maybe? Yeah, that's incredible. I thought, well, maybe I'll come back to this tomorrow. No, I didn't know.

45:52 Yeah, yeah. tell people is gonna take really long I'll take the rest of the day. Oh, darn it, it's done already. Yeah, that's the nice thing about it is when you structure it's so abstract. It's hard to talk about, like, podcast, I suppose. But when you structure the mathematics, right, letting the solver work, that the solution is computationally, I suppose not that intensive, I guess I would say. Yeah. As opposed to trying to enumerate the best solution. Right. Yeah. Yeah, the best the computational savings. Exactly. You're taking intelligent way to get optimally as opposed to trying to do something, and that would put the sun would burn out before you finish. Right. Right. Well, and it's, it's a solver, right? It doesn't just like try every possible thing. It has algorithms and stuff. And it's beautiful. Yeah. And the individuals that write the solvers, and they're the mad scientists, right, that they are able to, you know, the solvers that actually blow my mind are the stochastic ones. I took some Stokes classes, and it was just one of those like, okay, I don't really understand I barely touched on that I wasn't very much on the statistical side. But I did work with some people in my math experience around those. And it's like, here's a problem that will take seven days to solve. Or we can do this little magic and get basically the same answer and about half a second, like, wait a minute, how did that even how does it even possible, like, what are these things doing? Well, I mean, that kind of comes back to what I said, I got a little naive with so my education at times. But I want to say that in one of our first coding classes, we set up something like, like a traveling salesman problem. And I'm sitting there going, I got a core i seven in here. And so knock this out, I started letting it go. And just to prove the point that professors like literally, a, because we're doing it like brute force, basically, he's like, the sun will die before your computer will finish this problem. Yeah, you know, and then we structure it smartly and piombo. And it takes a couple of milliseconds. Yeah, it's insane. That's so insane. You also start to appreciate like factorial and stuff, right?

47:58 What do you mean that heat death of the universe before the start is no good. All right. Well, I think that gives people a sense, I mean, honestly, I don't recommend the diet. But it gives people a sense of the type of problems and the way you set them up. And it's a pretty clear understanding the problem. And then a simple bit of code, like the Python code that actually does the smarts, right, the cost and the, the limits or the constraints, but it's probably like six or seven lines of code. It's not a lot. Now, it's very straightforward. The actual, again, coming back to my thesis, I kind of pulled up with something like 600 lines of code. And I want to say two thirds of that was just prepping the data. Right. And then the actual piombo work was Yeah, exactly. Yeah. Maybe of that remaining third half of it. And then the last part of that third was like shaping the output to be intelligible. Right? The piombo itself is pretty clean. Right? Wow. Okay. Yeah, it definitely looks interesting. It looks very like it solves many different types of classes of problems, right, like linear programming versus non linear programming versus stochastic programming. And then those solve each many interesting real world problems, right. So this is broadly applicable, I think, yeah. And then I'm one of those guys. It's like, every problem is a network problem, right? And you can feed those to this. And then I view the world as either network problems or assignment problems. And assignment kind of ties back into some of my work for the government, which is do we have the right people where they need to be? And you can throw that at this? Yeah. Are you a fan of graph theory? Yes. Yeah, I'm too. I love that part. All right. Let me add, I think that's probably a good place to sort of wrap up our general conversation. I'll ask you the two questions anything else we should add to the general conversation before we wrap it up? I gotta just thank professors, Alderson and Carlyle. I mean, again, kid from the country didn't know what's going on in life and kind of stumbled into this curriculum that has completely changed my life. And they have always joked I'm the dumb smart kid that smart enough to get into the advanced stuff and then struggle the whole time. And yeah, exactly. I don't belong here, but somehow they let me in by

50:00 Yeah, that's cool. Yeah, that happened to me the nuclear power curriculum and happened to me here. It's a I'm forever indebted to those two gentlemen. So just thanks to them, but somehow that led to the chance to throw out here. Yeah, absolutely. Alright. So before I let you out of here, it's been really interesting. But let me ask you the final two questions, and I have a twist on the second one, because I want to throw out something in addition, while we're talking, I want to hear your thoughts on. Okay. I'm gonna write some code. What editor would use either Jupiter notebooks or Sublime Text? Jupiter or Jupiter lab? Ooh, now you're getting beyond my head. Have you made the transition over to Jupiter lab? are you sticking with the traditional? I don't think I have I'm probably stuck in the past. Yeah, it did a pretty similar, pretty similar. All right, good ones. And then notable pi package piombo? Probably the reason I'm here. Right? So yeah, awesome. That's really cool. That's really cool. I put I want to give a shout out to one because I think this is actually going to be pretty interesting. I haven't talked about how to talk Python I have on Python bytes. Do you see that link? Yeah, click open that link. And then let me describe this to the people and then you give me your thoughts. There's a cool graphics, so you don't have to like there's like an animated GIF didn't have to be to a lot of times, what we do is we do math and optimization problems, like we're talking about here. In in code in the code looks a little bit like theoretical math, but not really like theoretical math. But it would be really nice if you could have like the lawtech fancy published, like math book representation of the steps that you're doing. So there's a really cool project called hand calcs. Have you heard of this? No, I have not. But so I wrote my thesis in latech. Because there was so much of that fancy math of the actual written math, right for all my constraints. Yeah. And learning latech was a challenge, especially when I'm trying to wrap my mind around my actual thesis work. So seeing what I'm seeing here, and the fact that it's in Python, I'm jealous. I'm jealous right now. Yeah, just scroll through some of the pictures here. And I'll put it in the show notes as well. Yeah. So what you can do is you can write out like statements and equations in Python. And then you can say, render with as Hancock, you say, render the what I would have done like step by step sequence, I would have had to do to work out that calculation. Right. So you could say like, x equals negative b plus square root of b squared minus four a c divided by two, like quadratic. And it'll actually, if it knows what the values of those are, it'll write out the steps of solving that equation, like, bit by bit by bit as you would in like math class. But in Jupiter notebooks. Yeah, this is super cool. Isn't this neat? I thought like, given what you're talking about, like this. This is a good thing to pair it with. Oh, yeah. I mean, this would have would have saved a lot of time.

52:55 What am I done with my life? This is pretty new. I believe this is from Connor faster. And I'm really impressed with this project. This is cool. That's super, super cool. Because I mean, for me, it was either try to use the, in my opinion, atrocious, mathtype plugin and word which Yeah, not happening, or right in the latech. And this would have been more fun. That would have been to stick with one. Yeah. latech is fine, right? Like it all the math books and all the math papers and physics, I suppose as well, like almost all of them are done in that right. But the thing is, now you've got the data in two places. And if you change one, but you forget to change the other. Oh, no. It's like this just takes your Python code and like turns it into symbolic math. It's awesome. And this is super cool. Nice. All right. Well, let's leave it with Hancock's in a final call to action. And people want to get started with these types of problems. And like using libraries like this, what do you say, Oh, you want to use PI amo? If you're listening this podcast, you're probably familiar with some of those classic computer science problems. I'd say that pip install pi amo and try to structure on this problem is in that system. And my other, I guess I have two calls to actions. I'm cheating. Go for it. The other one I'll say is, from an analyst perspective, kind of bringing it full circle to Jacqueline and Emily, I get looked at at work like I'm a sorcerer, because it's my Python skills and listen to some of your guests like I'm not right, but your calls to action, often reach out saying hey, you know, maybe you're that person in a job. And you have this one Excel task that you do all the time. Right, you can automate that? Well, I'm kind of that guy in a way where Yeah, the calls to action that you've sent out. Again, I'm that person who has been automating things. There was one example where we're literally had people going through surveys by hand. So this is surveys were like, We asked our sailors, how do you feel about ABC and D? And they used to go through them by hand and I was like, I couldn't be better. Right? And so just like this can't be the best way there Right. And so we have the data digitally and I and I'm not even an NLP Not to be confused. Normally.

55:00 programming, but I'm not a natural language processing guy. But I installed some packages and was able to try to get sentiment out of surveys, right. And so that's cool. I just say that the power of this language and can help at all levels, and I'm at a fairly high level of government. It's incredible what it does for us. So the call to action, I suppose I'm rambling a little bit is, if you are that guy out there, take it from another one of that guy, that it really does work. Yeah, yeah, I think it's great. And you're in one of these positions, where you're a little bit on the boundary of a lot of people who need answers, they have a lot of data, but they can't answer the question themselves through code or programming or anything along those lines. And so it's like right there for you to just take that little step. And come across as a magician, like, I do like to say that developers, data scientists, people who can write code, we really are, in some sense, the wizards or magicians of the modern era, right? You think about an idea, you sort of do the incantation, and then out of just energy in your thought, comes a thing that can have huge impact. And those don't have to be Oh, I created some huge, like, I created Airbnb or whatever it could be. There are people that can now focus on stuff that humans are good at, and not just typing in moving stuff around from one excel sheet to the other, to copy it over to PowerPoint to show it to the general. Yep, absolutely. I have so many examples, I can give you one more. But we have this huge database of what civilian skills people have in the Navy Reserve, which is a unique thing of us because we have our reservists have their military life to civilian life. And facets of their civilian life might be applicable skill sets that we could employ in a military context. And whoever designed the system to capture this only set up free text entry. So imagine, if you have

56:50 20,000 people do free text entry, what they're capable of, right? You're like, could I have just gotten a combo box?

57:00 Exactly. But or a radio button list or something? Some kind of drop down menu, maybe some cascading drop down menus, right. But so I inherited that database. And it was sort of sort of one of those, can you make anything of this? And right at the same time, a pretty high level individual was coming to us saying, hey, do you have anyone with civilian skills to do this? And I just wrote the world's most basic query. I was like, Yeah, we got we got seven. Here they are. Right? Yeah, that's awesome. And you would have thought I'd like conjured a spell. Right. And yeah.

57:33 So here's why I made that source for common beginning of this. It really is incredible what you can do. It absolutely is. And it's within everyone's reach. I think that just takes a little little bit of practice. A little bit of trying it out. Yeah. All right, Clark, thank you so much for being here. It's been a lot of fun to talk about all these problems and cool work. And thanks for helping us all live a little healthier lives getting our diet figured out for cheeseburgers, five servings of fries, a fish sandwich before milks, your set.

58:01 Go live forever, optimally. Alright, good to chat with you.

58:05 Alright, thanks, Michael. Yeah, bye bye.

58:08 This has been another episode of talk Python to me. Our guests on this episode was Clark Petri. And it's been brought to you by us over at talk Python training and our friends at linode. Simplify your infrastructure and cut your cob bills in half with linode. Linux virtual machines develop, deploy and scale your modern applications faster and easier. Visit talk Python FM slash linode. And click the Create free account button to get started. Want to level up your Python. If you're just getting started, try my Python jumpstart by building 10 apps course. Or if you're looking for something more advanced, check out our new async course the digs into all the different types of async programming you can do in Python. And of course, if you're interested in more than one of these, be sure to check out our everything bundle. It's like a subscription that never expires. Be sure to subscribe to the show, open your favorite pod catcher and search for Python. We should be right at the top. You can also find the iTunes feed at slash iTunes. The Google Play feed is slash play in the direct RSS feed at slash RSS on talk python.fm. This is your host Michael Kennedy. Thanks so much for listening. I really appreciate it. Now get out there and write some Python code

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon