Tim Varelmann, the founder of Bluebird Optimization, which helps companies automate complex decision-making, speaks with host Sriram Panyam about mathematical optimization. The episode begins by differentiating optimization from what software engineers usually mean by the word. Making something faster or smaller is improvement, whereas optimization means finding the provably best solution after which no further improvement is possible unless the problem’s parameters change. The conversation examines the difference between simulation and optimization, where optimization is already running, optimization and AI, key software engineering principles, and how you can get started with mathematical optimization.
Brought to you by IEEE Computer Society and IEEE Software magazine.
Show Notes
Related links
Transcript
Transcript brought to you by IEEE Software magazine.
This transcript was automatically generated. To suggest improvements in the text, please contact [email protected] and include the episode number and URL.
Sri Panyam 00:00:18 Hello, welcome to Software Engineering Radio. I am Sri Panyam. Today we have Dr. Tim Varelmann. He’s the founder of Bluebird Optimization. He helps companies automate complex decision making through mathematical optimizations. He holds a PhD from RWTH Chen University, where his research focuses on developing optimization algorithms and software for operating electricity grids with high penetration of renewable energy. His academic journey took him to our four universities on three continents, including research stays at MIT and the University of Texas, Austin. He is also the author of the first GAMSPy course covering algebraic modeling for optimization in Python. He’s applied work spans production planning for industrial manufacturers, energy system dispatch and supply chain logistics. Tim, welcome to Software Engineering Radio.
Tim Varelmann 00:01:12 Hello. Hello. Good to be here.
Sri Panyam 00:01:14 Yeah, Tim — or, Dr. Varelmann?
Tim Varelmann 00:01:16 Tim is fine.
Sri Panyam 00:01:17 When software engineers hear the word ‘optimization’ we think about make things faster, make things smaller, make things more efficient. What is the kind of optimization that you are referring to? Can you explain what mathematical optimization means and what are the parallels and differences from other areas like engineering?
Tim Varelmann 00:01:34 Yeah, so let’s start with the examples you gave. I think those are examples for improving things. When I speak about optimization, it doesn’t mean that you have something in the beginning, you make it better and then it’s improved. But optimization really means we find the optimal thing. So, after this optimization, there is no more improvement possible afterwards unless you change the parameters of whatever you want to achieve.
Sri Panyam 00:01:56 Nice. I think the origin traces back to World War II around logistics. Can you share some examples from that era? How this problem or the space began and really how it shows up today in modern systems?
Tim Varelmann 00:02:07 Really the theory comes back from the end of World War II where a lot of decisions had to be made in logistics. There’s always a shortage of materials of tanks, everything on the front. So, you really need to decide where do the things we deploy have the most impact? And the theory was really developed in the late 1930s, early 1940s. Of course, people have essentially had no compute at all judging by today’s standards. But yeah, that’s really where the theory came from, where people started to realize, we have a bunch of complex decisions. Each individual decision is not really that hard, right? You can deploy a tank or not, or you can deploy a platoon or not. But overall, if you have a global maximum that you want to achieve effectiveness in this case, these things can become quite complicated because of course you have constraints.
Sri Panyam 00:02:56 I think it’s almost a pity understatement to say that there was no compute at the time, right? If you don’t include.
Tim Varelmann 00:03:02 It’s ridiculous. Yeah.
Sri Panyam 00:03:03 So how did it work? I mean obviously when you think of optimization and global optimization, the scale is just as staggering, clearly didn’t go all the way. So, what was the range that mathematicians or I guess optimizers at the time strive for?
Tim Varelmann 00:03:18 The ambitions were pretty much unlimited back then, already. So, I remember for the introduction of my PhD defense, I had brought up a slice with a quote from George Dantzig who’s at least in the western world, he’s considered the Father of Optimization in the mathematical sense. And what he really wanted to achieve was stochastic optimization. So, you have uncertainty playing a role and some things you don’t even, you can’t really model yet because you don’t know what their values are going to be. You just know something about how they behave in the future, but not really the specific value. And he wanted to do that for dynamic problems. So, you have time involved, that means typically have to ize(?) it in numerical mathematics. And he wanted to solve it not just to local optimality, but he wanted to solve it globally. And that’s pretty much the holy grail ever since and we haven’t even achieved today, I would say. I chose that quote because in the PhD defense I did a tiny little step forward to combining all these three things, but that’s really still a long way to go. Back in the days it was really just only linear computations. Nowadays, obviously we have lots of non-linear capabilities with lots of compute, but yeah, things were really, tiny in the beginning when we looked at it right now.
Sri Panyam 00:04:26 What’s an example of a linear versus non-linear system that might be a play here?
Tim Varelmann 00:04:30 So a linear system, I guess really, it’s a question of how to model things. You can model lots of non-linear things in a linear manner, but if we think more naturally lots of supply chain logistic applications, you can really model them linearly because you don’t need any squared numbers. You just have sums of trucks and maybe their capacities. But if the capacity is not a variable in a truck, that’s typically fixed and then you can multiply the capacity with whether or not that truck is going on a route. And then you have linear model interest.
Sri Panyam 00:05:00 So, something like one truck can carry a thousand gallons of fuel. Your war needs a billion gallons of fuel in a billion trucks. It’s almost like a linear operation there. Yes. And the moment something needs to be squared or logged or powered, it becomes a non-linear relationship.
Tim Varelmann 00:05:15 Exactly. That’s what happens.
Sri Panyam 00:05:17 So typically in this kind of modeling, it sounds like as you add more non-linearity, you can get to model the problem closer, realistic kind of way, right?
Tim Varelmann 00:05:25 That’s true, yeah.
Sri Panyam 00:05:27 If you look, if you take the problems of today in modern software systems, I guess the need hasn’t changed, but the way to achieve it looks like it’s changed.
Tim Varelmann 00:05:34 It has changed tremendously. Yeah. Like what we do now these days when we model electricity grids for example, we typically have alternating current and you have signs and cosigns in there all over the place, right? So that’s a pretty nasty nonlinearity specifically also because you really don’t have any global hill, right? You have a local maximum, but in the sign and cosign itself, they always reach the same value and then just go back and forth between one and negative one. That’s a pretty nasty thing to do in thermodynamics, we have exactly what you mentioned with logarithms and exponentials where you really want to model what is going on inside a chemical reactor really precisely in order to just represent the physics and the chemistry well, because the decisions you make with an optimization software can only be as good as the model you put in. That’s again, garbage and garbage out, obviously.
Sri Panyam 00:06:23 Nice. I guess taking that further these days with powerful computers or powerful systems, we do a lot of things in the form of simulations, right? I guess at a very basic level, how do simulations and optimizations differ?
Tim Varelmann 00:06:36 I think they’re pretty related in a non-obvious way. And my background started in simulation to be honest. In my bachelor’s degree, I really learned how to build professional simulation models from scratch with all the mathematical foundations. And towards the end of my bachelor’s in the master’s as well, the professors and everybody were teaching mentioned, hey now basically what simulation does, right? You can start with some initial configuration of whatever system you’re looking at, and then you can describe with your mathematical model how this moves forward through time. And then you can predict what happens at the end of some time horizon with whatever happens in your simulation model. Now, let’s take it a step further and do optimization because really the models don’t change when you do optimization and you’re coming from simulation. The direction of compute changes in optimization, you start at the end, you say, I want the best possible outcome.
Tim Varelmann 00:07:26 And you can define best. You can also define what the outcome is. Sometimes in production planning, people want to optimize cost, and they obviously minimize the cost. Sometimes if you have more general supply chain things, you’re looking for profit and then you’re of course you’re maximizing, you could really tailor that. The point is, at the end, you start in optimization and you say this is the best possible outcome that we want to achieve. And then you take the very same model that you could use to simulate and run it backwards and say, what do I need to put in in the beginning? That’s the computational result. Whereas in simulation, you start at the beginning and that’s the initial state that you prescribe. And in optimization, the output is these are the inputs you should put into the system right now so that in the end you will achieve the optimal outcome you’re looking for. And of course, the nice thing is, but also the thing that introduces computational complexity in the beginning, you don’t really know what the best thing is. So, it’s not just one backward calculation, but it’s a little more complicated because first of all, you have to start with what the best attainable output at the end is. And once you’ve figured that out, then it’s really just a plain backward calculation.
Sri Panyam 00:08:29 So would it be fair to say that in a simulation, or you have an initial idea of what the model is, if I drop a ball, it’s going to fall. What are the physics formulas, right? Like what is it? The gravity formula?
Tim Varelmann 00:08:41 Yeah.
Sri Panyam 00:08:42 Yeah. So, you kind of have some initial high of that model and you’re trying to see at every discreet tick what’s going on, right? And it sounded like with authorization, you have I guess if you’ll take this ball example, you have some kind of recording of the ball falling at various heights or initial speeds and you want to work back with what the model or formula is.
Tim Varelmann 00:09:06 I think I would want to change the analogy because if you have a physical ball falling down, there’s not much you can decide along the way. And optimization is really the science of optimizing decisions. So let me maybe slightly change your analogy and say. The ball is not falling in gravity, but you have like a ball or some other point in an electric field or a magnetic field because that is something that you can change over the course of the time that you’re looking at. You can make it fall, you can make it rise if you want to.
Sri Panyam 00:09:34 Right. And what would you be optimizing then? Would you be optimizing the model that would predict how the ball would move in that field or would you optimize the field itself?
Tim Varelmann 00:09:44 See, that’s the thing. You can decide whatever you want to optimize for. If you have a starting position, let’s say in the middle, and you want to minimize the time it takes until some of the electrodes is hit, so let’s just put maximum acceleration to it and move this thing up or move this thing down with the smallest amount of time, you can do that. Another important thing is you might want to keep it exactly in the middle. You have some external influences that disturb your electrical field that influences where exactly your loaded point load moves, and you sort of want to suppress those external disturbances. That’s what we do in control engineering all the time where you really have one goal that could be a moving goal, it could be just a steady state goal, and you have external disturbances that try to bring you away from that goal. And so, with optimization you can achieve that too by saying, over the course of time we want the minimum amount of deviations from our trajectory, whether the trajectory is just a steady state or it’s a moving target.
Sri Panyam 00:10:39 So what are some of the examples of that industrial or real-world control systems where this optimization is apparent?
Tim Varelmann 00:10:45 With control systems I would say I would move to chemistry, chemical engineering. So, lots of production planning cases obviously where you have this non-linear physics thermodynamic of mixtures involved, that’s where you really have complicated plans that you want to follow. And also moving targets in terms of the reaction chemistry, for example, sometimes you want to follow a certain temperature profile because in the beginning you want a different temperature then at the end because at the end you already have a bunch of product and that product could continue to react to something degenerate that you don’t even want anymore. Therefore, you maybe want to lower the reaction rates toward the end of some batch process, for example.
Sri Panyam 00:11:22 So in this scenario, once you’ve done or gone through your optimization phase, what does the model end up looking like for the system?
Tim Varelmann 00:11:29 It’s just a bunch of equations, really, equalities and inequalities. So yeah, as I said, it’s essentially indistinguishable from a simulation model where you just say, I have a bunch of physics. And then with the inequalities you can also put some constraints there. So again, as an example from logistics, if you have a fleet of five trucks, then the total amount of truck utilization must not exceed five. So, you have some trucks on the left-hand side and then you’ll say this left-hand side must be smaller than or equal to five. So, we have an inequality. That’s the additional thing that comes in addition to inequalities that can describe physics and other kinds of stuff.
Sri Panyam 00:12:03 Did I hear you right when you said it’s not just a one-off process? Like you can start up one way, either simulation or optimization, go all the way the other extreme, take that result and then drive it forward to the other side and then have some kind of convergence?
Tim Varelmann 00:12:15 I’m not sure where you’re going with this.
Sri Panyam 00:12:16 Well, I guess I think earlier you mentioned you can start off with simulation, but what the model is or you can start with optimization on what you want to solve and then work out the model, right? Is it usually a one-way process or do you repeat until something’s like a goal’s achieved?
Tim Varelmann 00:12:30 So like if I work with clients, it’s always an interactive process, the model development phase, if that’s what you’re asking for. And the reason is simply because the requirements are never complete, at least not in the beginning. So, you can ask people what is it that you want to optimize? What is the basic physics of your production route, of your logistics? You might have some, a bunch of parcels, a bunch of clients that you need to serve. They might have some drivers that only work half time. You might have some trucks that have skills such as cooling. So, all these things are what I ask people for and they always forget things, which are fine because the nice thing about it is the things that are really important, they don’t forget even not even in the beginning. So that always means in this iterative approach from the very beginning, we do have the essentials because that’s what people mention. And then I show them a solution, and they say, oh, actually I realized this solution doesn’t really work because we have this particular business rule. So, we can add that later on.
Sri Panyam 00:13:23 So for software engineers, we usually have some kind of simulation of a system, right? Like either load tests or capacity models. So, for software engineers, if they want to think about turning a simulation scenario into an optimization problem, what would that I guess process be like?
Tim Varelmann 00:13:38 The model can pretty much be the same. It’s more a matter of intent. So, if you have, let’s say a server farm and you sort of want to balance your load, that is a tricky question to formulate your objective because you can’t really say, I want to maximize this particular server and all the others I don’t really care about. These optimal balancing things are pretty difficult to formulate because it’s all about the difference between not just one server but multiple servers to each other. And then you sort of want to minimize the maximum difference between those servers. That’s something what a good balance would look like. So, the objective is really the only thing that you add on top of a simulation model. And then of course you need to compute it. And as I mentioned earlier on, the computational complexity of optimizing is a bit heavier than just simulating because it’s more than just a reverse computation in the beginning.
Tim Varelmann 00:14:28 You have to figure out the best solution and technical audience will be familiar with the problem of NP hard problems, whether it’s P problems and stuff like that. The funny thing is what most people don’t realize is who works in software rather than in, in this mathematical domain that I work in, these problems that we work with that I and my clients work with, they’re essentially all empty heart problems. And for a computer scientist it sounds like, oh, there’s no efficient algorithm, we won’t even touch these problems. The thing is, we don’t have efficient algorithms. The algorithms we use all have exponential worst-case complexity. However, if you do it in a clever way, this formulation, you can solve them in an acceptable amount of time, even though theoretically it takes an exponential amount of time. But in practice, the solvers are really good. And yeah, that’s sort of this difference between theory and practice, where in theory you don’t have an efficient algorithm, but practice, even if it’s not efficient, it’s good enough,
Sri Panyam 00:15:17 It’s good enough. So these are obviously, we’re talking about heuristics here, like some of the heuristic algorithms you might apply in lieu of a brute force might get you the optimal solution. But obviously with exponential complexity, right?
Tim Varelmann 00:15:28 Heuristic is essentially a clever simulation because it’s just forward and you execute it once. Maybe you have some iterative components in there and you can sort of dynamically decide when to stop the iterations. But essentially, you just run it forward and you don’t really concern yourself with what is the provable optimum in which region do I find it? And obviously you may end up with a local solution, which is fine, often works and feasible, but sometimes you’re really looking for not just a good hill, but the biggest mountain.
Sri Panyam 00:15:54 Nice. I would love to hear some of, I guess, some common algorithms that we might be applying using on a day-to-day basis without realizing that this will be doing.
Tim Varelmann 00:16:02 The thing about optimization is, so just to name a few algorithms, the basic one is the simplex algorithm for linear programming. There’s also a bunch of interior point methods. And then once we move beyond the linear parts, you can add mixed integers. So, you have discrete decisions, yes, no decisions, stuff like that. And you can obviously add non-linear components. And they all just build upon, let’s say linear programming in a sense, because what they do is just a divide and conquer approach until you have divided your solution space so far down that you can just do a linear programming and then with a back and forth between small linear programming and then a clever orchestration of all these things on the non-linear level, you can solve these problems as well. And really the thing about optimization is once it really works, it becomes invisible. I briefly alluded to that.
Tim Varelmann 00:16:50 We operate all of our electricity grids using optimization, deciding which transformation to use, where to route the electricity through which grids so they don’t burn off because they have to transport too much power. And under the hood is optimization because all of those things are technical decisions and technical decisions are pretty easy to quantify whenever we have a quantifiable decision, that’s where optimization shines. I always say, with optimization we can’t do these ethical decisions, right? Should Tesla run over the granny or the school kids? That’s not a decision for optimization please. But if you have a technical decision where you can quantify and say, we have one number here, one number there, we can use numbers to decide what’s allowed, what’s not allowed. And we can use numbers to discriminate between multiple allowed solutions and say; this one is better than the other because of some typical economic metric. Then you use it there. So, it’s on your electricity grid, it’s on Amazon, everybody who delivers passwords through your door, is on airlines. They operate so many optimization problems for fleet scheduling of the aircraft for the crews, how to schedule them so that you have people who are well rested on your flight and can take care of the whole thing in a case of an emergency according to all of the rules, routing your baggage through an airport is all done with optimization these days.
Sri Panyam 00:18:00 And I guess it almost sounds like a very, very macro way of looking at almost any problem.
Tim Varelmann 00:18:07 That’s true. That’s because mathematics is just so abstract and that’s what also software engineers like to do. We like to abstract things out because then they become reusable. And that’s what fascinates me about this technology as well, because the heart is already mathematics, which is also you have this incentive to do abstractions and become more and more general. And that pairs very well with software engineering philosophy, I would say.
Sri Panyam 00:19:00 I guess one of the hottest areas today, AI especially AI training, I think you mentioned that AI training itself is just optimization under the hood, but used in a very, very, I guess generic way. Can you tell us more and what makes it generic? Specifically, what makes the optimization inside this differ from let’s say optimizations in a factory product schedule problem?
Tim Varelmann 00:19:21 So, the thing that is optimization inside of AI is the learning process. Essentially an LLM is just a giant neural network where you have a bunch of weights and biases that you need to train. And during this training process, that is an optimization problem. And I would say it’s not really a very sophisticated optimization problem because it’s only minimizing some loss function. And for decades now, people have put a bunch of creativity into defining more and more loss functions that achieve very fine granular goals. But really from an optimization lens, that’s actually unimpressive because the most powerful thing that we have an optimization available, that is constraints, they don’t use it at all in training large language models. If you have a constraint like a physical system, let’s go back to logistics again where I mentioned that you can just sum up the amount of trucks that you have and say this total sum of trucks must be smaller than five, right? This is a hard constraint that you can enforce with this inequality and that an optimizer can take care of and will make sure never to violate, try anything in the context of AI that should never be violated. Where you can be like, sure, that is never violated, it’s totally impossible. And that’s because you don’t use the constraints and the power of constraints that you have. It’s really just optimizing the loss function. There’s lots of creativity in the loss function, but that’s all there is. It’s totally unconstrained.
Sri Panyam 00:20:41 So what kind of constraints could you use in AI training and what makes it challenging to use them today?
Tim Varelmann 00:20:47 I mean today the whole thing blew up so much. I don’t think it would be very easy to just start using constraints right now because of all of the things that developed afterwards after the training thing came in. But just thinking from a neural network theoretical perspective, people do write what they call physics informed neural networks. So, you have some kind of physics, could be thermodynamics, could be others, what do people do in quantum computing and stuff like that. You have some physics and you want your neural network to adhere to that physics. So, you can sometimes produce solutions that simply aren’t physical because some rules of physics are violated. And what people do in those physics informed neural networks is again the other things, they go to the loss function and essentially, they put a penalty into the loss function. So, if you have a violation, if you have a physical equation, you can say, hey there’s a residual to that equation, how much it is violated?
Tim Varelmann 00:21:37 And then the easiest thing you can think of is just square that and put the square of the violation into the loss function because then it doesn’t matter which direction you violated in, if it’s negative or positive, if it’s just squared, the sign goes away. And larger deviations are penalized more heavily than smaller deviations. And that sort of gives you physics aware neural network outputs because they have this penalty put in and then of course you can tune it properly so that it’s sort of acceptably small of an error, but you’re not really getting there with like sharp rescission and it takes a while to tune these things.
Sri Panyam 00:22:09 Interesting. So again, if go back to my ball for example, like for example, the ball dropping gravity, right? If gravity itself was a physical constraint, you might say any of these nodes, what came out cannot exist. Some physical function of what came in. Exactly. But then isn’t that pretty much an open space of physical, I guess equations like you can have almost infinite equations. How do you pick and choose which physical equations you might apply at which layer or node to your giant matrix?
Tim Varelmann 00:22:36 Those that are relevant, which take us back to the theory of mind, foundations of intelligence really, right? Because relevance is clearly something that is a core function of intelligence determining in a given context what is relevant and what isn’t. And obviously for me that’s what I make a living with, helping my clients decide what’s relevant and what’s not with the decisions that I model for them and put it to the model. And if you have some chemistry, for example, in a production planning context, you don’t really need to model everything on a quantum level. It just doesn’t make sense. People have empirical relations where they can say, roughly this is the number and we have sort of a chemical reaction constant is what they call it, which is basic measure of speed of the reaction. It’s good enough. Okay, so then the good enough comes back in, but it comes back from a physical perspective really.
Sri Panyam 00:23:22 Would this put some kind of limit on how general a model then might be? Because you might say that for this domain I might pick a handful of chemical equations or a dozen or a hundred chemical equations, whereas for a different problem, a different model, a different domain might pick a thousand physical equations if something else might pick another dozen biological equations and have different domains of equations that inform your model. Yeah. As in, do you lose generality, but you gain more optimized, constrained, focused models?
Tim Varelmann 00:23:51 Yeah, that’s exactly the tradeoff. I mean the ai, you mentioned that they are so generic just because they have this great loss functions that train the AIs, they can be very general, but it takes a lot of data to train these things. It takes a whole bunch of energy not just to train them but also to run them. And it’s super impressive, right? I’m not debating that, but it’s really like when you look at it, what these LLMs can do these days, it’s a miracle and it works, but it’s a miracle. And if you think back to your software engineering journey and your career maybe, I think every software engineer has some moments in their career where they can look back and say, this worked. But it really was a miracle. And I also have the feeling that when you think back to these moments, it was almost always an instance of poor architecture. If something is a miracle but still works, that is indicative of poor architecture.
Sri Panyam 00:24:37 I mean I look at my own code from a year ago and I feel that way.
Tim Varelmann 00:24:41 That’s exactly the point I’m trying to make, right? The architecture in in LLMs is oppressive. But I think for many decision-making problems you could do something much more specific. And typically, if you have like a production planning model, if you have a model for deciding how to operate batteries and electricity grid, once you have the model and it works for some cases it’s sort of validated and somebody says, hey this is fine and I can work with it, you can obviously still change things, right? And that’s a whole software engineering domain again, how do we implement software in a way that makes it maintainable? Because we know that reality changes every time. But if we have written our models in a proper, in the software engineering sense in a proper manner and they are easy to maintain, they’re easy to extend.
Tim Varelmann 00:25:21 And then it’s typically a very small amount of work that goes into the maintenance of these models so that if the reality changes, if you have some new business rule, if you have some people behave differently back when there was the pandemic, suddenly there was a lot of economic things that changed and assumptions that broke. You really need to adapt to these things. But once the fundamental model really works, it’s often just a small tweak and you have the thing running again. Whereas try that with AI, some fundamental assumption changes. Essentially what you have to do is train everything anew, set all of your guard rails new, and even if they are all in place, you have to monitor them sort of manually for a bunch of times before you really develop trust in it. Whereas if, under the hood there’s just mathematics going on and I know what the equations are, I can see them in my code because I’ve put them there and I know I have trust that they will be adhered to these mathematical constraints. You develop them, you test them once and you’re good. I would argue yes, you lose some loss of generality, but if you do it properly in a software engineering sense, you gain a lot more velocity with adapting to the real-world changes rather than with AI.
Sri Panyam 00:26:24 I mean you did mention these domain specific functions for physics and chemistry and biology, putting my own selfish needs ahead. What would say, I guess, what equation driven constraints look in the domain of coding agents, for example.
Tim Varelmann 00:26:41 What would you want to achieve with a coding agent?
Sri Panyam 00:26:43 Well, I mean if I don’t need to depend on an LLM that I’m paying a lot of money for, if I can get a much smaller model but highly optimized to with let’s say, a few code bases.
Tim Varelmann 00:26:52 Ah, I see.
Sri Panyam 00:26:53 The cost of running all these agents would be really the cents, right? As opposed to hundreds of dollars.
Tim Varelmann 00:26:59 Yeah, that’s true. And one thing that comes to mind is a company called Palantir, which you might be familiar with because what they’ve done is they’ve worked and exploited the hell out of ontologies and ontologies are sort of the higher-level orchestration of many different models. So, at the bottom you have all these very specific models where you said I have this issue that they are not very generalizable, doesn’t matter. Because if you have multiple models that you can pick and choose from and an ontology tells you how to orchestrate them, when to pick what, that’s exactly what Palantir does and very successfully so.
Sri Panyam 00:27:31 Okay. Any details on how they might be doing this?
Tim Varelmann 00:27:34 I have no insights in mind. No. Like I never worked with Palantir. This is just likeÖ
Sri Panyam 00:27:38 No. Okay, makes sense. Go back to this AI models again, how would you then look at hallucinations, what do you think, I mean how would hallucinations kind of be influenced by optimizations or lack thereof or how optimizations may be applied, right? What could be the technical reasons behind where hallucinations come from and where optimizations might play a role in that or lack of?
Tim Varelmann 00:28:02 Yeah, so this is again back to the architecture of the LLM, which is deliberately made in a way that is non-deterministically and that is precisely what’s not happening in optimization, right? It’s very deterministically. You specify the equations that you want to be followed once, these are my thermodynamics, these are the parcels, the truck skills I have and I’m using these and then making my decisions based on them. Whereas with AI you want that for some other like creative tasks and stuff like that. You want that to be non-deterministic, then you just throw computer at it, you throw data at it, you throw data centers at it and you throw hilarious amounts of energy at it and the reside is often good enough. But if you want the guarantee, then I would argue you want the more specific models.
Sri Panyam 00:28:42 I’d like to jump towards a real world, I guess authorization problem, right? Would you like to pick a real problem that you worked on and walk us through step by step, starting from the messy kind of real-world situation and really, landing with something that was solved. Things like what were the district variables, what the constraints look like, what the objective functions were in this real-world scenario.
Tim Varelmann 00:29:04 Okay, I think I have a simple in mind. So, we are in the domain of optimizing inventory, right? You have a bunch of spare parts, and we can really just focus on one spare part for this spare part, the historical demand, which is uncertain, that’s another interesting property of this particular application. Also, in this case we have a multi objective application. Because on the one hand what we do is we want to minimize the storage cost. Obviously when you have things in inventory and that invokes some amount of cost, rent for the warehouse, people handling the stuff. But you also want to minimize your risk for stockouts, and you sort of have to tradeoff between them because if you want to minimize your cost, you would just say I have no storage at all. That means zero cost.
Tim Varelmann 00:29:50 But essentially every demand is a stockout. And on the other hand, if you want no stockouts at all, you need so much inventory that you can sort of never run out in 10 pound years, there will be a huge amount of storage cost. So, you’re really looking for a good trade off. And in this case the variable that you have is, when do we reorder? And you could in a simple way that, so for example, SAP does with the ERP systems that they provide, it’s just a reorder point. I’m sure Oracle does the same. You could put just some reorder point into that ERP system, and it’ll automatically execute a reorder once your stock goes below that reorder point. The second decision and decision variable that we have is how much do we order when we order? In this case we, this is the two basic decisions that we want to make.
Tim Varelmann 00:30:31 And really, you can optimize because you have multi objective optimization. You can do multiple optimizations, you can say, how do we tradeoff between cost and storage, in stockout risk. And then what I did in this particular case was create a visualization sort of a par front where on one axis you have the expected cost. On another axis you have the stockout risk. And that allows the businesspeople to really pick and choose, this is my risk appetite. So, because I see if I increase my stockout risk, let’s say from 3% to 5%, that gives a huge reduction in cost. And then going from 5% to 10%, maybe it’s not as favorable anymore. So, I’m sticking with 5%.
Sri Panyam 00:31:09 And how did you compute this; I guess curve of risk versus storage?
Tim Varelmann 00:31:15 There’s multiple ways. You could either sort of do a weighted calculation where you say, hey I have one metric for the cost, I have one metric for the stockout risk. And then I sort of do a convex combination where I say I have a weight and if the one weight increases, the other weight decreases and the sum of the two weights have to be one, then you can sort of generate a continuous curve. In this case, what we did was we just picked discrete levels of stockout risk, and we allowed the optimizer to say your expected stockout risk is 0%. Then you have this huge amount of storage that you have and obviously that’s not realistic, but then you can allow more and more stockout risk, you can allow 3%, 5%, 10%, and the optimizer may choose to go for a solution that is below that. So, the constraint is not larger than 10%, but maybe the optimizer finds, okay, if I have 9% stockout risk, that’s fine and I have found no improvement and then it’ll give you that solution too.
Sri Panyam 00:32:08 Was there some kind of model there to begin with where it said, look, if I choose this stockout risk level, let’s say 3%, here’s the amount of storage or cost I might need, right? What gave that, I guess was there some oracle that gave you that?
Tim Varelmann 00:32:21 No, so that is just a simple optimization that is not multi objective anymore. Because I took the second objective for stockout risk, I put it into a constraint. I said, you’re not allowed to do more than 4% stockout. And then the optimization is simply optimizing for a minimum amount of cost.
Sri Panyam 00:32:36 But isn’t there still some kind of objective function though? Because if I know. . .
Tim Varelmann 00:32:39 The cost, yeah, like the storage cost. So, because, sometimes when there is a demand spark, I get those little 3% stockouts. In the meantime, I have something in stock and sometimes it’s 10 pieces of spare parts, sometimes it’s 20. And that is sort of a trajectory over time of how much things do I have in stock and then they incur a cost for you and then you can minimize that amount of cost.
Sri Panyam 00:33:01 So there was some element of past data that suggested, points in history where x percent stock at risk, this is what it cost them is what this is what they’re in investment was.
Tim Varelmann 00:33:12 Exactly, so essentially, we said the entire model in this case was based on the assumption. If the future behaves like the past did in terms of demand, then this is your struggle risk. And obviously then you can manipulate that too if you want to say, from some business perspective insights, we have information that we expect the demand to go up by 20%, we will run the exact same model but just put a modifier 1.2 in front of the demand thing and run the whole thing. Again, that that goes back to, we have very specific models, but they’re easy to adapt. If somebody in the business says we have 20% more demand, it’s one number that I put in front of the demand, I multiplied with 1.2 and I can run the same thing again and it all works out of the box again,
Sri Panyam 00:33:49 You obviously made it sound pretty easy. What were the actual challenges at a time like for that I guess? Well, in that customer use case.
Tim Varelmann 00:33:57 The normal thing is, as I mentioned earlier, we work in iterative steps. So, to me that was not surprising that obviously in this case as well, some requirements only came up in the third or fourth iteration where people realized, oh okay this doesn’t work because it’s just when they see the solution, they see why it’s not working, but they can’t just come up with all of the requirements out of the head in the beginning. So that didn’t surprise me, but what really was the challenge here was not so much on the technical side, but rather the communication and this Pareto front that I developed for this helped a lot because it really visualized to businesspeople who are lay persons in the sense of mathematics, software engineering, whatever, or thinks technical but, a two dimensional plot is something they can look at and say hey, this is what I want and that’s where it really helped. Also, they had a lot of questions about why does this work this way? Can you explain this, the model explainable stuff like that.
Sri Panyam 00:34:44 Were there any other constraints that you had to add or was just these two?
Tim Varelmann 00:34:48 So the two things were just decisions that we had. There were way more than two constraints. You had for different parts, you have different amounts of lead times, sometimes you don’t know the lead time exactly, you have like some estimation, but you also know that this supplier is not maybe super reliable. So, you have to consider that as an additional uncertainty as well. The uncertainty is not just the demand but also the lead time and that influences also how far in advance you have to make the decision. Okay, we are reordering now even though we still have 200 parts in stock, but we know that over long lead times those 200 parts might be gone and therefore we are reordering now already. Just the handling, some parts are bigger, some parts are smaller, so sometimes you have different cost for the handling, which is just a one-time cost for each reorder and that sort of puts an incentive to reorder larger quantities but reorder less frequently if you have large cost of handing them once. Stuff like that. The other details that you can add here.
Sri Panyam 00:35:43 I guess, because we are so much in the AI era, where would you say the parallels are with techniques like gradient descent when you’re walking over this giant dataset for finding your optimized kind of solution or optimized kind of frontier?
Tim Varelmann 00:35:55 So gradient descent is a local technique. It goes back to do you want to jump on a hill or do you want to find the biggest mountain. Gradient descent can take you on to the highest hill and then you can look around and there is no single step you can make that improves your, that increases your height. Let’s say if you’re looking to maximize your altitude, when you do optimization and you really look at Global Optima, then you can say I’ve worked up this hill, I’m going back down, take a good night’s rest and next time I go someplace else and I do brilliant ascent again for example, and I go up in another hill. And if you do it in a clever way, you can sort of divide and conquer all of your search space and you can say from a hill because it’s a maybe a sunny day, you can see very far and you I’ve seen this region and there is no place to go that is higher. So you have sort of a big area that you have covered with just one hike and next time you go someplace else and maybe actually reach the mountains eventually and then you can look very far and you can make even better, the divide and conquer decisions because you can work so far and you eventually end up on the biggest mountain that you can find globally rather than just a local hill.
Sri Panyam 00:36:59 I want to kind of switch to some of them, seeing how we can relate this to some of the software engineering principles, how our audience kind of knows, right? I think you mentioned talking about clean architecture and a lot of surprises stemming from I guess questionable architecture in the past, right? So how do principles like separating your data from model logic, what kind of principles would you start applying in this pursuit?
Tim Varelmann 00:37:21 You mentioned a very important one already. Back in the eighties, I think that the domain of general software engineering has brought up, for example the solid principles and then other architectural, general principles that apply generically to all kinds of software. And as optimization models are just code implementations, really, they are no exception. So, if you look at solid is like an acronym for five principles and the first one is single responsibility principle, which is exactly what you referring to. You either have a module of the software that is responsible for storing data or you have a model that is responsible for specifying the physics, other kinds of modeling stuff that you want to model. And if you separate them properly, that makes a model just easy to maintain, easy to extend, easy to read also. That’s essentially what I’ve built my online course on because for optimization we call this algebra modeling, which sort of gets into the specifics, it takes those general principles and then goes two or three levels down in detail specifically for optimization, what that means. And a specific modeling technique where once you have this in place where you have separate data and then later on you have your actual models would be, you can say the data is how many trucks I have available.
Tim Varelmann 00:38:26 And that’s just a set of trucks. Let’s say you have a set of names that you put into the data section and then when you do the modeling you can say, I have a sum over all the trucks that are available and that has to have something, but maybe you’re doing shift planning and, in each shift, you need at least three trucks. So, you can say of all the trucks that I have in my fleet, at least three have to be on duty in every given shift. You can formulate that with just a sum, which can be just an operator, let’s say, and an operator that expands over a set, in this case the set of trucks. And that means if you do it in this proper way later on you have an extension of the fleet, the fleet grows from 10 to 12 trucks, you can add the two new trucks on the data side. And because the model is formulated generically enough that it just says, I have a sum that expands over the set of all the trucks, you have never specified the individual names anymore down there in the model part. So, all you had to do for this extension was just add the two trucks to your data set and the model extends itself. Very easy to maintain, very easy to extend.
Sri Panyam 00:39:24 I’d like to hear more about GASpy and how you founded it in the pursuit of algebraic modeling.
Tim Varelmann 00:39:28 So GASpy is the python phase of a company called GAMS, which is one of the earliest companies providing this algebraic modeling services. because obviously under the hood, when you have this operator that I mentioned, the some operator that can expand over sets, that is some kind of software that somebody has to implement. And GAMS is one of the companies that did that goes back to the eighties and they have roots even earlier, but they’ve been around for quite a while and they are really good at doing what they do because they have like four decades of experience, they’ve really gone down. They use a lot of graph theory to under the hood, make the generation of the model as quick as possible. So, if the expansion of that sum node that you have to expand eventually into all of the trucks that you have that as a developer you don’t have to think about, but somebody had implemented for you earlier. They do it in a very efficient manner. And yeah, two years ago or so I guess they came up with this Python interface because their language was very domain specific language that you could really see came from the eighties.
Sri Panyam 00:40:22 What’s an example of that eighties I guess look and feel.
Tim Varelmann 00:40:24 You have like options. They have strange names and really awkward syntax like slashes followed by a star and then you can put something in there which is sort of a declaration of the set names and then you have to again star in a slash to end the whole thing again. Just yeah, awkward syntax had to read code.
Sri Panyam 00:40:43 So they actually had interesting things within a comment.
Tim Varelmann 00:40:46 Yeah, I mean, yeah, nowadays it looks like a comment, but back then it was like meaningful things between those flashes and then and startups. Yeah, that’s what people did in the eighties, and they just stuck with it and focused on doing their core business under the hood until eventually they said enough is enough and we are giving this Python interface out. And that makes just things really easy because I mean Python, all of this heavy compute is not done in Python anyways, right? All of these things. Python is just an interface library really. And even if you look at PyTorch and all the machine learning things, the heavy computation is always done in C or C++ underneath. And Python is really just a wrapper to go into these things, but all of the data is available in Python, very easy to understand, it’s quick to start with and that’s why what makes Python popular?
Sri Panyam 00:41:31 So what does one of these Python files actually look like? Are these models that GAMs actually export but written in a more Python way or you mentioned the GAMS syntax itself is pretty quote unquote eighties right before syntax became more structured and cleaned up, right? So, I guess in a way somebody’s maintaining GAMS now and have there been efforts to kind of modernize GAMS instead of just providing a Python wrapper?
Tim Varelmann 00:41:56 No, like the Python wrapper is what they do with GAMSpy. So, it is just a wrapper where you have a nice API you have sort of this object-oriented feel. You can say object dot add variable and then you add the variable and the argument of that add variable function just takes a bunch of arguments the name of the variable bounds for the variable stuff like that type of variable if it’s continuous variable or discrete one. So that’s really what it is. It’s a wrapper and the hardcore is still under the hood and still plays a role. You just don’t see it from Python anymore.
Sri Panyam 00:42:26 Interesting. And typically, what does the things like the constraints and the solvers themselves are probably are actually probably under the, as far the GAMS engine itself. So, what does the Python interface for those constructs look like?
Tim Varelmann 00:42:38 You have this inline expansion right in Python, you can have like a list that expanse over, for all entries in some Python list, some iterable.
Sri Panyam 00:42:48 Like list comprehensions.
Tim Varelmann 00:42:49 Yeah, exactly. The nice thing is really just that you have this list comprehension now available inside of this GAMS API. So, you can use it to formulate constraints. For example, you can formulate a constraint for everything inside of your iterable.
Sri Panyam 00:43:02 Okay? Then you end up getting a list of constraints or list of iterable or on of constraints.
Tim Varelmann 00:43:06 In this case you have just created a GAMS model. So, you just, very early on in your code you say I want to create a new GAMS model that gives you a handle back to that model. And then on that model you, you call it this a constraint which you do inside of risk competition for example. So that means you’ve just added a bunch of constraints to that GAMS model, which is something that you don’t have to worry about under the hood that has these constraints.
Sri Panyam 00:43:27 Now where do you see this going next in terms of the languages, the tools, what’s available, what’s getting modernized, what’s next?
Tim Varelmann 00:43:34 Well there’s lots of things going on. I could think of decompositions becoming more popular, just because people always want performance. I could think of the ontology again so that you have the issue that you mentioned. We have some models that are very specific and we have other models that are more detailed or serve just different purposes and you might want some kind of orchestration that uses them in an intelligent manner. But the closest, like what what’s happening at the moment already is moving more towards optimization and uncertainty. We briefly talked about it in the example I gave you where the uncertainty was the demand of the spare parts, but you have it essentially everywhere in real world optimization. And if I look at the electricity case again for how to operate a battery depends on the weather essentially because the weather influences the renewable energy generation and therefore influences prices.
Tim Varelmann 00:44:27 And a battery operates like the way a battery is economical if it loads charges at cheap prices and then it can discharge and be paid for that at higher prices later on. So, with that difference, you can run a battery economically viable, but essentially everything is influenced by the weather forecast in this way because of PV generation, right? Solar and wind. And therefore, you need to decide if maybe next day we have a very windy day, we are going to have super high amount of very cheap electricity, maybe today let’s just sell everything we have, because we can essentially recharge for free the next day. It’s a matter of probability really. And that’s something that traditional optimization solvers had a hard time doing, but nowadays more frameworks are coming up to deal with this in a proper manner. So yeah, that’s what I’m also working on developing products for and I’m quite excited about it.
Sri Panyam 00:45:17 I guess, as we come to a close for software engineers who want to get started in this area, I mean, how do they go about this?
Tim Varelmann 00:45:23 Have a look at operations research, mathematical optimization, decision science. The field has many, many names and just get started with linear programming. That’s always an easy way not because the algorithm is so super relevant anymore these days, that’s all wrapped up in solvers that you can get off the shelf both commercial and open-source ones. But it gets you into the habit of modeling thinking really how do I model things in a linear fashion? And there are many tricks on how you can linearize nonlinear things too for people who want to go sort of from beginner to intermediate already. But yeah, that’s really where you can start to develop the modeling habit. Yeah, check out my blog. I have, my blog is really a collection of random things and one of the articles I have there is called Magical Optimization for Optimization Muggles or something like that. It’s a Harry Potter themed blog post. There is this little riddle in Harry Potter one. It’s only in the book but in the movie unfortunately. But yeah, it’s a logic riddle that Hermione can sort of solve because she has a great brain and I show people how to formulate this as an optimization problem and then we have some surprises in the article too later on. So yeah.
Sri Panyam 00:46:27 Awesome. We’ll definitely be mentioning these in the show notes as well. Is there anything that I should have asked but I didn’t, that our listeners would really benefit from?
Tim Varelmann 00:46:35 I think we’ve covered a whole lot of rounds. I’m very happy with the episode.
Sri Panyam 00:46:38 Tim, thank you. This has been a very, very enlightening topic for all of us. I know it’s so much going on, it’s hard to kind of get into things, but your thing was really clear and detailed for us to kind of, I mean there there’s so many threats for us to kind of go and grab, right? So, thank you and looking forward to learning a lot more. Will you be talking or presenting anywhere that people should be aware of?
Tim Varelmann 00:46:56 I have a talk that, is coming up pretty soon. Probably the recording will not be out by then. Other than that, just for the future, people can look me up on LinkedIn where I’m active and I have a newsletter. It’s called blue briefings. So, any news will always be broadcast there, if people don’t want to miss anything in the future.
Sri Panyam 00:47:12 Thank you very much, Dr. Varelmann. It was great having you here and looking forward to following your work more.
Tim Varelmann 00:47:18 Awesome. Thank you.
[End of Audio]



