Latest / Talk Python To Me / #291: Operational Resilience with Pyomo
Transcript
- 0:00Do you have a scientific system that needs optimization or solving?
- 0:03Our guest on this episode, Clark Petrie, is here to tell us all about Pyomo.
- 0:07This is a library that can solve all sorts of cool problems,
- 0:10linear programming, nonlinear equations, and many other things that you can throw at it.
- 0:14We're going to solve a really fun diet problem.
- 0:16What is the most nutritious meal that you can eat for the least amount of money?
- 0:20The answer might surprise you a little bit. It's going to be a lot of fun.
- 0:23So listen in to hear about how Clark has used Pyomo to do his work
- 0:27and how you might use it in yours.
- 0:29This is Talk Python To Me, episode 291, recorded October 1st, 2020.
- 0:34Welcome to Talk Python To Me, a weekly podcast on Python,
- 0:50the language, the libraries, the ecosystem, and the personalities.
- 0:52This is your host, Michael Kennedy.
- 0:54Follow me on Twitter where I'm @mkennedy,
- 0:57and keep up with the show and listen to past episodes at talkpython.fm
- 1:00and follow the show on Twitter via at Talk Python.
- 1:03This episode is brought to you by Linode and Talk Python Training.
- 1:07Please check out the offers during their segments.
- 1:09It really helps support the show.
- 1:11Hey everyone, two quick announcements before we jump into the show.
- 1:14Number one, I really appreciate everything that many of you are doing to support us here at Talk Python
- 1:19and make it possible for this to be my full-time job.
- 1:22Our primary means of support is through the courses over at Talk Python Training,
- 1:26and I've been thinking about how I can offer you something special in return.
- 1:29What I've come up with is something I'm calling Talk Python To Me Pro Edition.
- 1:34It's like regular Talk Python, but it comes with two perks.
- 1:37It is ad-free so you can listen without any interruptions,
- 1:40and you'll have the entire history going back five years to episode zero in your podcast player.
- 1:45Talk Python To Me Pro is available exclusively to listeners who have an everything bundle over at Talk Python Training.
- 1:51If this sounds like something you want, learn more at talkpython.fm/pro.
- 1:56And if you already have a course bundle, just visit that link for details on how to add the Pro Edition to your podcast player.
- 2:01Announcement number two, somewhat related to Talk Python Pro,
- 2:05Black Friday is just around the corner if you're listening to this episode right when it comes out.
- 2:09We'll be offering major discounts on our brand new FastAPI course
- 2:13and on our everything course bundle over at Talk Python Training for just four days.
- 2:18So visit talkpython.fm/Black Friday to get notified when the deals go live.
- 2:23Thanks so much for your support.
- 2:25Even if you're just listening, it really means a lot.
- 2:27Thank you.
- 2:28Now, let's optimize some things with Python.
- 2:31Clark, welcome to Talk Python To Me.
- 2:33All right.
- 2:34Thank you, Michael.
- 2:34I'm happy to be here.
- 2:35Yeah, I'm happy to have you here.
- 2:36And we're going to talk about operational resilience and using a package called Pyomo,
- 2:41which is about solving all these constraint problems,
- 2:44which brings me back to my math roots, right?
- 2:48Like I didn't do that much applied math,
- 2:50but I definitely studied a ton of math before I got deep into programming.
- 2:53So it'll be a fun journey, I think.
- 2:55Happy to have you.
- 2:55Yeah, this is a lot of fun for me.
- 2:57I've been a fan of the show for a while,
- 2:58and it's kind of surreal to be sitting here talking to you right now.
- 3:02So this is exciting and fun,
- 3:03and I'm happy to spread the joy of Pyomo to the audience.
- 3:06Yeah, and honestly, I had not heard of Pyomo.
- 3:08I obviously know about some of these like solver type systems and the general concept,
- 3:13but I've never used Pyomo and it looks really cool.
- 3:15We have a really fun and slightly comedic,
- 3:19but honestly serious example to go through as well to give people a sense of like the kinds of problems we're solving.
- 3:24But, you know, that's not where we start the show, right?
- 3:27We start with your story.
- 3:28So let's start there.
- 3:29How did you get into programming and Python?
- 3:30I mean, I took a really roundabout way to get there.
- 3:33Just for, I guess, audience context, I was born in 81 and grew up in rural Northern California,
- 3:39kind of one of the few tech nerds in a one-stop-light town.
- 3:42I mean, there was literally a girl that rode a horse to school.
- 3:44I'm not even joking about that.
- 3:45No way.
- 3:46That's crazy.
- 3:47Yeah.
- 3:47We had these like ag fields out back,
- 3:49and she would sometimes ride her horse to school and just put the horse out to pasture during the day.
- 3:53That's actually really cool.
- 3:54It was neat for her.
- 3:55I was not into that, but like, especially looking back now, I can go, that's pretty legit.
- 4:00Yeah.
- 4:01But, you know, like I said, I was one of the few tech nerd kids, and I remember the early days of AOL,
- 4:05and I was actually making money as like a sophomore making web pages for local businesses.
- 4:11Okay.
- 4:11Yeah.
- 4:12I guess the HTML that I did all by hand back then,
- 4:15you could say it was my first experience programming, so to speak.
- 4:17I did a little bit of IRC bot coding.
- 4:20I loved trying to make what we now think of as like a chat bot,
- 4:24but I'd had some foresight.
- 4:25I could tell there was a future in that, but it was just for me, it was a toy, and I love that stuff.
- 4:31But it was just me and a single mom predominantly who, despite her best efforts,
- 4:36didn't really know how to guide me to college.
- 4:37So I kind of stumbled into joining the military, specifically the Navy, right after high school in 99.
- 4:42Fast forward to actually get to answering your question.
- 4:45They cultivated my potential.
- 4:48I eventually got commissioned as an officer, and in 2015, I got sent to the Naval Postgraduate School
- 4:53for the Operations Research Curriculum, which...
- 4:55That sounds really cool.
- 4:56I often will colloquially...
- 4:58Yeah, it was a great opportunity.
- 5:00I mean, I got paid to go to grad school, so I can't...
- 5:01I'm like the luckiest guy around, which for someone that hasn't heard of OR,
- 5:06a lot of us will just kind of cheat and just call it applied mathematics,
- 5:09compared to...
- 5:10I hope I'm not offending any actual math masters out there.
- 5:14But from looking at the curriculum, you know, we just kind of drop a few math classes,
- 5:18add in a few programming classes, which, to answer your question, in the first quarter,
- 5:21we took a Python course.
- 5:23And I just...
- 5:23I kind of fell in love and quickly realized that was the main technical tool I wanted to
- 5:31cultivate for my time in school, and also what I wanted to really use in whatever thesis
- 5:36I ultimately ended up doing.
- 5:37And here we are now.
- 5:39Yeah, here you are.
- 5:40You've done your thesis with Pyomo and Python, and we're going to talk about it.
- 5:44That'd be great.
- 5:44Yeah.
- 5:45So it's never too late to learn to code.
- 5:46I mean, heck, I was...
- 5:47Yeah.
- 5:47...35.
- 5:48Yeah.
- 5:49And when I started that, so...
- 5:51Well, I wasn't quite that far along, but I hear a lot of stories from people like,
- 5:54oh, I started that when I was four.
- 5:55Like, as soon as I could sort of kind of read, I was on the computer and whatnot.
- 5:59And for me, it wasn't that way at all.
- 6:02It was basically grad school, almost grad school, senior year of college, doing research projects,
- 6:07going to actually need some programming skills to start answering these questions.
- 6:11But once I got into it, it was like, why have I been studying this other stuff?
- 6:16This is way more fun.
- 6:17How do I do more of this?
- 6:18And less of what, I'm actually getting my degree in.
- 6:20That was a bit of a problem, but it worked out in the end, I suppose.
- 6:22Yeah.
- 6:23Yeah.
- 6:23I did similar stuff where I kind of juggled around electives to take more programming classes
- 6:28while I was there because I was enjoying it so much.
- 6:30I kind of put off other pain until later, I guess you could say.
- 6:35Exactly.
- 6:35So what is operations research?
- 6:38Like, what kind of problems are being solved there?
- 6:41Give people a sense of what that means.
- 6:42So from the military perspective in particular, a lot of it is logistics and optimization.
- 6:47So in that curriculum, there's kind of three main tracks people tend to fall down.
- 6:51One is the optimization track.
- 6:53You could say that's where I went.
- 6:54Another is more of a just data analysis track, a lot of regression analysis.
- 7:00And the third would be simulations.
- 7:03And I guess you could say just trying to drive answers through some kind of simulation theory.
- 7:08So within operations research, we're looking to find the best way to go about doing something.
- 7:14So some of those classic computer science problems exist in that domain, I'd say.
- 7:17You know, the traveling salesman problem is an early one.
- 7:20Right.
- 7:21And it's about doing that at scale for...
- 7:23The Euler Bridge problem.
- 7:25Yep.
- 7:25That one.
- 7:26That seven bridges.
- 7:27City.
- 7:27I forgot the name of the city.
- 7:28Yeah.
- 7:28You know, we go through some of the classic use cases during World War II with like...
- 7:32God, like...
- 7:35I don't know.
- 7:35It might have been post-World War II, I want to say.
- 7:36But like looking at the Soviet railway system and how...
- 7:40What's the minimum cut, right?
- 7:41To essentially disable their railway system if they were to invade Europe.
- 7:46Right.
- 7:46And it's a lot of work in that domain.
- 7:49Yeah.
- 7:49Okay.
- 7:50Pretty interesting.
- 7:51And I'm still looking forward to the example we're going to get to.
- 7:54Yeah, I'm so goofy.
- 7:56And contrast it with the seriousness of these things.
- 7:58But how about day-to-day?
- 8:00Like, what are you doing now?
- 8:02So right now, I'm a senior officer working in the Pentagon as a data analyst.
- 8:06Let me just really quick.
- 8:08I got to get the obligatory.
- 8:10The views and opinions expressed here are mine and mine alone.
- 8:13They do not represent the U.S. government, the Department of Defense, or the U.S. Navy.
- 8:17So there we go.
- 8:17I said it.
- 8:18We're safe.
- 8:19This is the world of Piomo, according to Clark, not the U.S.
- 8:23Okay, got it.
- 8:24Yeah, got it.
- 8:25So basically, I work for a three-star admiral, which is pretty darn senior.
- 8:28And he is in charge of the entire Navy Reserve.
- 8:31So for kind of civilian context, you could think of that as a multi-billion dollar company with 60,000 people.
- 8:37Yeah.
- 8:37Wow, okay.
- 8:38And he's the CEO, if you will.
- 8:39And at the Pentagon level, and we have, you know, it's the military, so everything's tiered.
- 8:43It's very vertical.
- 8:44And I'm one of his two data guys, basically.
- 8:47And we have one never-ending project, which is we're always analyzing and forecasting our personnel strength, which is a multivariate problem in and of itself.
- 8:57We 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.
- 9:05So we get folk that are coming straight into the Navy Reserve, those that are leaving active duty, and we have to try to plan out how many people we're going to have, and do we have the right types of people for all of our different missions across the future years defense program, which is sort of the budgetary outlook.
- 9:20That's our main job.
- 9:21But 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.
- 9:32COVID was a big example of that.
- 9:34It's funny.
- 9:35You 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?
- 9:42Yeah.
- 9:42You got to tell us this.
- 9:43So, yeah.
- 9:45So it was me and my counterpart who 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.
- 9:58So how many do we have, and if we pull them to go to New York, are we pulling them from a hospital in another hot spot in their civilian life because they're a reservist?
- 10:06And so that's answering questions like that as a recent example, you could say, is what I do.
- 10:11Okay.
- 10:11Yeah.
- 10:12Two things I want to talk about.
- 10:13One is we saw the nightmare that was the cruise ship industry, right?
- 10:18Yes.
- 10:19And I think there's still people around the world who are still stuck on these cruise ships, right?
- 10:25Like not cruisers, right?
- 10:27They were taken and put somewhere.
- 10:29I remember, like, I guess it varied where you were, but people who worked on the cruise ships.
- 10:33I think there's still a ton of them stuck there.
- 10:34And that's just insane.
- 10:36And yet, I used to live in Coronado, California, a little island outside of San Diego for a little bit.
- 10:42And there was two of the main aircraft carrier station there.
- 10:46I know that pier very, very well.
- 10:48It's a beautiful place.
- 10:50But the reason I bring that up is literally the traffic would change.
- 10:55The traffic patterns would change how much traffic there was and whether or not the aircraft carriers were home or they were gone.
- 11:01Because there are so many, there's like 5,000 people on an aircraft carrier, something like that.
- 11:06Yeah.
- 11:06If the, so this is, you're getting really into my wheelhouse.
- 11:09My first 10 years as an officer, I was one of the nuclear engineers for aircraft carrier reactor plants.
- 11:15Oh, wow.
- 11:15Okay.
- 11:15Which is why I had the technical aptitude to do the ops research program for like eligibility.
- 11:20And yeah, if the carrier has the air wing embarked, you're looking at 5,000 or 6,000 people.
- 11:25Yeah.
- 11:26And when the air wing, all the planes and everything associated there is not there, you're talking about 3,000.
- 11:30Either way, whether a carrier is important or not changes the quality of life for a commuter for sure.
- 11:35Yeah.
- 11:36I mean, it would change.
- 11:37It would dramatically change.
- 11:38So why do I bring that up?
- 11:39Well, 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.
- 11:44And that's a huge challenge.
- 11:46I mean, how did you all deal with that?
- 11:47What was even the outcome?
- 11:48I know that there was a commander of one of those carriers that was lost his job basically.
- 11:55Because he spoke out about like, this is a serious problem.
- 11:58He was very upset and kind of went above rank or pulled rank or something like that, right?
- 12:02Yeah.
- 12:03I mean, I can't really like, I wasn't there, right?
- 12:05But I can only report what I kind of saw in the news.
- 12:07I don't have much insider information, if you will.
- 12:10But we take rank and reporting at the chain very seriously.
- 12:15And I feel for that gentleman.
- 12:17My job before this was as a commanding officer.
- 12:19And he was facing incredibly tough decisions.
- 12:22And it's just, the whole thing's unfortunate.
- 12:24But as far as what you're getting at with like the cruise ships that are dealing with such rampant COVID problems,
- 12:30yeah, that's really tough.
- 12:31Because on a ship, where are you going to go, right?
- 12:33Yeah.
- 12:33But one way that I think we haven't been as decimated is the wrong word,
- 12:39but maybe negatively impacted with our ships,
- 12:42partially because generally, most of the sailors on ships,
- 12:46and the average age of a Navy sailor is like 21 years old.
- 12:50We're talking pretty healthy people.
- 12:52Which is probably not the same age as the average cruiser.
- 12:55I do love a good time on a cruise ship.
- 12:57But if I need to feel young, I can also do that, right?
- 13:00Yeah, right.
- 13:01So I think there's probably some degree of extra resilience, I would think,
- 13:06amongst our personnel on ships that has probably helped mitigate the problem.
- 13:10And I'll tell you this.
- 13:11We have also had, we're the military, right?
- 13:13And we need to be ready.
- 13:15The restrictions in place on us for doing things that would possibly increase your risk profile are pretty strict.
- 13:23Yeah.
- 13:23Like, 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.
- 13:31But like, if I were to go, I'll give you an example.
- 13:33One of my big personal hobbies outside of nerd stuff is I'm a big Brazilian jujitsu guy, which is really mean wrestling, if you will.
- 13:41Yeah.
- 13:42It's cool, but it's also kind of up close with other people.
- 13:44Yeah.
- 13:45There's no way to socially distance when you're rolling around with people, right?
- 13:48And if I were to go do that and get COVID, technically speaking, I would have disobeyed like a direct order.
- 13:54Right.
- 13:55You know, and I'm senior enough that I probably wouldn't get like in real trouble, if you will.
- 13:59But I know, like, I'm a good boy.
- 14:01So.
- 14:01Yeah.
- 14:02The restrictions in place like that are probably protecting our people more.
- 14:05Sure.
- 14:06Well, 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.
- 14:12Whereas you can say, you know what?
- 14:14We're not going to go into port and you guys don't go anywhere.
- 14:16You stay here.
- 14:17Which is a different kind of experience, I guess.
- 14:20Yeah.
- 14:20No more pulling into Hong Kong and going wild, I suppose.
- 14:24It's probably restricted liberty when the ships do pull in.
- 14:27Yeah, exactly.
- 14:27But I'm a desk jockey now.
- 14:29My ship going days are way behind me.
- 14:30This portion of Talk Python To Me is sponsored by Linode.
- 14:35Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 14:40Develop, deploy, and scale your modern applications faster and easier.
- 14:44Whether you're developing a personal project or managing large workloads,
- 14:47you deserve simple, affordable, and accessible cloud computing solutions.
- 14:51As listeners of Talk Python To Me, you'll get a $100 free credit.
- 14:55You can find all the details at talkpython.fm/Linode.
- 14:59Linode has data centers around the world with the same simple and consistent pricing, regardless of location.
- 15:05Just choose the data center that's nearest to your users.
- 15:08You'll also receive 24-7, 365 human support with no tiers or handoffs, regardless of your plan size.
- 15:15You can choose shared and dedicated compute instances, or you can use your $100 in credit on S3 compatible object storage,
- 15:22managed Kubernetes clusters, and more.
- 15:25If it runs on Linux, it runs on Linode.
- 15:27Visit talkpython.fm/Linode or click the link in your show notes,
- 15:32then click that create free account button to get started.
- 15:36Got your land legs back.
- 15:37Okay, so let's talk a little bit about, let me just ask you about Python and the government,
- 15:42our programming and the government.
- 15:44I did 10 years of in-person training, and much of that was at places that were like HP or JP Morgan or something like that.
- 15:53But periodically, we teach classes at military places.
- 15:58And they were a little bit different, right?
- 15:59Like I did a class for the people that ran the launch control for NASA.
- 16:04I think they were technically Air Force, but still, that was pretty cool.
- 16:06And someone at Edwards Air Force Base.
- 16:08And I talked about like, oh, yeah, you just pip install this thing.
- 16:11And you get like, look at this amazing package that are like, that's really awesome.
- 16:14We're never, ever going to be able to do that.
- 16:17You can't just install stuff off the internet.
- 16:19So tell us what programming in this world feels like.
- 16:22So that's the tough part, right?
- 16:27Is anyone listening to this show probably knows what Python's capable of.
- 16:31And we're all here because we love it, right?
- 16:33It's a great language.
- 16:34And then there's the government limitations that you just got to.
- 16:38So there's a group in the Pentagon called N81 that doesn't really mean anything.
- 16:42But they're kind of some of our researchers on the Navy side.
- 16:44And a lot of ops research guys and a lot of coders.
- 16:47We do in some cases have standalone machines that are able to touch the outside world.
- 16:52But they're just not plugged into like our broader, just unclassified internet,
- 16:56which is called NMCI for Navy Marine Corps internet.
- 16:59Now, some of those N81 folk allegedly treading a little bit of dangerous water, maybe,
- 17:04maybe found a way to kind of get Python working on their machines, but to try to do work.
- 17:10But again, what you got to a truth, which is, oh, you go, you need some package.
- 17:13You can't just pip install it.
- 17:15Again, allegedly, it might be the case that you have to download the wheel.whl files.
- 17:21Whl, yeah.
- 17:22Yeah, yeah.
- 17:23You have to download the wheel files.
- 17:24I call them wheel files.
- 17:25I don't actually know what the...
- 17:26Yeah, yeah.
- 17:27Yeah.
- 17:27Yeah, you have to download those manually and install them.
- 17:30But of course, if one package needs like subservient packages, you have to like backtrack, right?
- 17:36Until you have what you need to then get Python running.
- 17:39But even if you go through that heartache, you now are facing another conundrum, which is you have Python running, yay, on your government computer, which because we're so big and we try to standardize everything.
- 17:53And for good reason, there's a lot of background processes running to keep machines up to date and to monitor activity and such.
- 18:01A core i5 with 8 gigs of RAM that is, you know, permanently got 80% of that used isn't exactly the like analytical monster you might want.
- 18:12Right, right.
- 18:13And so...
- 18:14And it's trying to decrypt the drive and run the three different virus scanners and then the network monitor.
- 18:20It's like at a permanent 60% CV usage before you touch it, right?
- 18:23Yeah, exactly.
- 18:24You know too well.
- 18:25So that's the hard part is someone like me, I'm always beating the drum.
- 18:30My 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, we'll be so much more efficient.
- 18:39Yeah.
- 18:40And that's one of our limitations.
- 18:41And I understand and get the complexities of that problem.
- 18:44It's not easy.
- 18:45It's not, oh, you just got hired with insert tech company here.
- 18:48Here's your new MacBook.
- 18:49You can't do that with us.
- 18:51Yeah, exactly.
- 18:51But that's sort of the challenge.
- 18:54Now, what's sort of interesting is COVID has changed a lot of that.
- 18:59It's changed it for, I think, for banks and for all sorts of industries that were like, we can't work from home.
- 19:05You can't access this from your home.
- 19:06But you guys are kind of the far end of that spectrum.
- 19:09Well, yes, comma.
- 19:11I'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.
- 19:23Now, that's on my machine.
- 19:24I keep a good delineation.
- 19:26But a lot, the main data sources I tend to work with don't have that anyway.
- 19:30So I've been able to move a lot of my analytical work to my personal computer, which I'm a nerd.
- 19:34It's a good machine, right?
- 19:35So 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.
- 19:52Our people are more effective in a lot of cases, and they're happier?
- 19:56What?
- 19:56You know?
- 19:57Yeah, exactly.
- 19:58Wait a minute.
- 19:59And we have this big fancy building we can go to, but they don't want to go to it anymore.
- 20:03Like, it's, yeah, it's a really interesting paradox.
- 20:05And what's silly about that is, for anyone listening out there that's doing data work, I work in a secure space.
- 20:11So I can't have my cell phone.
- 20:13And I'm not missing it because I want to play a game.
- 20:15I can't have a podcast going.
- 20:17Yeah.
- 20:17I can't have music going, right?
- 20:20And 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 trance going, if you will, in the classic coder.
- 20:29Yeah, just have the distractions, right?
- 20:32Yeah, it helps.
- 20:32So COVID's changed a lot of that for us.
- 20:35And I can just tell, I think, like the whole world at large, we're just a microcosm of it.
- 20:38We're never going to go back to normal, whatever that was.
- 20:41Yeah.
- 20:42We're permanently going to be.
- 20:43So what about, like, things that allow whitelisted packages?
- 20:49To be vetted and then like local PyPI server type of things.
- 20:55Is that something you guys have looked at or maybe you will be looking at?
- 20:59Yeah, there is some of that happening.
- 21:01So government is headed in that direction.
- 21:03The senior people, they get it.
- 21:05I mean, it isn't like they don't know, right?
- 21:07Yeah.
- 21:08And 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.
- 21:18And we're starting to develop some of that.
- 21:20I know some of my counterparts in my office, you know, working for the Admiral of the Navy Reserve, they're helping.
- 21:27They're involved with 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?
- 21:36I'm blanking right now.
- 21:37Like a virtual machine?
- 21:38Yeah, yeah, a virtual machine.
- 21:39I was just blanking.
- 21:40It's basically a virtual environment that you can like remote into.
- 21:43And then you're going to have the full suite of packages.
- 21:46And presumably someone would have white listed all the Python packages you could want, right?
- 21:52So we're trying to get there.
- 21:53It's just, we got to get there while navigating the limitations of our government requirements, which, you know, many of which are in congressional law, right?
- 22:02So it's not like that's an easy thing to change and update.
- 22:04It's not like there's just a picky manager.
- 22:06No, no, no, no, no, no.
- 22:08So that's where we're headed.
- 22:10So another thing, I don't want to go too far down the strad hole, but it is interesting to me.
- 22:14So let me ask another question.
- 22:15So 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.
- 22:33Have you looked at those types of setups or even creating like isolated something like that internally, but then setting up those kinds of servers?
- 22:40There is something like that.
- 22:41And it actually shows you how much in demand it would be.
- 22:43When that initially got set up, I'm blanking on the name.
- 22:45I haven't tried to use it for almost a year.
- 22:47The demand.
- 22:48It was overwhelmed and just killed it.
- 22:50Yeah.
- 22:51Yeah.
- 22:52Demand from people like me was so significant.
- 22:55It just vomited and died.
- 22:57And it was really hard to use.
- 23:00And then the other problem is we don't exactly have the fastest pipe up and down to do work like that.
- 23:06So you're going to be working in a high latency environment oftentimes, which can make the experience more challenging.
- 23:11But there are setups.
- 23:13I know the Air Force has one that's pretty robust.
- 23:15Okay.
- 23:15I think that's kind of ironic given that our ARPANET and DARPA and all that stuff sort of created the internet.
- 23:22Yeah, right.
- 23:23And I know people hear I'm in the Pentagon.
- 23:25They picture some kind of like Jason Bourne control room.
- 23:29Right.
- 23:29And those places exist in the Pentagon.
- 23:31I'm not in it.
- 23:32Yeah.
- 23:33But.
- 23:33Exactly.
- 23:34Yeah.
- 23:34Yeah.
- 23:35Cool.
- 23:35All right.
- 23:35So 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 pot.
- 23:48Like when you say I'm a data scientist or I have a career in data science or data engineering, like that actually can mean a whole bunch of different stuff and really interesting ways to kind of map out that world.
- 23:57You want to talk about that just a little bit?
- 23:58Sure.
- 23:59Yeah.
- 23:59I mean, I have a blog that's for me.
- 24:01I don't.
- 24:01I haven't even done like good SEO on it for that matter.
- 24:05But that episode was 262 with Jacqueline and Emily.
- 24:08You know, they described different kind of fictitious companies.
- 24:11And one of them, when they got to this is a large company, probably a lot of government contracting.
- 24:15Maybe it is government.
- 24:16You know, my ears perk up.
- 24:17Right.
- 24:17Maybe it's Boeing.
- 24:18Maybe it's even the Pentagon.
- 24:19Okay.
- 24:20Right.
- 24:20And then they perfectly describe some of these challenges we just discussed, which is, wow, you don't have access to the tools you want.
- 24:27But then they really go down the analyst role, which is certainly what I consider myself.
- 24:30I'm technically trained.
- 24:32I have technical skills.
- 24:33But especially at my level, they were so eloquent in how they described it.
- 24:39I'm the one who, almost by virtue of my education, when I speak to numbers, it's gospel, if you will.
- 24:47And then that's an important trust, right?
- 24:48My admiral trusts me that I'm right.
- 24:50And I can never betray that.
- 24:52So I'm the one that's kind of in the boardroom, if you will, showing the CEO the charts and breaking down what's what for them, as opposed to the real data engineer in the trenches.
- 25:04Right.
- 25:05Like deploying a machine learning model to production over like a FastAPI implementation, right?
- 25:10Not so much that.
- 25:11No, no, no, not at all.
- 25:12I have done some technical stuff with Python in my current role.
- 25:15And we can talk about that.
- 25:16But I am more of the, and Jacqueline and Emily talk a lot about, I think they say Excel and PowerPoint.
- 25:21I'm like, haha, yeah, that's my life.
- 25:23My PowerPoint skills have become much stronger in the last year of this job than my coding skills.
- 25:30That is the lingua franca of that whole environment, isn't it?
- 25:33Yep, absolutely.
- 25:34I legitimately was joking with my other data buddy, just about what a PowerPoint savant I've become, almost to the point that, like, it's like, oh, you want your slides touched up?
- 25:43Contact Clark.
- 25:44So that's a feather.
- 25:46I remember doing a training course with this group out of the Air Force Academy in Colorado Springs.
- 25:53And, like, one of the pinnacle moments was when we found a way to dynamically generate one of the slides in PowerPoint.
- 26:01It was like, it would pull in data from where all the planes were flying.
- 26:05And it would dynamically, like, in real time or, like, near real time update what would be shown in the PowerPoint.
- 26:11It wasn't, like, enough to have that on a web page.
- 26:13It was like, it needs to generate a slide on live data.
- 26:18Like, why would you do that?
- 26:19Like, it doesn't matter why.
- 26:21It has to do this because this is the world we're in, right?
- 26:24Yep.
- 26:25We are beholding the PowerPoint for sure.
- 26:27You know, it's funny we talk about PowerPoint because Tableau is starting to gain traction.
- 26:31People are realizing the power of a good Tableau dashboard.
- 26:34And that has, if nothing else, the name Tableau, like, is spoken in whispers in the halls of the Pentagon.
- 26:40So, you know, maybe we'll get there eventually.
- 26:43Yeah, that's a bit of a step up.
- 26:44That's a bit of a step up.
- 26:45Yep.
- 26:45But, yeah, anyone who has not listened to episode 262, and I'll link to it, Jacqueline and Emily wrote a,
- 26:50really good book.
- 26:52Like, I'm not even that interested in a data science career for myself.
- 26:55And I'm like, this is like a page turner.
- 26:57This is really, I think they really broke it down well.
- 27:00And it, because people ask me, like, oh, I want to get into data science.
- 27:03What should I do?
- 27:04What should I study?
- 27:05I'm like, that's not enough.
- 27:06I don't know enough to answer your question necessarily, because that means kind of different things.
- 27:10So, I recommend people check that out.
- 27:12It's a good one.
- 27:13Yeah, definitely.
- 27:13I mean, for me, that episode gave me, like, validity.
- 27:16I'm kind of the king of imposter syndrome.
- 27:18And I heard that.
- 27:19I was like, oh, like, they describe a legitimate, valuable role that I'm kind of well-suited to.
- 27:25Sweet.
- 27:26You know?
- 27:27That's awesome.
- 27:27That's all right.
- 27:28Well, because you might compare yourself against, like, the machine learning people deploying
- 27:33machine learning models at Google.
- 27:34You're like, well, I can't do any of that.
- 27:36Like, all of that is foreign to me, right?
- 27:37But that doesn't mean you're not doing valid data science.
- 27:40Like, you're just doing, like, a different slice of it.
- 27:42Yeah, absolutely.
- 27:43And it's important to have someone that can speak to it and translate it into the common
- 27:48vernacular, if you will.
- 27:49And I think that's kind of where I've found myself.
- 27:51Yeah.
- 27:52And hearing them talk about that gave me hope, because whenever I retire from the service in
- 27:56a couple of years, potentially, like, okay, cool.
- 28:00There are roles in the outside world.
- 28:01Some kind of weird military Stockholm syndrome.
- 28:04I know that there are.
- 28:05Yeah.
- 28:06I suspect that a lot of the stuff that you work on, you can't really share or talk about
- 28:10a bunch.
- 28:11And so it doesn't give you that chance to kind of put it side by side with other people.
- 28:15Let's talk about your thesis and this optimization stuff for the Python library, Pyomo.
- 28:21Sure.
- 28:22So you said you did your work at Los Alamos National Labs.
- 28:25Is that right?
- 28:26Yeah.
- 28:26So I can back that up a little bit.
- 28:28Professor David Alderson, who's one of my thesis advisors, he's the head of the postgraduate
- 28:33schools, Center for Infrastructure Defense.
- 28:36I want to make sure.
- 28:38Yeah.
- 28:38Center for Infrastructure Defense.
- 28:40Making sure that the power grid doesn't go down and that the internet stays on and things
- 28:45like that.
- 28:46Yeah, absolutely.
- 28:47It's a power, water.
- 28:49And then that goes two ways, right?
- 28:50From a military context, it's about protecting our stuff in a potential theater of war, whether
- 28:55we're setting up a forward operating base in theater, as we would say, or domestically.
- 29:00But at the same time, if we know how to protect our stuff and are smart on that, we also know
- 29:04how to take out the enemy stuff better.
- 29:06Yeah.
- 29:07And so it works both ways from a military context.
- 29:09So he's the head of that center.
- 29:11And I got hooked up with him mainly because he taught one of the more advanced coding courses
- 29:17I took while I was there.
- 29:18And again, loving the language, coming back to how we started.
- 29:20And he was working in conjunction with researchers at Los Alamos National Labs, which is how I got
- 29:26hooked up with them.
- 29:26Okay.
- 29:27So which was a good opportunity.
- 29:29I got sent out there for several weeks to just be in that environment, learn, and kind
- 29:33of get hands-on with some other data, which I was able to bring back for my thesis, which
- 29:37then Paloma became kind of the cornerstone of it.
- 29:39Yeah.
- 29:39What was your thesis about?
- 29:40Yeah.
- 29:40So it was assessing the operational resilience of electrical distribution systems.
- 29:44Yeah.
- 29:45Okay.
- 29:46At the time, anyway, transmission, you know, think the big power towers that you see when you're
- 29:51in the middle of a highway somewhere that's the transmission lines.
- 29:54Those are really well understood.
- 29:55The white and orange ones that are really high.
- 29:58Yeah.
- 29:58Yeah.
- 29:59Those ones, right?
- 29:59Okay.
- 30:00Yeah.
- 30:00Those are really well understood and modeled as we understood.
- 30:03But distribution, like what's in your neighborhood, what's in your town, wasn't.
- 30:08And obviously, distribution works great.
- 30:09Right.
- 30:10But from our awareness, no one had really built a model using real world data, taking
- 30:16into account all of the mathematics for three phase AC transmission.
- 30:21That's kind of where some of my nuclear engineering background helped because I was cursorily familiar
- 30:27with that stuff.
- 30:28Yeah.
- 30:29I mean, that's basically a power plant as well, right?
- 30:31Yeah.
- 30:31Power plant and all the distribution, right?
- 30:33So I was familiar with concepts like real and reactive power.
- 30:37No one had built a model that took in real world data.
- 30:40And what we could basically do is say, hey, if we take out this electrical pole or that transformer,
- 30:48what will unequivocally happen?
- 30:50Most analysis had been based.
- 30:54It was essentially data analysis and regressions where you look at a disaster that happened,
- 30:58maybe a tornado touchdown in Oklahoma, right?
- 31:00Okay.
- 31:01We know that the tornado did damage here, here, and here.
- 31:04Okay.
- 31:05We understand the results of that.
- 31:06Now we can apply those results and think we'll know what will happen somewhere else.
- 31:10But we built a model that will allow us to unequivocally state what would happen.
- 31:14Yeah.
- 31:14Okay.
- 31:15And so the optimization part of that was working with the distribution system.
- 31:20We kind of made an assumption, if you will, that we want to minimize how much load, real
- 31:26and reactive power load, is lost if you take out a telephone pole or something, right?
- 31:32So in the end, the grid wants to keep power going everywhere the power is being asked for.
- 31:37So what we're trying to do is minimize the amount of power lost when you essentially mess with
- 31:42the network.
- 31:43Right.
- 31:44Okay.
- 31:44I grew up in Kansas City.
- 31:46Tornado Alley is sometime called.
- 31:48We ran experiments like that all the time of what happens if we take out this block of
- 31:54thing or whatever.
- 31:55But yeah, not in that clear sense, right?
- 31:58Like stuff would just get blown over and see the little capacitors, whatever, it's explode,
- 32:03whatever those gray cylindrical things that are on the towers.
- 32:07Yeah.
- 32:08Or the poles.
- 32:08Yeah.
- 32:09All right.
- 32:09So use this library, Pyomo.
- 32:12Tell us about that.
- 32:13Yeah.
- 32:13So what the library does, like we talked about at the beginning, I can't talk to what's
- 32:18happening behind the package.
- 32:19Sure.
- 32:20But it allows us to set up an optimization framework.
- 32:23As a consumer of it.
- 32:24Yeah.
- 32:24Yeah.
- 32:24I'm a consumer, right?
- 32:25So allows us to set up in Python and optimization framework to, I guess, structure these problems.
- 32:32So we're talking about an objective function.
- 32:34It can be a multi-objective function.
- 32:35And then the various constraints to perform linear or nonlinear optimization in whatever
- 32:42capacity you want to.
- 32:43So using everything that we love about Python, right?
- 32:46The relatively straightforward syntax.
- 32:48And then all the tools beyond that, which made it unique.
- 32:52We can set up these problems and then throw a solver at it.
- 32:56Like Cplex is what I used, which to me is a bit of a magic black box, though.
- 33:00We went into some of the mathematics behind that, obviously, like the simplex method and
- 33:03all the Danzig's work back in the 40s.
- 33:06But we throw a simplex at it and then structure in Python how we want our results.
- 33:11And voila.
- 33:12In the case of my thesis, we get a detailed printout, if you will, of what loads stayed up, what went
- 33:19down.
- 33:19And we can analyze that all within a Python framework.
- 33:21Yeah.
- 33:22That's beautiful.
- 33:22To give people a sense of this, let me maybe go through some of the problems that it solves.
- 33:27And then like some examples of using it.
- 33:29Then we'll go through a concrete code example.
- 33:31And that'll bring it together.
- 33:32So looking through their docs, some of the things you can do is linear programming.
- 33:36And I don't know how many people have done linear programming.
- 33:38It's really simple.
- 33:39It's not necessarily easy to compute, but it's not like a complicated thing.
- 33:43But it really, it's incredible the way that that like, this is the exact answer.
- 33:47Like all these constraints.
- 33:48Here's the optimization.
- 33:49I love it because it's simplicity plus power.
- 33:52Yeah.
- 33:53What we always talked about linear programming is guaranteed optimality, right?
- 33:57It's pretty straightforward.
- 33:59You don't have a local minimum or a local maximum.
- 34:02That's not the actual answer, right?
- 34:03Yeah.
- 34:03Yeah, exactly.
- 34:04And in some cases, especially with nonlinear problems, you can get stuck in a local minimum
- 34:09or maximum depending on where you're going.
- 34:10But generally speaking, if you write a greedy heuristic, you'll get a good answer.
- 34:15But is it optimal?
- 34:18Right.
- 34:18And that's the real sticking point that the professor's there because maybe this comes
- 34:23back to kind of that military background, but we often will not settle, especially in a war
- 34:28context, I suppose, for anything that's suboptimal, right?
- 34:32And that guaranteed optimality.
- 34:33And I know an example of FedEx, right?
- 34:36Right.
- 34:36They gobble up a lot of the ops research graduates out of the Naval Postgraduate School
- 34:41because their profit margins hinge on optimality with delivery, right?
- 34:47There's a traveling salesman problem for you, right?
- 34:49Yeah.
- 34:50Yeah.
- 34:51The whole UPS, FedEx delivery stuff, especially with COVID, it's like insane how many of those
- 34:57guys are driving around.
- 34:58So we've got linear programming, quadratic programming, nonlinear programming, what it
- 35:02gets really interesting.
- 35:03Let's see, stochastic stuff, just junctive programming, which I don't know anything about,
- 35:08but differential algebraic equations, equilibriums, all these different types of problems.
- 35:14It can solve those.
- 35:14And then some of the projects using it that they've listed on their site that I thought
- 35:18was interesting is the DISPA set, which is unit commitment and dispatch model focused on
- 35:24balancing and flexibility problems in European power grades.
- 35:28It seems like it comes back to power a lot, honestly.
- 35:30Yeah.
- 35:31I was actually surprised looking through these, seeing how many power problems there were,
- 35:34which I don't know.
- 35:35I would not have expected that, but yay.
- 35:37Yeah.
- 35:38I didn't either, but yeah, that's cool.
- 35:39There's another one, which I don't know how to pronounce.
- 35:42I-D-A-E-S-P-S-A, P-S-E toolkit, which is a open source optimization-based framework for
- 35:49chemical processes, which is pretty cool.
- 35:52MinPower, which is an open source toolkit for students and researchers and power systems.
- 35:56Open energy modeling framework.
- 35:58Like I said, it's a lot of energy in here, which is a open framework for developing energy
- 36:03models that emphasize communication and community involvement.
- 36:07And then OpenAgua, which is a web-based app for modeling water systems for water resource
- 36:12planning and management.
- 36:13So I think that gives people a sense of like some of the types of problems this is being
- 36:17applied to.
- 36:18Yeah.
- 36:18And I know those are kind of, those are obviously complex and real world.
- 36:22I know in a learning context, many of the classic computer science problems, traveling salesman,
- 36:28the knapsack problem.
- 36:29If you're familiar with that or for the audience's essay is basically, I have a bag that can hold
- 36:3420 units of stuff.
- 36:35And I have a hundred units worth of things I want.
- 36:38I would love to try to fit in it.
- 36:40How do I maximize my value by putting in the knapsack?
- 36:42We would structure problems like those in Pyamo while we were learning the package.
- 36:47Right.
- 36:48So some of those classic problems can be solved here.
- 36:50Yeah.
- 36:51Yeah.
- 36:51Cool.
- 36:51All right.
- 36:53So on the Pyamo website, they have this dietary problem.
- 36:56They have a bunch of examples of, here are some examples you said.
- 36:58Do you want to talk us through this?
- 37:00It's a little bit hard to talk about code over the air.
- 37:02So we'll just keep it kind of vague in general, but maybe talk us through this and people go,
- 37:06okay, I see what this does and how I might use it.
- 37:08Yeah.
- 37:09Yeah.
- 37:09This is a great example, especially, I don't want to spoil it, but it gets a funny result.
- 37:13So what this diet problem is trying to do, and this is a classic optimization problem,
- 37:18is you want to select, you have a group of foods and you want to select foods to meet your
- 37:23nutritional requirements at minimum cost.
- 37:26And I think nutritional means caloric.
- 37:29Yeah.
- 37:30Not necessarily all your vitamins.
- 37:32And I'm living on the food pyramid, right?
- 37:34Yeah.
- 37:36Yeah.
- 37:36It's a very simple, it's a toy problem, right?
- 37:38So it's going to be relatively simple.
- 37:40And any optimization problem that'll probably go into Piamo is going to have either the word
- 37:45minimize or maximize, right?
- 37:47So we're trying to meet certain constraints, these caloric requirements while minimizing cost.
- 37:51Although I am reading, sorry to cut you off, but it does say, and the amount of vitamins,
- 37:55minerals, fat, sodium, and cholesterol.
- 37:57So it's not just calories.
- 37:59So it's a little more nuanced.
- 38:00Okay.
- 38:01All right.
- 38:01Okay.
- 38:02Yeah.
- 38:02So what they do is they set up the mathematical formulation outside of code first, which is how you would do any good linear programming.
- 38:09And so you have a couple sets, right?
- 38:11You have a set of foods and a set of nutrients.
- 38:13And then they have a whole bunch of parameters that need to really read, I guess.
- 38:17But like the cost per serving of a given food, the amount of nutrient J and food I.
- 38:22So it's A sub IJ.
- 38:25And then you got minimum level of nutrients.
- 38:27Right.
- 38:28Like how much sodium, how much fat and so on.
- 38:30Yeah.
- 38:30Yep.
- 38:31Yep.
- 38:31The amount of the food, I guess, mass or volume.
- 38:34And then how much you can actually consume.
- 38:36Let's see here.
- 38:37What else have they got?
- 38:38This is great.
- 38:39The number of servings of food to consume.
- 38:43So how much are you eating of any given food, I guess.
- 38:45And then, so here's the meat and potatoes of any good LP.
- 38:48Either you're going to minimize the cost of the food.
- 38:51So you're minimizing the sum of 4i of the cost times how much you eat of different foods.
- 38:57Right.
- 38:57So i is the different foods and it's how much you eat of it times the cost of it.
- 39:01Right.
- 39:02So if you're eating $5 milkshakes and you eat two of them, right, you spent 10 bucks.
- 39:07Right.
- 39:07We're trying to minimize that cost.
- 39:08Yeah.
- 39:09And you've gotten however much goodness out of that.
- 39:12Yeah.
- 39:12But you're trying to minimize the price.
- 39:13So that would be 10 contribution there.
- 39:15Uh-huh.
- 39:15Okay.
- 39:16Go ahead.
- 39:16So then, but now to frame this, I don't know if this is a little abstract for the audience,
- 39:20but you can think of a lot of these problems in like a multidimensional framework.
- 39:24If you just have X and Y axes and going up and Y and to the right, if you will, and X is
- 39:31both the direction you want to go.
- 39:32Well, the optimal spot of those two constraints is the top right corner.
- 39:36Right.
- 39:37So I don't know if that made sense, but yeah.
- 39:39So for the constraints, you're going to limit the nutrient consumption for each one.
- 39:43So you have like a less than set up.
- 39:45You got to limit the amount of food consumed.
- 39:47Like you can't just eat like a hundred cheeseburgers and go, we're good.
- 39:50Yeah.
- 39:51We're good.
- 39:51Right.
- 39:52And then you have a maximum amount of food that I guess your stomach can hold that they
- 39:55have in here.
- 39:56Right.
- 39:57So you can only eat so much of the various foods less than or equal to the maximum amount you
- 40:03can eat.
- 40:03And then there's also, and this is important that you'll see this will get forgotten a lot
- 40:08because it's so stupid, but you have to have a lower bound with optimization problems.
- 40:13Right.
- 40:13So they, the amount of food you eat has to be greater than or equal to zero.
- 40:16Right.
- 40:17Cause if you don't have that in there, it'll be like, Oh, eat infinite negative food and
- 40:21you're great.
- 40:21Right.
- 40:22It's free.
- 40:22You can't eat negative milkshakes.
- 40:24Right.
- 40:24So.
- 40:25Exactly.
- 40:25You get paid to eat it.
- 40:26So that's sort of the LP setup that they have on this site.
- 40:30And then they go into the actual pie on formulation where they were always this, they import it.
- 40:35And then you'll see if someone were to look at this link in the show notes, they, they
- 40:40define it as an abstract model.
- 40:41You can do a concrete model, an abstract model.
- 40:44I'm actually not a little embarrassing.
- 40:46My, my thesis was concrete.
- 40:48I'm not super informed on what the difference is between those, but we can move along, I suppose.
- 40:55And then they just, in their code, they, we define those things.
- 40:59We had the set of food, right?
- 41:00That was F.
- 41:01And so they're going to have, there's an object in Pyamo called model, right?
- 41:05So model.f is a set.
- 41:08They set it equal to a set and model.n is the nutrient set.
- 41:13So model.n equals a set, right?
- 41:14And those are just, now those are objects in Pyamo's framework in Python that now just
- 41:19exist for the purpose of these optimization problems.
- 41:22I've been talking a lot.
- 41:23You want to run with this?
- 41:24I don't know.
- 41:24No, no, go ahead.
- 41:25Like, you know this better than I do.
- 41:26So we're getting close to the end.
- 41:28That's actually not a whole lot more to it.
- 41:29Yeah.
- 41:29And then we're going to get to the fun part at the end.
- 41:31So then they have to define the cost of each food, right?
- 41:33And this is, as a small aside, this was great about doing this in Python is that you can,
- 41:39we all know how well Python works with data, right?
- 41:43So half of my thesis code was just taking the real world electrical grid data that we had
- 41:48and getting it shaped for use, right?
- 41:51So they do something similar here where they are looking at the data they have and feeding it in for each food, right?
- 42:00And then you got to keep track of how much of the stuff you're eating and they have some more code in there.
- 42:05Yeah.
- 42:05So you like, you've got this param object.
- 42:07You say the parameters come out of this, the food set or the nutrition set, the nutrient set.
- 42:13And then here's, these are positive reels or these are non-negative reels or these are integers.
- 42:18They can go up to infinity or whatever, right?
- 42:21Yep.
- 42:21Yeah.
- 42:22Thanks for bringing that up.
- 42:22So yeah.
- 42:23So you kind of just lay that out really.
- 42:24I think it's pretty straightforward.
- 42:25It's good.
- 42:26These are the constraints.
- 42:27Yep.
- 42:27And you have these, bam.
- 42:29And now, now the model from a mathematical perspective understands what those are, right?
- 42:34And then the exciting part is they get to where they define the objective function, which as we described is how much does the food cost times how much of that food you eat for a given food.
- 42:44And then minimizing that.
- 42:46So they set that up.
- 42:49And 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.
- 42:57They set up those constraints again in this, their functions that they set up and then pass these.
- 43:03You will usually in Pyamo, you'll write the function just as you would essentially any other Python function, passing it some of the elements of your model.
- 43:12And then you'll, once you have that function written, you will then pass that to a model dot, whatever you want to name it.
- 43:22And the function contains the constraint.
- 43:26And now passing that to the model dot, whatever your name is, will give that Pyamo object the inherent mathematical rules of said constraint.
- 43:36Yeah.
- 43:37It's pretty neat.
- 43:38And I guess the last bit is there's also a data file, which looks a little bit like YAML.
- 43:44I don't think it's YAML at all, but it looks like that's kind of the visualization.
- 43:48It says, okay, we have cheeseburgers, ham sandwiches, fish sandwiches, chicken sandwiches, sausage biscuits.
- 43:53You're going to get some serious caloric intake from that.
- 43:55And then, you know, like how much you're allowed to eat, how much protein you need, how much carbohydrates.
- 44:01And then it lays out like the ingredients for each one of those.
- 44:05So you just define this data file that says the parameter F has this options, the parameter N has these options and so on.
- 44:11Right.
- 44:12So.
- 44:12Yep.
- 44:13Put those two things together at the end.
- 44:15You say Pyamo solve, give it a solver, give it the Python code and the data file that has all these parameters.
- 44:21Yes.
- 44:22And it comes up with a beautiful solution in a, actually, I think an actual YAML file for the output.
- 44:27Yep.
- 44:28And then, so here's the funny part.
- 44:29So how should we eat?
- 44:30Like I'm looking to get a little healthier, but also save some money.
- 44:33So what do I do?
- 44:33Yeah.
- 44:33So, well, I got some great news for you, my friend.
- 44:36For only $15 a day.
- 44:39If you eat four cheeseburgers, only five French fries, one fish sandwich.
- 44:45Oh, five servings.
- 44:47Oh yeah.
- 44:47Five servings of French fries.
- 44:48Five servings of French fries, I believe.
- 44:49One fish sandwich and four milks.
- 44:51You're good.
- 44:52Boom.
- 44:53Yes.
- 44:54Yes.
- 44:56The only thing that would make me happier is if there was like an ice cream shake or two in there.
- 45:00What you got to do is you got to be sitting there eating that and just let people that walk by, just tell them that you're optimal.
- 45:07Exactly.
- 45:08I've solved it.
- 45:10I've solved the nutritional problem.
- 45:12Yeah.
- 45:13So I'll include this problem in the show notes.
- 45:14It's pretty interesting.
- 45:16It went really quick.
- 45:17It took 9.7 milliseconds to run this.
- 45:19So that's pretty quick.
- 45:21The best.
- 45:21And I mean, I can tell you, we had time parameters in my thesis and we're talking a pretty robust
- 45:26electrical system and some pretty high, high level mathematics to account for all of the three phase AC power flow constraints and everything there in for a lot from the electrical engineering perspective.
- 45:36Yeah.
- 45:37And I did all of it on a fairly middle of the road, like 2015 MacBook Pro.
- 45:42And it would knock it out in 20 seconds, maybe.
- 45:46Yeah.
- 45:46That's incredible.
- 45:47I thought, well, maybe I'll come back to this tomorrow.
- 45:49You know, I didn't know.
- 45:51Yeah.
- 45:52Yeah.
- 45:53Tell people it's going to take really long.
- 45:55I'll take the rest of the day off.
- 45:56Well, darn it.
- 45:56It's done already.
- 45:57Yeah.
- 45:57But that's the nice thing about it is when you structure, it's so abstract, it's hard to talk about like a podcast, I suppose.
- 46:05But 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.
- 46:16Yeah.
- 46:17As opposed to trying to enumerate the best solution.
- 46:19Right.
- 46:21Yeah.
- 46:21Yeah.
- 46:22But that's the computational savings.
- 46:23Exactly.
- 46:25You're taking an intelligent way to get to optimality as opposed to trying to do something and the sun would burn out before you'd finish, right?
- 46:32Right.
- 46:33Well, and it's a solver, right?
- 46:35It doesn't just like try every possible thing.
- 46:38It has algorithms and stuff and it's beautiful.
- 46:40Yeah.
- 46:41And the individuals that write these solvers, I mean, they're the mad scientists, right?
- 46:46That are able to.
- 46:47Yeah.
- 46:48You know, the solvers that actually blow my mind are the stochastic ones.
- 46:52I took some Stokes classes and it was just one of those like, okay.
- 46:55I don't really understand.
- 46:58I barely touched on it.
- 46:59I wasn't very much on the statistical side, but I did work with some people in my math experience around those.
- 47:06And it's like, here's a problem that'll take seven days to solve, or we can do this little magic and get basically the same answer in about half a second.
- 47:13Like, wait a minute, how did that even, how is this even possible?
- 47:16Like, what are these things doing?
- 47:17Well, I mean, that kind of comes back to what I said.
- 47:19I get a little naive with some of my education at times, but I want to say that in one of our first coding classes, we set up something like a traveling salesman problem.
- 47:29And I'm sitting there going, I got a Core i7 in here.
- 47:32This will knock this out.
- 47:34I start letting it go.
- 47:35And just to prove the point, the professor is like, literally, because we're doing it like brute force, basically.
- 47:41He's like, the sun will die before your computer will finish this problem.
- 47:45Yeah.
- 47:45You know, and then we structure it smartly in Piomo, and it takes a couple milliseconds.
- 47:49Yeah.
- 47:50It's insane.
- 47:51That's so insane.
- 47:52You also start to appreciate, like, factorial and stuff.
- 47:56Oh, yeah, right.
- 47:57What do you mean, the heat death of the universe before this time?
- 48:01This is no good.
- 48:01All right.
- 48:02Well, I think that gives people a sense.
- 48:04I mean, honestly, I don't recommend the diet.
- 48:07But it gives people a sense of the type of problems and the way you set them up.
- 48:13And it's a pretty clear, understandable problem.
- 48:15And then a simple bit of code, like the Python code that actually does the smarts, right?
- 48:21The cost and the limits or the constraints.
- 48:24But it's probably like six or seven lines of code.
- 48:26It's not a lot.
- 48:27No, it's very straightforward.
- 48:29The actual, again, coming back to, you know, my thesis, heck, I haven't pulled up, but something
- 48:34like 600 lines of code.
- 48:35And I want to say two thirds of that was just prepping the data, right?
- 48:39And then the actual Piomo work was.
- 48:42Yeah, exactly.
- 48:43Yeah.
- 48:44Maybe of that remaining third half of it.
- 48:46And then the last part of that third was like shaping the output to be intelligible,
- 48:50right?
- 48:51The Piomo itself is pretty clean.
- 48:53Right.
- 48:54Wow.
- 48:54Okay.
- 48:54Yeah.
- 48:55It definitely looks interesting.
- 48:56And it looks very like it solves many different types of classes of problems, right?
- 49:01Like linear programming versus nonlinear programming versus stochastic programming.
- 49:04And then those solve each many interesting real world problems, right?
- 49:09So this is broadly applicable, I think.
- 49:11Yeah.
- 49:11And I'm one of those guys that's like every problem is a network problem, right?
- 49:14And you can feed those to this.
- 49:16And then I view the world as either network problems or assignment problems.
- 49:19And assignment kind of ties back into some of my work for the government, which is, do we
- 49:23have the right people where they need to be?
- 49:24And you can throw that at this.
- 49:26Yeah.
- 49:26Are you a fan of graph theory?
- 49:27Yes.
- 49:28Yeah, I am too.
- 49:29I love that part.
- 49:29All right.
- 49:31Let me add, I think this is probably a good place to sort of wrap up our general conversation.
- 49:34I'll ask you the two questions.
- 49:35Anything else we should add to the general conversation before we wrap it up?
- 49:38I got to just thank professors Alderson and Carlisle.
- 49:41I mean, again, kid from the country didn't know what was going on in life and kind of stumbled
- 49:46into this curriculum that has completely changed my life.
- 49:48And I've always joked, I'm the dumb, smart kid that's smart enough to get into the advanced
- 49:53stuff and then struggle the whole time.
- 49:55And yeah.
- 49:57Exactly.
- 49:57I don't belong here, but somehow they let me in.
- 49:59But yeah, that's cool.
- 50:01Yeah.
- 50:01That happened to me at the nuclear power curriculum.
- 50:03It happened to me here.
- 50:04I'm forever indebted to those two gentlemen.
- 50:06So just thanks to them is something I would love the chance to throw out here.
- 50:09Yeah, absolutely.
- 50:09All right.
- 50:10So before I let you out of here, this has been really interesting, but let me ask you
- 50:13the final two questions.
- 50:14And I have a twist on the second one because I want to throw out something in addition.
- 50:19And while we're talking, because I want to hear your thoughts on it.
- 50:21Okay.
- 50:22If you're going to write some code, what editor would you use?
- 50:24Either Jupyter Notebooks or Sublime Text.
- 50:27Jupyter or JupyterLab?
- 50:28Ooh, now you're getting beyond my head.
- 50:30Have you made the transition over to JupyterLab or are you sticking with the traditional?
- 50:34I don't think I have.
- 50:35I'm probably stuck in the past.
- 50:37Yeah.
- 50:38They're pretty similar.
- 50:39They're pretty similar.
- 50:39All right.
- 50:40Good ones.
- 50:41And then notable PyPI package.
- 50:43Pyama, probably the reason I'm here.
- 50:44Right?
- 50:45So, yeah.
- 50:47Awesome.
- 50:48That's really cool.
- 50:49That's really cool.
- 50:50All right.
- 50:50So I put, I want to give a shout out to one because I think this is actually going to
- 50:53be pretty interesting.
- 50:54I haven't talked about it on Talk Python.
- 50:55I have on Python Bytes.
- 50:57Do you see that link?
- 50:58Yeah.
- 50:58Click, open that link.
- 50:59And then let me describe this to the people.
- 51:01And then you give me your thoughts.
- 51:02There's a cool graphic.
- 51:03So you don't have to like, there's like an animated GIF.
- 51:06So you don't have to like feed.
- 51:07So a lot of times what we do is we do math and optimization problems like we're talking
- 51:13about here in code.
- 51:16And the code looks a little bit like theoretical math, but not really like theoretical math.
- 51:22But it would be really nice if you could have like the LaTeX fancy published like math book
- 51:29representation of the steps that you're doing.
- 51:32So there's a really cool project called Hand Calcs.
- 51:36Have you heard of this?
- 51:38No, I've not.
- 51:39But so I wrote my thesis in LaTeX because there was so much of that fancy math, the actual written
- 51:49math, right?
- 51:50For all my constraints.
- 51:51Yeah.
- 51:51And learning LaTeX was a challenge, especially when I'm trying to wrap my mind around my
- 51:57actual thesis work.
- 51:58So seeing what I'm seeing here and the fact that it's in Python, I'm jealous.
- 52:02I'm jealous right now.
- 52:03Yeah.
- 52:03Just scroll through some of the pictures here and I'll put it in the show notes as well.
- 52:07So what you can do is you can write out like statements and equations in Python.
- 52:12And then you can say, render with this Hand Calc, you say, render the, what I would have
- 52:17done like step-by-step sequence I would have had to do to work out that calculation, right?
- 52:23So you could say like X equals negative B plus square root B squared minus 4AC divided by
- 52:29two, like quadratic.
- 52:30And it'll actually, if it knows what the values of those are, it'll write out the steps of solving
- 52:36that equation like bit by bit by bit as you would in like math class, but in Jupyter notebooks.
- 52:42Yeah.
- 52:42This is super cool.
- 52:43Isn't this neat?
- 52:45I thought like given what you're talking about, like this, this is a good thing to pair it with.
- 52:49Oh yeah.
- 52:49I mean, this would have, this would have saved a lot of time.
- 52:52What have I done with my life?
- 52:56This is pretty new.
- 52:57I believe this is from Connor Fester and I'm really impressed with this project.
- 53:00This is cool.
- 53:01Yeah.
- 53:01That's super, super cool.
- 53:04Cause I mean, for me, it was either try to use the, in my opinion, atrocious math type
- 53:09plugin in word, which not happening or write in LaTeX.
- 53:16And this would have been more fun because I would have been able to stick with one.
- 53:19Yeah.
- 53:19LaTeX is fine, right?
- 53:21Like all the math books and all the math papers and physics, I suppose as well.
- 53:24Like almost all of them are done in that.
- 53:26Right.
- 53:26But the thing is now you've got the data in two places and if you change one, but you
- 53:31forget to change the other.
- 53:32Oh no.
- 53:33It's all like, this just takes your Python code and like turns it into symbolic math.
- 53:38It's awesome.
- 53:38Yeah.
- 53:39This is super cool.
- 53:40Nice.
- 53:40All right.
- 53:40Well, let's leave it with hand calcs and a final call to action.
- 53:43People want to get started with these types of problems and like using libraries like this.
- 53:48What do you say?
- 53:49Well, if you want to use Pyamo, if you're listening to this podcast, you're probably
- 53:52familiar with some of those classic computer science problems.
- 53:55I'd say pip install Pyamo and try to structure one of those problems in that system.
- 54:00Then my other, I guess I'm going to have two calls to actions.
- 54:03I'm cheating.
- 54:03Go for it.
- 54:04The other one I'll say is from that analyst perspective, kind of bringing it full circle
- 54:08to Jacqueline and Emily, I get looked at at work like I'm a sorcerer because of some
- 54:12of my Python skills and listening to some of your guests, like I'm not right.
- 54:16But your calls to action often reach out saying, Hey, you know, maybe you're that person in
- 54:22a job and you have this one Excel task that you do all the time, right?
- 54:26You could automate that.
- 54:27Well, I'm kind of that guy in a way where the calls to action that you've sent out, again,
- 54:35I'm that person who has been automating things.
- 54:38There was one example where we literally had people going through surveys by hand.
- 54:42So this is surveys where like we ask our sailors, how do you feel about A, B, C, and
- 54:46D?
- 54:47And they used to go through them by hand.
- 54:48And I was like, that can be better, right?
- 54:51And so just...
- 54:51This can't be the best way.
- 54:54No, right?
- 54:55And so we had the data digitally and I'm not even an NLP, not to be confused with nonlinear
- 55:00programming, but I'm not a natural language processing guy.
- 55:02But I installed some packages and was able to try to get sentiment out of surveys, right?
- 55:07And so...
- 55:07Oh, that's cool.
- 55:09I just say that the power of this language can help at all levels.
- 55:13And I'm at a fairly high level of government.
- 55:14It's incredible what it does for us.
- 55:16So the call to action, I suppose I'm rambling a little bit, is if you are that guy out there,
- 55:21take it from another one of that guy that it really does work.
- 55:24Yeah.
- 55:24Yeah.
- 55:25I think it's great.
- 55:26And you're in one of these positions where you're a little bit on the boundary of a lot
- 55:31of people who need answers.
- 55:32They have a lot of data, but they can't answer the question themselves through code or programming
- 55:37or anything along those lines.
- 55:39And so it's like right there for you to just take that little step and come across as a
- 55:44magician.
- 55:44Like I do like to say that developers, data scientists, people who can write code, we really are in some
- 55:51sense, the wizards or magicians of the modern era, right?
- 55:56You think about an idea, you sort of do the incantation.
- 56:00And then out of just energy in your thought comes a thing that can have huge impact.
- 56:05And those don't have to be, oh, I created some huge, like I created Airbnb or whatever.
- 56:09It could be there are people that can now focus on stuff that humans are good at and not just
- 56:15typing in, moving stuff around from one Excel sheet to the other, to copy it over to PowerPoint,
- 56:19to show it to the general.
- 56:20Yep, absolutely.
- 56:21I have so many examples.
- 56:22I can give you one more.
- 56:23Like we have this huge database of what civilian skills people have in the Navy Reserve, which
- 56:29is a unique thing of us because we have our reservists have their military life, but they
- 56:32have their civilian life.
- 56:33And facets of their civilian life might be applicable skill sets that we could employ in a military
- 56:39context.
- 56:40And whoever designed the system to capture this only set up free text entry.
- 56:46So imagine if you have 20,000 people do free text entry of what they're capable of, right?
- 56:55You're like, couldn't I have just gotten a combo box?
- 56:58Exactly.
- 57:01But...
- 57:02Or a radio button list or something.
- 57:04Some kind of dropdown, maybe some cascading dropdown menus, right?
- 57:08But so I inherited that database and it was sort of one of those, can you make anything of
- 57:13this?
- 57:14And right at the same time, a pretty high level individual was coming to us saying,
- 57:17hey, do you have anyone with civilian skills to do this?
- 57:21And I just wrote the world's most basic query and was like, yeah, we got seven.
- 57:25Here they are.
- 57:26Right?
- 57:27Yeah, that's awesome.
- 57:28And you would have thought I'd like conjured a spell, right?
- 57:31And...
- 57:32Yeah.
- 57:32So this is why I made that source for a common beginning of this.
- 57:36It really is incredible what you can do.
- 57:38It absolutely is.
- 57:38And it's within everyone's reach, I think.
- 57:40Yeah.
- 57:41It just takes a little bit of practice and a little bit of trying it out.
- 57:44Yeah.
- 57:44All right, Clark.
- 57:45Thank you so much for being here.
- 57:46It's been a lot of fun to talk about all these problems and cool work.
- 57:49And thanks for helping us all live a little healthier lives, getting our diet figured out.
- 57:54Four cheeseburgers, five servings of fries, a fish sandwich, and four milks.
- 57:58You're set.
- 57:59You're set.
- 58:00You're going to live forever.
- 58:02Optimally.
- 58:03All right.
- 58:03Great to chat with you.
- 58:04All right.
- 58:06Thanks, Michael.
- 58:06Yeah.
- 58:07Bye-bye.
- 58:07This has been another episode of Talk Python To Me.
- 58:11Our guest on this episode was Clark Petrie.
- 58:14And it's been brought to you by us over at Talk Python Training and our friends at Linode.
- 58:18Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.
- 58:23Develop, deploy, and scale your modern applications faster and easier.
- 58:26Visit talkpython.fm/Linode and click the Create Free Account button to get started.
- 58:31Want to level up your Python?
- 58:33If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 58:38Or if you're looking for something more advanced, check out our new async course that digs into
- 58:43all the different types of async programming you can do in Python.
- 58:46And of course, if you're interested in more than one of these, be sure to check out our
- 58:50Everything Bundle.
- 58:51It's like a subscription that never expires.
- 58:53Be sure to subscribe to the show.
- 58:55Open your favorite podcatcher and search for Python.
- 58:57We should be right at the top.
- 58:58You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 59:03and the direct RSS feed at /rss on talkpython.fm.
- 59:07This is your host, Michael Kennedy.
- 59:09Thanks so much for listening.
- 59:11I really appreciate it.
- 59:12Now get out there and write some Python code.
- 59:14I'll see you next time.
- 59:34Thank you.