Exploring Random Quantum Circuits

Guy Kawasaki presents how the Wolfram language handles random quantum circuits, covering the math behind generating random unitary matrices and methods for efficient circuit randomization in quantum computing.
Chapters
Hello, everyone. So this is a presentation. We're going to talk about some capabilities that the Wolfram language has enabled me to do this very interesting research where I explore random quantum circuits. So we're going to go ahead and I'm going to share my screen and we'll get started. All right, so this is a presentation on, as it says, random quantum circuits, alternative methods to random unitary matrices. And so what we're going to do is go through a little bit of just a tiny bit of quantum computing background where we'll share just a couple of details that gets someone who might not be familiar especially with quantum computing up to speed just a little bit. And then I will talk about a few other things that are resulting from that. And then we'll go into the actual computational science involved in random unitary matrices and these random quantum circuits. So big picture, really big picture. All quantum circuit based algorithms are essentially one big unitary matrix multiplying the first standard basis vector. So what that means is a unitary operator is a matrix such that when you operate it by, when you multiply on it by its conjugate transpose, you get back the identity matrix. So essentially you can think of this as a bunch of operations that are done and then a bunch of operations that are undone. And then, and every operation you do, you can undo the dimension of the unitary matrix. For a quantum computing algorithm for a quantum circuit goes like 2 to the Q, where Q is the number of qubits in the circuit. I already used N below, so I didn't reuse the index N the entire operation for every quantum circuit. So, heard about Shor's algorithm, You might have heard about Grover's search algorithm. All of the circuit based algorithms out there are essentially this unitary matrix which represents all of the actions of the circuit times. The first standard basis vector gets you the first column of the unitary matrix and then each of these, each of these elements in this column is a probability value and the absolute value of that squared is the probability of measuring that number in the numerical basis. So when we're going to measure the quantum circuit at the end, the probability of measuring that particular number when you combine all the qubits together is that absolute value squared. So this is a super high level and it's not meant to be a complete understanding of quantum computing. But generally speaking, the reason this is actually interesting is the system is so complicated that you won't know the form of U ever. For large enough systems and for small systems, if we can know the form of U, we don't Actually really need to make the quantum algorithm. So the idea is, in exploring this new field, can you take the small numbers of qubit systems, understand them, and draw inferences about larger systems, or mathematically prove things about larger systems that you can use to actually perform things? So let's wax poetic for a second about the circuit. This is generated in Wolfram's quantum framework. Each of the operations here, each of the operations is a unitary matrix, a unitary operation that can be undone. And when you multiply all of the unitary matrices together, you get a full circuit. So for example, this is a swap operation between Qubits2 and Qubit4. This is a single unitary operator. We're multiplying that by this other unitary operator that switches one and five. Then we're multiplying it by Hadamard, which just affects qubit number five. Then a controlled rotation from qubit five to qubit four and Hadamard, et cetera, et cetera, et cetera. Each layer here is its own unitary operation. The number of layers is the depth of the circuit and each of the matrix operations that are going on. So this first swap, the second swap, the Hadamard, the controlled rotation. Those are all 32 by 32 unitary matrices. You stack, you multiply all of these unitary matrices together and you get a 32 by 32 unitary matrix. We can work in classical computers with 32 by 32 matrices. Not so easy when you get to hundreds of qubits, because then it's two to the hundreds size matrix. And just as a background, the reason why I dived into random quantum circuits is that many quantum algorithms involves some kind of random circuit at some point in their, in, in their development. So for example, quantum machine learning often involves with some kind of random, random convolution matrix or something like that. You got to do. And in order to get that, you got to start with a random circuit. You also might want to benchmark your quantum computer. And if you're benchmarking your quantum computer and understanding how it works, you need to work with the space of all possible unitary operators. How do you do that? You create a random circuit with a random unitary operator. And I so random quantum circuits can be achieved in one direction by creating a unitary matrix and then breaking it down into its constituent parts. So we saw all these different gate operations where we have, this is a gate operation, this is a two gate gate operation. Each one of these is kind of a part of a big circuit, and then the whole circuit makes up a unitary operation. Well, what if we take A random unitary matrix and impose that on the circuit. It's easy to make a random unitary matrix. We know from mathematics that if we generate an n by n matrix of random complex elements, each, those elements sampled from a complex Gaussian, then we get a unitary matrix with these random complex elements. If we do a QR decomposition on that matrix and then take the Q, we have a unitary matrix. And it so happens that this will evenly sample from all unitary matrices. So you're sampling essentially from what's called the HAR measure, and that is the space of all unitary matrices. You're going to sample uniformly from that measure if you use this method. So we have a method to go from the size of the circuit that we have N qubits, it's a 2, to the N by 2, the N matrix. You just generate your random unitary matrix and then you impose on that quantum circuit. Simple, right? Not quite. So first of all, the size of the matrix you're going to have to work with is going to grow exponentially with the number of qubits. And so even if we had a perfect way to implement these random unitary matrices into quantum circuits, it would still eventually become infeasible because the matrices we would have to generate would be too large. QR decomposition would get too expensive. Now, how do we implement an arbitrary unitary operator on a circuit? Well, you have to break it down. And that is a tremendously difficult mathematical problem. So we know it has been mathematically proven that with enough finite gate operations you can approximate to any degree that you want a unitary matrix. So you take that random unitary matrix, you can turn it into circuit operations like the ones in here. These are circuit operations, they're defined, we know how to implement them on hardware. So we know mathematically that if we had to take a random unitary matrix like this one, this is for a 2qubit system, that we should be able to go and make the, make the quantum circuit that implements that unitary operator to any accuracy that we want. Problem is that it is unbelievably expensive to actually do that. So you see this exponential looking curve here? It might actually be even more than exponential, I'm not entirely sure, but it goes from two qubits to seven qubits, or sorry to eight, actually trying to go to eight, and it actually doesn't even fit on the graph. So two qubits to eight qubits and pythons, qiskits transpile decompose functions cannot do the operation of breaking a uranium unitary down. So this is how much it takes so for two qubits, you know, it's, it's I think maybe six or I think six a depth, a circuit depth of six. For three it becomes like 40 and then for four it becomes like 115 or something. Then five, you're into the two hundreds. Six, it's 400. And then you're into the, by the time you get to seven, you're into, you're over 10, you're like 15,000. By the time you get to eight cubits, you're working in the 40, 50,000 range. And that's just a depth that is just untenable. So, so you're basically going to use, you never even get into the hundreds. Like circuit depth is kind of limited to something like this in actual hardware nowadays. So if you're trying to like benchmark your quantum computer, you're basically just created complete noise. Instead of having a random unitary operator that has some random specific noise, you're basically just going to uniformly. And this really becomes an unfeasible way to work with it. You first have to work with a matrix that might be ridiculously large, but then you'll have to break it down to a circuit that is ridiculously long. So it's not really tenable. So I spent 10 minutes setting up the problem. Let's look at what I was thinking about. Oh yeah, let me clarify a few things. When you break it down, you have to break it down into universal gate sets. So these are operations that you can do between one or two qubits, in this case anyway, that can approximate the unitary operator. So it has been mathematically proven that these five gates here, cnot, rx, ry RZ and the global phase gate, can together approximate any unitary operator to any unitary operator to a specified degree. That means that if I apply the Rx rzry a global phase at some point and cnots in specific places throughout a circuit, I can approximate any unitary operation. So this is a 2qubit system down here. So the RX ry rz operations would get scattered somewhere between the 2qubits and then I have a CNOT somewhere and, and then a global phase at the end. So essentially what I'm saying is that the two unitary matrices that have size two to some number where that number is the number of qubits. The tensor product of all of these gates here, which are easy to implement in hardware together, can approximate that unitary operator. Now that's when you're going from the situation I just described is when you're going from, from the Unitary operator, the random unitary operator that generated and gone to the circuit. And what I decided to do and the Wolfram summer school shout out to that program. It was, it was really fun. I would not have thought of this project had I not been there, was to go in the other direction. So let's say I am randomly picking a theta and a qubit for the RX operation and randomly picking a qubit and a theta for the RY operation, randomly picking a qubit and a theta for the RZ operation, randomly picking some gates to do cnots and then at the end throwing on a global phase. How well do I approximate the randomness and can I beat this kind of insane exponential growth exponential demand that takes to go in the one in from the unitary matrix to the circuit. So I'm taking it from the gate operations to the unitary matrices instead of the other way around. And I want to ask the question, well, how well do I do, if I do that process where I pick a random, I pick a random qubit and in this case it happened to be RY on the first qubit and I pick another random qubit and I apply another RY operation with a random rotation and I happen to have picked up Qubit 1 and Control Qubit 2. In this case I pick Control Qubit 4 and going to Target Qubit 3. And I've applied all of these different operations. Well, how well am I approximating the space of unitary matrices? And it's very easy to generate these random circuits. This, this kind of random circuit where I'm. You just have a few operations. It's harder to know once you have this how. Well, this is actually sampling from the space of all unitary matrices. And so that's the mathematical question I'll be exploring in the second half of this presentation. So I've set the problem up, I have these random unitary operation, random fundamental gate operations. And I want to compare that to the effectiveness of the method that we know is working where we're generating first a random unitary operator and then applying it to the circuit. I should say also before that you can use other sets of fundamental operations. These, these, these, these universal gate sets. So another example of universal gate set might be a polygate hadamard and a CNOT plus a T gate. That's another set where I think you can actually fix the polygates with a specific thetas. As long as the thetas are, you know, not going to exclude, not falling into a measure 0 set of thetas that don't work, you can fix these thetas. You should have three different thetas and along with a Hadamard, a cnot and a T gate. And you can actually approximate any unitary operation that way. I've chosen this because it actually allows more flexibility with these thetas. So anyway, the question remains. Oh my goodness, there we go. The question remains, how well does this approach work? And it's not a trivial question to answer. And in fact there is no mathematical way to do it. So here is the code for generating these random universal circuits. This is the Mathematica code that will do it. And going to examine the sort of fingerprints of randomness. So as I said, there's no mathematically proven way to go from a data set that's generated this way. I can write the unitary matrices this way. So let's. I have this circuit, it generates a unitary matrix and I create 1,000 of these circuits. There's no way to take that data set of 1,000 unitary matrices. In this case 16 by 16 unitary matrices. There's no mathematically proven way to take this data set and do a statistical analysis on it to see that if we're actually evenly sampling from the HAR measure. But I can look at all of the fingerprints that the HAR that sampling from the HAR measure actually does and tell and that should be able to tell us how similar these two operations are. So let's say that these. Excuse me, that sampling from the circular unitary matrix distribution in Mathematica. So that's actually sampling from truly a random unitary the space of all unitary matrices. Well, I know that the element magnitude should be normally distributed. So then I know that if my element magnitudes are normally distributed in the other when I generate the unitary matrices this way. Well, that's not a sufficient test. It's a necessary test. So if the elements are not normally distributed, then I know that I did not evenly sample from the HAR measure. However, if they are normally distributed, then I didn't actually manage to sample from the HAR measure. Phases of the eigenvalues should also be uniformly distributed on. I should. Sorry, that should be 0 to 2 PI. And we typically factor the PI out. So it's uniformly distributed on 01. The probability distributions of the states at the end, those numerical states should be random and the instrument entanglement should follow some sort of pattern. So these are just a few interesting things that I picked up on. You can kind of go crazy. You can go every entanglement monotone and every property of the matrix and trace and everything should. It should all. They should all match up and spoiler alert. Well, they don't really match up. Remember that it takes many, many, many of these, these types of operations to approximate a random unitary operator. So it's kind of hard to actually get things to match up. So here is an ex, here's what I did at the summer school. These are two gibbet situations. So excuse me, when you have random unitary matrices and, and you look at the magnitudes of the real parts of the matrix elements, this is the left side here is actually we know this is a random unitary matrix generated data set. Looks like this. Here's what it looks like when you use my method and kind of sample randomly. It's like, it's just a little bit different. Here's the entanglement entropy. So this is really cool. Personally, I think this is one of the coolest things I discovered was that the entanglement entropy of a 2 qubit system, so one qubit into the other, that's the bipartite first qubit, second qubit. It for a random unitary matrix generates this basically a beta distribution of entanglement entropy. It's really cool. And well, it's just not quite, it doesn't just, it just doesn't quite look like that in the, in the other case. And then the eigenvalues are uniformly distributed and that's something that we see in both of them. So again, this column is the circuits that I generated going into the unitary matrices and this is the unitary matrices into circuits. So this is what we're shooting for. This is what we got. We can see they're similar and they're probably similar enough for most experimentalists to want to work with, but they're not quite the same. And it's exceedingly difficult to tell when, when you're looking at something how similar it is. Like statistically, like how statistically similar are these two distributions? Well, enter some of the formal comparisons for comparing probability distributions. There's various tools, entropies and like cross entropy and other. There's all sorts of methods you can contrive to compare probability distributions. Most notable is the Wasserstein distance or the earthmover's distance. It looks like this. So if you have a data set and these are generalizable to any probability distribution, discrete or continuous. But if you're using an empirical distribution derived from data sets, which indeed we are in this situation, then it's actually a function of the order statistics. So the X order statistic, the Y order statistic and, and a P for the p distance. This is essentially defined Any of these P moments will generate a different Wasserstein distance. And this is a one dimensional case where you can line everything up. If it is a multiple dimensional case, you have, it's a function of each permutation. So this is a little bit more complicated. Small catch is that we need the same number of data points to do this. So this is, this is, say the, this is the unitary matrices. This is from the circuits. And you're, you have to have the same number, otherwise you can't, you can't do the summation. And so you have to do other things in that situation. And the numbers also don't mean much on their own. So let's look at this. I mean, so here's a Wasserstein distance of 0.04012. The tan distribution is the four qubits, a depth of 20 and a C not weight of 1. So C not is just as probable as any of the rotation gates. And this is what we get. It's clearly not the same distribution. You can see there's a higher, more sharp peak in the middle, but they do follow a similar shape. And the blue distribution is not, I didn't write it there, but the blue distribution is what you get from actual random unitary matrices. So it's essentially a normal distribution. Well, these aren't the same. And just keep in mind this is what it looks like to have a 0.04 Wasserstein distance. But it doesn't really tell us much on its own. It's just a quantity of how much essentially effort it takes to move these peaks here above the blue line into, fill in all of the other ones and then move these over here above the blue back into the other ones and to basically even out these two distributions. And in this case they're more similar because these two higher ones are in the center. So you get to kind of push them over to the side. And like heuristically, that's, that's kind of what's going on. And the computational needs in this situation grow like sorting algorithms, but in this situation they grow like factorially. So again, we run into the problem where you have a lot of qubits. If we're looking at the outputs of the quantum circuits, we'd be sitting in this situation and it's just problematic. But this is also very easy to implement in the Wolfram language. And so this is kind of an easy get for comparisons. And it does make sense when we're looking at multiple comparisons. So remember that we have the qubit Number depth of the circuit. That's essentially the number of random elements we're creating and a CNOT weight hanging around. That's how likely we are to pick a cnot, essentially. So the greater this number is, the more likely it is. So the ratio, this is the ratio essentially of CNOts to rotation gates. And I'll kick the other one off of here and we'll look at this. So on this axis we have our circuit depth and this axis we have a CNOT weight. So here we have no CNOts. Here we have CNOts that are occurring twice as likely as any of the gates, the rotation gates. And the Wasserstein distance is this actual plotted value. And this is where it actually tells us something. It tells us that the situation when the Wasserstein distance is lower we're doing better, and when it's higher we're doing poorly. And so you can see that when the circuit depth is very small, we are not approximating the Wasserstein distance very well. Or sorry, we are not approximating the unitary matrices very well. But then when it gets much, much lower, it goes down to about 0.01 for highly likely cnots and deep circuits. And this kind of makes sense. Oh, this is in 4 qubits, by the way. This is a 4 qubit situation. So at the summer school I only worked in two qubits. That is going to be different and easier to deal with in the cnot because you essentially scrap. Because one cnot between two qubits does all of the entanglement you need between them. You don't need to do it multiple times. You can, but it doesn't help when you have more than two qubits. You need to have multiple cnots going on in order to fully entangle the system. And so this is why one CNOT is not going to do it. You need many CNOTs, and in four qubits you'll need multiple CNOT to actually work with this. So these are the conclusions that you can draw here. So again, this is just because the Wasserstein distance is very small in this situation where we have highly likely cnots and very deep circuits does not mean that it were evenly or uniformly sampling from the HAR measure. It just means that we're closer than we were when we were over here, over here. Now, here is the Wasserstein distance, just kind of basically just a one cross section of this. And so you can see that. I'm sorry, I did not, for some reason, when I brought this over from the notebook, I generated in it, it did not keep the axis labels at the polygon Apologize for that. So this is the CNOT likelihood, this is the Wasserstein distance. And we fixed this at the depth of 40. So this is essentially this far line down here. It turns out we need lots of these cnots to actually do a good job. And if we were to continue this, this is not computationally trivial. It is a lot of computation to continue. If you continue it, this will go back up again because now we have so many cnots that we're not fully scrambling the qubits before we entangle them. So now let's go on here and look at some alternative methods. So I was generating these methods as well. So this is a situation where I scramble in the RX and sorry, in the rz in the RY direction and I just entangle down the line. And so I tangled the first qubit with the second, second with third, third with fourth, fourth with the fifth. And in this case I scrambled the qubits a little bit more. And so now I, I did the first qubit with all of the other qubits, then the second qubit with all the other qu. And this is fully entangling. And these do an even better job of approximating the, the distributions. So again, we're looking at something like this, where we're looking at the element magnitudes, we're looking at the entanglement entropy distributions. So if we lower, by the way, it's say if we lower the C naught ratio in the circuits, we actually pull this peak backwards. So if, and so if you have no cnot, you're going to get no entanglement at all. And then if you have lots and lots of cnots, you're going to push this, you're going to push this entanglement value upwards. And so you can actually tune the amount of entanglement on average that you get by tuning that CNOT parameter in this. Now in this situation here, you don't do that because the CNOTs are fixed. It's the random and actually the structure of the circuits are fixed. You're just picking random rotations. So this is essentially, I call this the scramble and entangle method. So you're scrambling and then you're entangling. And both of these do a really good job at approximating all of the values that we were looking at here. Where the element magnitude should be normally distributed, the phases should be uniformly distributed on 01. Probability distribution of the states should be random. Entropy of entanglement should follow some kind of pattern that's similar to the unitary matrices. So these all do. These all do a good job. And they are all polynomials. So this goes. The size of the circuit grows like N squared here and it grows linearly here. And so these are great. Excuse me. These are great ways to. I hope to formally statistically prove in the future that these are great ways to randomize your circuit in a linear fashion in a polynomial way instead of an exponential way. And so hopefully I can refine these techniques a little bit more. And then we have a way to fully approximate the process of generating these random unitary matrices like we did here and then going into a circuit so that we avoid doing this. We avoid doing this, like, extremely gross breakdown that's computationally expensive and totally infeasible. And we can go more towards something like this where we have like a linear efficient way to randomize the circuit and then get on with our business and do the rest of the algorithm. So the randomness need not hold us up. We can use this method. The conclusions. I'm just going to wax poetically for a second in these. So in conclusion, we're not perfectly. This number isn't going to zero. We're not perfectly approximating the random unitary matrices, but we are getting very, very close. We're producing probability distributions that are, that are very close for small qubit systems. And hopefully this can be useful to anyone who needs to do things like benchmarking or quantum machine learning or anything like that to really get a, to really get a kind of a robust randomness in their quantum circuit. And so that is my time. It's been half an hour. Thank you all very much. I am not sure Q and A. Do I have a Q and A section? You're welcome to answer question ask. I think you could type questions to me or anything like that. It looks like there's 14 or 15 people here. So if you have questions, I think you, you should be able to type them somewhere. If not, thank you very much for, for listening. I much appreciate it and I know there's probably other sessions going on, so thank you.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






