We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Keeping the Lights on with Python

00:00

Formal Metadata

Title
Keeping the Lights on with Python
Title of Series
Part Number
123
Number of Parts
169
Author
License
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Scott Reeve - Keeping the Lights on with Python We are using Python to help the National Grid in the UK to balance electricity production and usage. We do this by installing Python powered devices at customers sites that allow us to monitor and set control criteria to automatically turn on and off power consuming and producing devices when there is a mismatch between electricity supply and demand. In this talk we will be talking about how and why we have used Python, as well as where in our system we would like to use Python. ----- We are using Python to help the National Grid in the UK to balance electricity production and usage. We do this by installing Python powered devices at customers sites that allow us to monitor and set control criteria to automatically turn on and off power consuming and producing devices when there is a mismatch between electricity supply and demand. These devices talk to our Python powered cloud based system using the 3g network, giving us near real-time monitoring of our customers assets. Our entire infrastructure is written in Python, from our billing systems, data analytics systems and customer portal all the way through to our on site industrial system interfaces. In this talk we will be talking about how and why we have used Python, where we have had problems, as well as where in our system we would like to use Python and why we cannot. We will also be talking about what we are going to do next, moving our system from near real time monitoring to near real-time control, using Python for both system modelling and control. We will discuss how we are using Python to creating a system that monitors the balance between electricity supply and demand many times per second and is able to provide a corrective control based on the sum of the output of a dynamic set of our customer sites and the challenges that presents.
11
52
79
DemonRed HatUtility softwareHydraulic jumpService (economics)Execution unitFrequencyDisintegrationElectric power transmissionPhysical systemUtility softwareComputer architectureBitQuicksortAssociative propertyDifferent (Kate Ryan album)Food energySoftwareSlide ruleType theoryProper mapWorkstation <Musikinstrument>Factory (trading post)System programmingService (economics)Scaling (geometry)Chemical equationProduct (business)Line (geometry)Electric generatorLogical constantArmProjective planeGenderHydraulic jumpComputer animation
1 (number)Structural loadFrequencyFeldtheorieVelocityWater vaporField (computer science)Diagram
FrequencyShift operatorRing (mathematics)System programming3 (number)Fluid staticsAerodynamicsProduct (business)Dependent and independent variablesThresholding (image processing)Continuous trackEwe languageSoftwareDiagramMetropolitan area networkMalwareComputer configurationFormal languageReal numberComputer programGame controllerSoftware testingSummierbarkeitLevel (video gaming)VibrationFrequency responseDependent and independent variablesSpectrum (functional analysis)MereologyData loggerEvent horizonProcess (computing)FrequencyResponse time (technology)System programmingComputer programmingWebsiteDynamical systemResultantCASE <Informatik>Computer hardwareCondition numberPoint (geometry)Arithmetic meanElectric power transmissionQuicksortState of matterSocial classSystem on a chipParticle systemMathematical analysisProfil (magazine)Game controllerMixture modelFront and back endsSoftwareRight angleCodeSoftware testingPresentation of a groupVariable (mathematics)Single-precision floating-point formatPlastikkarteMetreSet (mathematics)Type theoryAsynchronous Transfer ModeRevision controlDiagramGoodness of fitPhysical systemComputer architectureTrailProduct (business)MicroprocessorTerm (mathematics)Software developerLogicFactory (trading post)Electric generatorMultiplication signTask (computing)CoprocessorNeuroinformatikStructural loadMassNatural numberMathematics2 (number)Group actionLibrary (computing)Moment (mathematics)FreewareSelectivity (electronic)Flow separationModemDebuggerMeasurementQuadrilateralGraph (mathematics)Different (Kate Ryan album)InjektivitätFunction (mathematics)BitMusical ensembleDirection (geometry)Hand fanComplete metric spaceCommunications protocolDiagramProgram flowchart
Moment of inertiaCASE <Informatik>Dependent and independent variablesBitInformation securityFrequencyWebsiteComputer programmingDynamical systemSound effectInstallation art10 (number)Electric power transmissionScaling (geometry)Structural loadSystem programmingTerm (mathematics)AreaFactory (trading post)Protein foldingVibrationPhysical systemBlogInstance (computer science)Network topologyType theoryMusical ensembleMereologyLecture/ConferenceMeeting/Interview
Transcript: English(auto-generated)
Welcome all to using Python to give the last one. Give Scott some clapping. So this talk is really about, well, I guess it's more of a celebration.
The last talk was excellent about the architecture and such. I guess this is a compliment in that we talk very little about the architecture. But it's more about talking about the problem that we're solving and why we like using Python so much to solve it. So I'm the technical director at LimeJump. We've been going as a company proper for a couple of years.
Next slide. So LimeJump is a utility in the UK. We're able to trade energy. And the thing that we're interested today in is aggregation services. We're going to talk a bit more about that in a minute. But we work with small companies in association
with National Grid. So the National Grid in the UK own the High Vault Electricity Network just for England and Wales. And they work to maintain that. And also they try to keep supply and demand of electricity balanced. And that's kind of where we come in.
So if we go back to 1870 or 1933 in the UK when our first national power network was created, you had big, mostly coal powered power stations that created a large amount of power
which was then distributed through high voltage lines across the country going into lower voltage lines, eventually down to big factories, smaller factories and consumers. Now that worked well back in 1870 and 1930s. But things are changing now.
We've got concerns about climate so we don't want to have big coal fired power stations or other big stations for that matter. And there are new types of power generation coming in like wind, solar generation, we've got some wave power and other things like aerobic digestion where you use waste food products and animal manure
to generate gas which can then power engines which produce electricity. And we've got landfill gas which is methane coming off waste to produce electricity again. And just now things like batteries are coming in. So the power network has to change
to meet these new challenges. So this is the kind of thing that we're starting to see. So we're getting a much more distributed power system. So you can see some solar panels and some aerobic digestion there and all sorts of different ways of producing power. And they're working on a much smaller scale.
The amount of electricity they generate is smaller. They don't come down these high voltage lines so much as more local systems. So we need to start controlling them more locally to balance the grid. But really, what do I mean by balancing the grid?
So if you think back to the original power stations, you had a big coal fire boiling water up, turning it through turbines. That would turn a huge shaft and then you go back to your magnetic field theory.
If you turn a shaft and magnetic field, you can generate electricity. And the speed of that shaft is proportional to the frequency of the AC current you get out. So what we're trying to do is to keep this shaft moving at a constant velocity so we get 50 hertz out. So what we have to think is if there's too much load
on this shaft, say you've got too many lights on, or for example, a power station is broken down, then this shaft is gonna start slowing down because there's not enough power to push it. The frequency of electricity will go down and vice versa, if it's the middle of the night and no one's really using electricity
and suddenly the wind starts growing very strongly in Scotland, as happens sometimes, you get too much wind power. So there's more supply than demand and the frequency starts to go up. So that's kind of summarized here. So when supply is able to demand,
which is where we want to be, everything is at 50 hertz. And then as supply is outstripped by demand, the frequency goes down. And when supply is higher than demand, then the frequency goes up. And really what we're trying to do is to keep it within 49.5 and 50.5. In reality, we keep it in a much tighter band than that.
But when we start getting to these points, then we start having problems. Electronic equipment will stop working in some cases. And if things get really bad, you'll get a complete blackout and that's really not what we want. So that's where we come in. So as I said earlier, the National Grid's job is to balance supply and demand.
So they have products which we work with customers. So we work with lots of small customers who aren't big enough to go to the National Grid directly. So we coordinate their response and then sell them as a group together to deliver different products to the National Grid.
The one we've been working on for the last year or we've been starting to implement for the last year with customers is a static response. So when things are getting quite bad, so when frequency goes down to 49.7 or up to 50.3, we either get customers who produce electricity
to turn things on if the frequency's gone low or if they use electricity, we get them to turn things off. And vice versa, when the frequency of the grid goes too high, we get people who produce electricity to turn their production down or customers who use electricity to turn their usage of electricity up.
I'm going to touch upon this a lot more and how we do that. But then also in the future, we're going to be starting to look at things like dynamic products where we track the grid frequency so we keep it in a much tighter band and you get two seconds to respond to a change in grid frequency and then enhanced frequency response which is responding very quickly
and that's coming out in the future in the next one to two years. And there you have to respond to a change in grid frequency within one second, so the only thing capable of doing that at the moment is to have a big battery and to turn the power output from the battery up and down. So what exactly do we do and where does Python come in?
Well, because we're working with lots of small customers, we have to go and install a panel on each of their sites so this sits with generators or with factory equipment. And we have a PLC in there, a Programmable Logic Controller which is an industrial computer effectively
that you can use for automation tasks. We have data being back for the 3G modem. We have a quad core, it's a Raspberry Pi-type device where all our Python sits at a customer site level. And also we're starting to use things like Arduinos to control and measure customer equipment.
And also we have power meters which sit on the power lines out of equipment so that we can measure what's going on, how much electricity they're producing. And we do this, we monitor power every second so we can see second by second how much power a customer is producing or using.
We measure frequency on site so we know what's happening in terms of frequency on site 10 times a second and we also measure what our system is doing 10 times a second so we can keep track of whether everything's performing properly. Now, for those of you in the last talk,
this is a very similar architecture to the one being discussed in the last talk. I'm not gonna talk about it quite so much. Other than to say that the data logger there is pure Python and everything, to the right of it is also pretty much Python except the front end stuff.
And everything to the left of the data logger so the sub-meter controllers and PLCs, they're in a mixture of C and PLC code, which I'll show in a second, which is some ladder logic and some programming by diagram, really. And then we've got industrial power meters which we communicate through a protocol
called Modbus from the 1970s. So we've got those connected to assets and we can also control assets from there. I should also point out the data logger doesn't just log data, it also sets up the PLC so we can have a semi-autonomous response to events.
So the PLC is the part that responds when frequency goes out of the spec that I was talking about earlier and it's also the PLC that controls the output of an asset if we were to want to do dynamic or enhanced frequency response. So that's kind of how we do things. Why do we use Python?
Well, it's fast to develop. This has been developed within two years, really. I think we've written virtually everything that's in production now within the last two years, which I come from a C and C++ background. I don't think we could have done this if we'd used C. There's a huge selection of free libraries.
I'm preaching to the converted, I guess, with this, but it's transformed the way that we can do things, especially with things like Modbus and the testing. I'm a big fan of pytest, so we use pytest in all our testing and I stay lastly, we use Python, so I can come to EuroPython each year.
So where have we been having problems with Python? That's a good question. We haven't been having massive problems with Python. We've been moving to asyncio recently and we've cut down our load on our embedded processes,
the processes of the customer sites by five, tenfold by using asyncio, so that's been really great. We think it's not quite as elegant as it could be, but that seems to be changing a lot with each new version of Python, so we're really enjoying using that. But I guess the biggest problem we have is finding good Python developers in London
which I'm sure lots of people can sympathise with. So that's kind of really our problems or things that we've been using. Where would we like to use Python? Well, as I said before, I like to talk yesterday on the micro bit and starting to use Python in microprocessors.
The diagram on the right is part of the PLC software that I was talking about earlier. I've spent days and days with our PLC suppliers debugging this software. It's tricky, it's very, very tricky. This is the kind of code you get.
You can't put test harnesses around it very easily, so you end up having to try and create every single situation by a mixture of forcing variables within the program and creating the conditions with IO and hardware to try and test it. It's going to respond how you want it to respond in each way.
So if anyone has any ideas for getting us out of using PLCs, then I'd be really, really pleased to hear them, especially if it's using Python. I'd also say we've been using embedded controls with C, but again, that's not quite as nice in my opinion anyway.
So what are we going to do next? This is a test case from last week. I spoke about dynamic frequency response. So if you look at the second graph down, you'll see this is a test profile we've injected into one of our panels. This is a battery site.
So this is a big solar panel array with a 800 kilowatt battery attached to it. So the battery is charged up by the solar array during the day, and then we can discharge it when the customer can get the best prices for electricity. So what we've done here is we've got a charged system. I should say SOC stands for state of charge. So 140 actually means 70% charge
because there's two battery systems attached. So what we've done is inject different frequencies into that, and if you look at the top one, the kilowatt out, so that's the kilowatt output of the battery, mirrors the frequency. So as frequency goes down, the output of the battery goes up and tracks pretty much the frequency
as it goes up and down, and you can see the battery discharges and then charges again as we use the power in different ways. So once we've done that, our next job is gonna be delivering dynamic response, and which I haven't mentioned now, this is response at a local level. So this is just a battery responding to the grid.
What we're looking to do next as well is to have a response across several pieces of equipment. So we might have a engine and a battery, maybe solar farms as well. And what we're looking to do is have each one of them produce their own individual response,
which when summed together, creates this kind of group response. This means that a lot more customers can get involved in this program and we can give a larger lump of responsive power to the national grid, so it kinda helps everyone. And let's do some more Python as well. And that's it.
Who has any questions?
Thanks for the talk. At what kind of scale is this running? How many of these devices are running? So we had our first site installs last year. We're now in the tens of installs. Probably by the end of the year, we'll be moving up to hundreds of installs and on from there. In terms of power, sites range from about 100 kilowatt
for small sites up to a couple of megawatts for big sites. So if you compare that with a power station, a power station might be 1300 megawatts. So we're rising very quickly. So it is getting bigger and bigger.
I'm not sure if I understood this correctly from what you said earlier, but is it the case that when demand falls so much that the frequency is at risk of rising or demand rises and the frequency is at risk of falling, that you will get large users of electricity
to use more or less? Yeah, that's right. And is there a possibility of doing this? I guess you can do that very easily with huge users, but with embedded systems in all kinds of devices in people's homes, you could presumably get ordinary things like fridges
and heating systems and so on to use more or less appropriately. Is that a possibility? Yeah, yeah. So we've started the industrial scale because it's easier to have a viable business at that scale. But as we refine our technology, we can move into smaller and smaller producers. So in the end, hopefully, yes,
we'll be able to use home supplies. So if you think of a fridge, for instance, a fridge is only on some of the time, but if you had 1000 fridges, you could predict the base load that the aggregated 1000 fridges use. So yeah, yeah, that's definitely what we're aiming towards.
How much was security a consideration? Because I could imagine if these systems are hacked, you could destabilize the power grid pretty easily. Yes, because security is a big consideration, yeah. So yeah, we can turn on and off these big batteries and engines. So yeah, that is something we think about a lot.
Yeah, I don't want to talk about that a bit too much. Yeah. So is it the case that when the frequency drops, you respond, but what happens if you respond and somebody else responds and somebody else responds?
Isn't there a risk? How do you not like yo-yo? That is very true, actually, and has happened. So we're all employed by the national grid, so they know how much the response will be. So they contract out a set response, but you're right, it has been seen on a few occasions
where everyone responds at once, and you go from having low frequency to having high frequency. So yeah, that's one for the national grid to sort out, luckily. But that's why they're moving to the dynamic responses, because of course, they're much more granular, so they correct things much more quickly, so you don't get that yo-yoing.
I should probably also mention that when we're moving away from these big rotating shaft-type systems, the power generation, the coal-fired power stations, we're losing a lot of inertia in the system, which is a stabilizing effect. So a big shaft turning acts like a flywheel, whereas with things like wind, they don't have a flywheel as such,
because they're electronic-inverted. So yeah, as the UK reduces that, we're gonna become more unstable, so we have to be more careful to stop this swinging up and down a frequency. Any more questions? Great. Give. Yeah, I'll answer questions if anyone wants afterwards,
or, yeah. Cool. Yeah.