Devreal

Quantum Computing and You

Event: Scale by the Bay

Scale By The Bay 2018: John Azariah, Quantum Computing and You

Recording: Scale By The Bay 2018: John Azariah, Quantum Computing and You

you so you all must be wondering what in the world a quantum talk is doing in a scholar conference when you find out let me know because I have no idea why yeah just kidding so I'm John Ezra I am the principal architect at the Microsoft quantum team amongst the many things that I've done there I actually helped design the Q sharp programming language which is a DSL for design you know developing quantum algorithms and programming quantum computers so the Scala connection you'll actually see that a lot of the interesting things like the type system and so on and so forth heavily influenced by languages like Scala so even though the language is by definition not purely functional in fact it cannot be purely functional and we will see why there's a lot of functional influence that comes from it so you'll recognize some very interesting things from the Scala world natively in the language I'm assuming that not too many people here do quantum computing for a living I know that that that is actually and pleasantly surprised that that number is not zero in this talk we actually have colleagues constantly who will be giving a talk at 1:10 also on quantum computing right here and he's of course you know distinguished engineer in his field so if you have any deep quantum computing questions save them to 110 and ask him right cool so that said I want to just basically you know introduce you guys to quantum computing a little bit so hopefully at the end of this you may get a sense of why you need computing boy is it different might actually look at a piece of code and maybe we can actually see if it works how about that right so why quantum computing first off right and this part probably you guys know because that is actually an interesting problem a few months ago if you could factor that into two prime numbers you could have net yourself $700,000 there's a reason why it's so valuable it's actually because it's actually very very hard and the reason why it's hard is actually why we have economy the way it is today our entire system of economy is based on our encryption and the encryption is based on the fact that factoring that number is actually really hard so much so that might take you some time to get a result right the goal of quantum computing though is to drastically change the approach in which you take to try and solve that problem and try and get a number like that so we go from a billion years to a couple of minutes right this is not going to be the case for every problem out there they're very specific problems as we are going to find out in the talk for which you get this kind of a quantum advantage and we want to find out why it is that way and what we're doing about it and how we can actually get there right so why is it that way well in 2003 well the red line over here there's actually red line I don't know if you guys can see it but there's a red line there which kind of is the 2048 bit RSA factoring a problem right if you took a cluster back in 2003 and ran it you would be well beyond billion years to solve that problem the state-of-the-art clusters now can speed things up drastically but it's still a trifle slow and you can see a trend now already so probably in about 20 years when you look at this thing again what do you expect to see you expect to see the same shape of the curve moving to the right and that's if most law holds out right and that's not going to be good enough if you want to solve the problem that way so quantum computing is is is about breaking Moore's law in terms of this application of it in any case it's about changing the way in which we do things so drastically that Moore's law actually doesn't apply at all and you actually get a curve that looks like that and on a gigahertz machine you can talk about solving the problem in a couple of minutes right let's go with another application up to about a well the slide is a bit old up to about two months ago that was the fastest computer in the world in about a couple the last couple of months there are two teams in the u.s. that have actually taken that slot so now that's the third fastest computer in the world it's still no slouch but if you wanted to actually figure out why chemistry works the way it does how do molecules actually behave you can kind of work on modeling my favorite molecule in the world and you guys have been here like the first session after the party so you are the faithful ones you must have had some of that too right but there's an interesting little molecule which we actually depend on which we encounter in life and many many molecules like it that are actually not possible to simulate on a classical machine they pay close attention to this ephemeral code thing because I'm going to tell you why that's actually very profoundly impactful molecule why it's actually useful to know about it why we can't know about it classically and how quantum mechanics is going to make it possible for us to understand and that should give you a sense of context of what the application of quantum computing is so at the very least the initial hype of what it does should be dispelled from you you should understand a little bit better that's more than just the hype and the the the range of applications is actually relatively small right and the method of programming is also relatively different from from Jerry Bob is computing why is this difficult well let me explain what that molecule is till about 1911 if you wanted to farm you had to use organic fertilizer because there was no industrialized farming right and one of the sources of organic fertilizer was basically animal waste ammonia from animal waste and what that does is try to fix the nitrogen in a way that the plant can actually consume and actually grow with but any gardeners among you will know that you'll get the same kind of effect if you plan to field beans right because what's happening in the field of beans is that there is actually you know some parasitic nodules on the root of the bean plant right that don't actually belong to the bean plant but they just grow on there and in the cell membranes in those parasitic nodules there is a bacterium called nitrous amass back there and nitrous or Mars back there performs this almost impossible task of taking atmospheric nitrogen cleaving the nitrogen nitrogen triple bond bringing water hydrogen from water and making ammonia and fixing it into the ground leaving the ground move for a Tyler all right now in 1911 two German gentlemen decided to figure out how to ammonia and they embarked on this enormous ly expensive process to heat air to very high temperature put some serious catalysts and there and you know do do do stuff with water again to try and get ammonia going and they figure out the Bosch able process and that process is still in use today so chances are that anything you've ever eaten before in your entire life was impacted by industrial fertilizer that was built made using portable process and the Bott Haber process consumes four percent of the entire energy output of the world okay so the the impact of replacing nitrogen from an industrialized source with a natural source like this is enormously profound profound at many many levels because economies change you don't have to be you know rich country to spend energy to make fertilizer to feed you people you know everything really there's knock-on effects that have profound impact so you must be asking why can't we actually find a way to use the process that is happening in nature to generate the ammonia and the answer is we don't know how we don't know how it works we don't know how that molecule works and the reason we don't know how that molecule works is because it is very complex it has a transition metal in the middle of this core and it has about a hundred and seventy electrons that perform all kinds of interactions to define the behavior of that molecule now if you studied basic chemistry you'll realize that you know if you can model how hydrogen or you can model why hydrogen is of a particular size or why water has a particular shape by looking at the way in which the electrons in hydrogen and what an oxygen interact to form water why the angles are going to be the way they are and how that impacts how reactive that molecule is and so on and so forth this is the ab initio chemistry right the moment you get a transition metal in there it becomes really really difficult because the number of electrons that participate in the in the in the intramolecular reactions is very very large and to take an idea of how its how difficult that is I'll put some scale in perspective for you so basically nature uses quantum mechanics to do this stuff right and really our idea the whole idea of quantum computing is to use a natural process to simulate another natural process that's effectively how we are going to solve the chemistry problem we're going to take something that does the difficult math for you how difficult is the math well it turns out that if you want to describe how an electron behaves that's a wave function you need two complex numbers to actually describe that to describe how two electrons interact with each other you need two to the two with complex numbers to describe the problem if you want three electrons it's two to the three if you want n electrons it's two to the N so you need two to the n complex numbers to just describe the problem that's the order give or take right by some constant factor that molecule ephemeral code that I showed you has a hundred and seventy electrons in it okay let me put that in perspective because that number is kind of large right at about 2 to the 50 you kind of reach the scale of data that Facebook stores and about two to the hundred and fifty you kind of have a look an idea an idea of how many atoms there are on this planet okay at two to the hundred and seventy you need a million planets this size to just write the problem down if each atom on it stored a complex number so now it should be dawning on you that you're going to land up needing a little bit of a different approach to solving the problem right because we can't actually take the standard linear algebra approach of using the complex numbers to actually solve the problem right and this is actually the root of the problem so now if you can actually take the electrons because obviously you know nitrogenases around from of course in nitrogenase nobody told the femoral molecule hey the math you're doing is too hard right it's just doing the math so if you flip your your perspective around a little bit one way to actually think about the problem is to say hey that that molecule is already doing the heavy math so if I can find a way to solve my problem or craft my problem in a way that I can express it in terms of how the molecule is doing its thing then I can get it to do the hard math for me and in some sense that's exactly what quantum computing is it's trying to craft your problem in the space of a quantum mechanical phenomenon trying to get the quantum mechanical phenomena and to actually express the problem you're trying to solve keep the pros that get the solution from there and then get it back so if you think about it it's really like a coprocessor if you want to think about it that way but this is a functional conference so let's talk about let's talk about what kind of coprocessor that is in a minute right so the quantum future basically looks like this you know if you think about many many many many molecules that we commonly encounter are too difficult to actually process chlorophyll is one of them hemoglobin is another all of these things have profound impacts material science allows us to actually think about building solutions that if we understand how super conductivity works maybe build room-temperature superconductors I would change everything so there's a whole bunch of applications that are very very profound right but how does it work and how why is quantum computing weird right so let's let's let me introduce you guys to quantum computing I hope oh you guys role geniuses you all know Matt's right so let's talk about binary operations who can tell me what that is not get bigger or not get right what does it do it takes 0 to 1 and 1 to 0 cool now I'm going to do something slightly different I'm going to treat the bit as a vector right so the zeroth bit the zeroth value in that column vector is a 1 and the first value in that column vector is a 1 right and now if I want to represent a not gate I could create this matrix which when I multiply with 0 gives me 1 and then if I multiply with 1 gives me 0 Hey they lost anyone no good so really what we're saying what I'm trying to tell you in a very sneaky way is that everything you learnt about abstraction from a classical computing point of view until now was 0 is the presence of charge 1 is the absence of something or the presence of something or the other the way in which some areas magnetized right and you thought about zeros and ones at way right you thought about the abstraction as if there's a current treated as a 1 if there is no current treated as a zero and so then you built your entire you know programming model on top of that well actually that's a sugar-coated lie right because really what's happening is this thing underneath it from a mathematical abstraction point of view it's really linear algebra that's going on right your programming model is still valid and consistent but you can model it mathematically now it's completely abstract has no physical representation from that point of view right so you're looking at me somewhat quizzically but just go with me here right you don't really what I'm trying to say is if you were an alien you didn't know anything about a like electronics electrical electricity or magnetism you could still derive binary logic and the entire computational model that we have right that's a fair statement so ever okay okay that's all very good for one bit what do we do at two bits well I'm going to introduce this concept of density which when you take two matrices and you tensor them it gives you another matrix that basically has the twice the values so exactly like this when you take zero tensor with zero then this one goes up there this one comes here this one goes there this one comes here standard automatic but now you should get start getting a little worried right because I look at it from this point of view to represent n bits now we're not talking about taking a shortcut of representing in bits in a string and trying to do something all of a sudden I've got some crazy kind of nonsense going on here where I double the value or double the size of the space every time I do something to it right and you might be wondering why I'm taking you down this path but this is kind of important to not understand the linear algebra on n bit spaces is hard it's precisely because the space is huge so if you want to think about going back to that RSA problem to begin with the reason why it's hard to factorize that number is because the stuff that you're doing to it is it actually operation is in a very very high dimensional linear space and that is necessarily hard we're depending on the fact that it's hard right but I don't like keeping adding that down so I'm going to give you a little shortcut notation this thing is called Dirac notation and you can basically treat it that way so zero so now we're back to the familiar bit string this would be the bit string that you know you're talking about but it's a notation that we can kind of use to to to shorten the way in which we talk about stuff all right so your unease must have come down a little bit by now let me make you more uneasy now what happens if I make that number of complex number right so at the moment zeros and ones are all real so what that means is they're on the real line and to me all that is is that it's actually a special case of a complex plane where you haven't left the axis but the math still holds right I can still do that and I can still do the same matrix multiplications on that complex number and get back the same results but here's the fun part what if I told you that there are more numbers than zero and one that you can compute with right so imagine I took a single a single value that could be either a zero or one so far all you've been happily working with is the North Pole and South Pole of this thing right and zero and one have this interesting property that the length is one so if I now look at all possible complex numbers whose modulus the length is one it would actually be fear in four dimensional real space right each point over there this this is kind of cheating on this because these two don't have an imaginary piece so we're looking at just those two ends of the sphere and we kind of come up making ourselves happy but a point over here on the equator if you want to think of it like that actually has a complex component what do you think happens when you apply the same matrix to a point over there it works not still does the right thing it flips the if it still flips the values up and down the way you expect it to right so if I did that I took a state that had alpha and beta I said it to be that way then when I ran the matrix on that he would actually flip alpha beta 2 beta alpha which is exactly what you expect but now let's look at it a little bit more there are more operations that I can do on this as well so far all that I have had is the one not gate which basically took the North Pole to the South Pole South Pole to the North Pole but there's a whole ton of matrices that I can now apply on this thing that effectively take a point from anywhere and move it to any other point on that sphere now imagine I had a big beach ball over here and I put a dot on one side of the beach ball and wanted to take that dot somewhere else what would I have to do to the beach ball to make that happen just rotate it so it turns out that all the matrices that they actually operate on qubit space are simply unitary rotations they don't change the size of the matrix because they're still at the surface of the sphere but now I'm rotating it all over the place and then I can do all kinds of computations with those rotations right and here's the weird bit now about quantum computing you can't ask the beach ball where is the doctor because if you could you would basically need to be able to represent a you know an infinity number of values in order to be able to represent that information the the beachball knows where where it is but when you ask the beach ball where is the dot it probably Stickley collapses the dot to either the north pole or the South Pole based on how close it is to either of the two and tells you it's at the north pole or the South Pole and now I can get back one classical bit from something that used to represent an infinity of values okay and that in some sense a very very hand wavy very literally hand wavy explanation of superposition that's actually what it is just so long I will I will table your question to the end so let me show you this and this effectively means that you know the the vectors are going to be of the same size they're all one and you can do the transformations we've already met this guy these are not gate but now you can do things like flipping the face the Z gate or rotating in a different way or taking something on the North Pole and moving it to the equator right and or rotating it by any random angle right and all these are valid operations now on the quantum representation as in the the the same space that you were talking about for classical machines but when you added complex numbers in there rather than just real numbers you can actually do a whole whole lot more and as we've seen we've seen the representation of it and this superposition right so because it's on the equator what what actually happens when I measure it well it either comes back to the north pole or the South Pole but it's on the equator so which one is it more likely to come back to equally they both equally likely so it's just like a quantum coin flip right it's like a quantum coin flip but different because I'm going to show you this is where stuff goes really really weird and I'm going to show you that bit in code this is think about the quantum coin flip just hold down the back of your mind we'll come back to it and take a look at what makes it weird okay but first off what does a quantum computer look like it does not look like that that is a fridge a quantum device it's the very very bottom of that fridge and remember how I told you that when you have to a harness quantum mechanical phenomena you need to somehow make it so that it's able to actually represent problem you want to represent and one way of doing that is to remove all interaction with its environment ideally you want to remove all interactions the environment except for the time that you want to measure but that's actually near impossible to do because any interaction of the environment is effectively measurement right but one way to get there is to kind of chill the thing down how cold well the warm end of it is at 300 Kelvin we sit there with a very sweater but I sit there and write code right but then we send the instructions down to control hardware that sits at about 4 Kelvin because CMOS kind of still works at 4k high right and down at 15 milli Kelvin or so which is 15 thousands of a degree above absolute zero you'll end up having the situation where stuff starts slowing down and behaving in a way that you can actually sort of harness the quantumness of it there are many many techniques to actually get qubits the actual bits the transistors if you want to call them the equivalent of transistors in quantum computing there's very many just to get cubits that'll actually show you the behavior that you have of being able to do superposition and entanglement or all the other kind of fun stuff they do right but basically Microsoft working on trying to build the whole stack and my contribution along with my team is to sort of build the language in which you can write the code to run on the quantum computer now this is by necessity like a coprocessor and remember how I told you this is a functional conference and you'll never figure out what kind of coprocessor it is it is in the truest sense a monadic coprocessor because you actually cannot look physically at the data inside the quantum space at all by doing so you will destroy the data that you have so it's only natural that any language that prepares to actually sequence instructions to this space you have to design it with that in mind and then lean on your traditional functional programming experience to effectively build a muriatic sequencing approach which is actually exactly what q sharp the language does so if you actually look at Q sharp and you look at the value of a qubit it doesn't exist at all qubit is just a opaque identifier of something in there that will do the rotations and whatever it is for you and now you write sequences that effectively get translated into hey please rotate this by PI over 4 or whatever it is and then you trust that the thing in the quantum space is actually done what you needed to do so it's a it's a physically realized statement how cool is that right now this whole thing obviously the language in which you express what you need to do to the qubits is very different from the language in which you're actually writing the rest of the code so you can write your your code that runs on the classical machine classically and just like you write CUDA code but instead of writing it in C++ where you'll end up having pipe conflation and all of this other stuff or indeed Python where the the types of the stuff that you want to do the operations that you want to do on the quantum device actually collide with the types that you're describing the quantum computation in we created a completely new language with a completely independent type system that allows us to reason about the cue shop code and optimize it so now we can look at it as the inside of a scholar for comprehension but instead of just running it we have access to that code we have a compiler effectively that looks at that for comprehension says hey you're applying these two rotations then it's really equivalent to not applying anything at all so I'm just going to remove those two and the closest you'll get to is kind of like a free monad where you can actually look at the sequence and then try to do some optimization on it but this is so much more because you actually need whole program optimization which you can't do with the frame all right right and that's kind of why we've done what we've done so if you go down and get the quantum development kit you can actually you know get the simulator which does the linear algebra for you with the quantum numbers and everything and on a decent laptop you can get to about 30k bits on a cloud solution you can get about 40k bits right but everything gets doubly slow and doubly expensive at that point for every qubit that you add right so at some point eventually you will get the quantum hardware so the simulator and as your simulator basically do the thing using traditional math and the quantum hardware will eventually do something interesting with the actual quantum device so I recognize a couple of electrical engineers here so this might actually go over well with them this diagram is actually traditionally how we used to define circuits for doing quantum computations so each line over here going up to down is a set of qubits and from left to right is time and you have the various operations that you want to do on each qubit and it turns out that if this circuit is actually very popular it's the circuit that takes values from one qubit and makes the other qubit the same as it as the first qubits value and the reason why this is important is because there's this mathematical theorem that says that you can't simply say let equals B you can't say here's my beach ball with a dot at some abstract location give me another beach ball with the same dot that's actually a forbidden task you can't do it but if you can if you want to make second beach ball have the same dot you can do that by destroying the information on one side and having it teleported over to the other this how obviously has limitations from a programmatic language perspective you can't do things like loops and so on and you can't parameterize by the number of qubits so you can't say okay teleport for qubits and then you have to have a completely different circuit for doing that well it'd be nice to write code that allows you to do that kind of thing and in fact that is Q sharp code it might looks familiar we put the braces and everything in I get I get shouted at by Haskell people who are doing that but I left sharp people but this is actually quite familiar familiar sort of topology for writing code and you know there's a strong argument for why we need a custom language versus using you know a library with an existing language and so on and so forth but I suspect that this graph probably won't mean as much to you and I'm probably running out of time I don't know how much time do I have I've brought in Mitch cool so maybe I'll show you guys some code about that in the tendency there you go now just suffice it to say that that I think given the fact that we've kind of talked about why the whole program analysis is kind of important you'll have to realize that the only way to do it is to have your own language which basically allows you to pause and compile the whole thing do the optimization and knowing full well that everything that it's doing is running inside this context of monadic composition on the quantum state Mona right okay let me show you guys some court oh by the way the the FB stuff is you get immutability first class functions partial application using techniques that are non Curie based so all functions in in Q sharp are tuple into to pull out so we don't care about the arity of the tuple function is always double into to pull out so you can pre-fill half a tuple regardless of the arity of it and we'll give you back an operation that takes the other half so it basically allows you to write a pretty expressive code actually with generics in all of this so these types this type systems here actually are completely independent of the host language which basically means you can write your host language code in Python if you want or f-sharp and then Express the quantum piece in Q shop and the type systems in Q shop won't collide with the type system of the host language so that's kind of the design the the design of the system I think I'll Park it over there for the language part of the talk if anyone's really keen on talking about why we did certain things come talk to me because that's probably the one piece that I can actually speak cogently about as I said if you have quantum questions wait for Constantine at 1:10 after lunch and ask them all the questions I'll be here so let me see right so this is Visual Studio you guys might not be familiar with it but it's actually a fairly powerful mechanism for building software Microsoft has skills in a few areas one of them is actually busy building languages and some tooling around the languages so so if you want to actually write code and do interesting things you can actually do it in this ecosystem so the driver code for this piece of code looks pretty much like this this is written in C sharp and what this is going to do is take a function which I want to test the weirdness off and I want to run run that function a thousand times collect its result and then group it into a dictionary and return the dictionary or at least just print out the dictionary so that's really what this function is doing right and what I'm going to do is I'm going to do three different tests one is the single header mod now let me this is where the quantum weirdness is going to start showing up the single Hadamard as you expect should take something that starts at 0 moves it to the equator and then when you measure it sort of equally distributes going back to 0 or going to 1 right that's your quantum coin flip we're going to find out what happens when you do to had a mods in a row as in you flip the coin and somehow flip the coin again while it's being clipped right effectively you do that and you flip it again what do you think happens when I put two rotations of Hadamard in a row so from the weirdness pilot part of it what do you think happens if I flip the same coin twice you get the same distribution but multiply it twice over right well this one's not going to work like that and we'll see what that is right and then I'm going to do one more interesting thing I'm going to flip the coin look at it and then do it again and you think that should change the behavior you only say yes because I kind of let it on that way but I'll tell you why it changes the behavior like that right so this thing we'll have a mod let's take a look at the code just to show that I'm not doing anything weird right this is Q sha right and the quantum weirdness test basically says and this is a higher-order function that takes some test which goes from qubit result and with an input and returns a boolean value so you can kind of see the functional influence of the thing where you can pass functions around and the quantum weirdness piece basically says the first ones the single Hadamard which simply does nothing except Hadamard the qubit and then measure it and the doubleheader Mart is Hadamard the qubit and remind it again just measured it it's about as simple as it's going to get right and then I'm going to ignore this its measurement but I'm gonna measure it and we're gonna head Adam on it again and let's see what actually happens when we do this oh by the way I could actually put breakpoints on this and and show you you know and I said that you can't look at the quantum state monad I lied because I got a simulator I can look at the inside of that but it was actually running on the quantum machine I could not physically do what I was going to do but now I'm in a position where I can actually you know step through code and look at values and things like that so it's quite a useful way of looking at the code from from a development perspective right so this is kind of what you expect right and passed in a thousand I want to run this a thousand times I start with the qubit in the false state and I get back false and true roughly 507 493 so it's kind of a fair coin and if I go up to 10,000 it will distribute even more evenly but this is kind of roughly what do you expect from a from a probabilistic distribution of the thing when I run to had a match in a row the coin flips itself if I pass in false a thousand times I get back false a thousand times every single time there's this probability there and the probability is exactly one you unlimited a second time okay this works what false and true and now what are we going to do next we're going to flip it look at the coin and then flip it again and we're back to being random again so this kind this is actually kind of one of the reasons why it's a little hard to get intuition for what your code should be doing if you don't really understand what the mathematics behind is right and you'll lose track of that mathematics fairly quickly like after about two or three cubits the the vector spaces are too large for you to get an intuition for what's going on right but when you're talking about 170 cubits and you want to look at hey this molecule has these things doing what it's going to do you literally cannot write the problem down because the matrix is too large but you can't represent it with just a hundred and seventy cubits so reasonable question is how many qubits do we have and in round figures the answer isn't none my colleague from IBM will tell you that they have some cubits cubits are not all created equal so they have noisy qubits that behave like qubits for a short period of time with a certain level of error because of the natural physical characteristics of it and from that you synthesize logical qubits so depending on how good your starting point is you can then create larger and larger logical qubits Microsoft's approach is to do some of that error correction in hardware and come up with a more robust qubit to begin with so we're all kind of on the same path to try and get a logical error free qubit or in the absence of that try and make do with the noisy qubits and try to solve problems with the noise inherent into in the system right so until we actually get one hundred and fifty cubits we are going to be stuck with classical simulation but the goal and because of the size of these things it's entirely conceivable that some Bay in the not-too-distant future you should be able to put a million cubits on a on a one inch by one inch square right and chill it down to 15 Mille Calvin in that fridge and expose it as a cloud service whether it's on some Amazon Cloud or Microsoft cloud or Righetti's cloud or IBM's cloud you have a cloud service a way to program the thing and that I think is the end of that demo give you an a sense of where you can get more information about it and and then I have only 30 seconds to come catch me after the talk and I'm happy to answer any questions of course I keep saying if you have quantum questions as constant right so she could go to Microsoft comm you'll get / quantum you'll get some information about it all the cue sharp code that we've ever developed is all open source it's available on github so from the simple demos that I can show you to the most sophisticated quantum chemistry code the hamiltonian simulations and all of the stuff that actually we have ever written cue sharp is all open source and available and there are some interesting cutters that are written by my colleagues who basically walk you through various concepts and teach you both cue sharp and quantum at the same time all of that is open source as well so feel free to to to you know go there follow me on Twitter or you know and hit me up and I would be happy to put you in in touch with the right people so with that I will say thank you for your business [Applause]