 OK, I'd like to introduce our next speaker. Our next speaker is John, who's currently a PhD student at the Radford University in Nijmegen. And he spent the first two years of his PhD dabbling with the foundations of quantum mechanics, which is about the deep question why nature is described by the laws of quantum mechanics. And nowadays, he's working on optimizing quantum circuits using graph theory, such as the ZX calculus. And that's what he's going to talk about today, about his project called Pi ZX. And the talk is about quantum circuit optimization, verification, and simulation with the software tool. So please welcome John. All right, well, thank you. Thank you for the introduction. And thank you for inviting me here to give this talk. So in this title, it might be that you don't know what any of these words mean. I hope to make it a bit more clear to us in the talk. And I'll spend most of the time basically explaining what these things mean and how we use physics to use it. I know it looks like Pi ZX, but it's pronounced physics because it's more fun like that. So physics is a Python library that you can use to manipulate large ZX diagrams. Even if you've heard of quantum circuits, you might not have heard of ZX diagrams. So I will get to explaining to what those are and why you should care about it if you care about computing. Yeah, picture the plane just to show that a marketing apartment is really hard at work trying to get the word out about our project. All right, so just like the basics, a quantum computation. There's multiple ways to do it, but the most general or the most straightforward way is to use a quantum circuit. It's basically a quantum analog of a logic circuit that does for computing. And a quantum circuit, you can build it out of quantum gates. And quantum gates are like, you can think of a quantum circuit with quantum gates as sort of the assembly language of a quantum computer. So they contain sort of abstracted, basic instructions for your computer. And these gates have names like not gate, s gate, t gate, h gate. Not gate is probably familiar to you all, others maybe not. So the way you should understand these single qubit gates, so they do a transformation on just a single qubit. On a qubit, you can sort of see as a sphere called the Bloch sphere. And if you compare this to classical computing, you would have like a 0 and a 1 state. And a 0 and a 1 state, you can see the 0 lives up here at the north pole of the Bloch sphere. The 1 state lives down here. So in not gate, you can see it's like a 180 degree rotation that flips the two poles like this. But the special thing about quantum computing is you don't just have the poles you can use. You can use any position on this sphere manipulated. So for representation, what a qubit, in what state it can be. And then these order gates, like the Hadamard gate, s gate, t gate, this correspond to different types of rotations on this Bloch sphere. They're different types of operations you can do in a qubit. For instance, Hadamard gate interchanges the z and x axis. So it makes a state like a 0 state. And it puts it on a crater, which makes it a superposition of two states. And these other gates are like this also, this is a quarter rotation, the t gate is like a 1-h rotation. I use these specific gates for a reason, which will come in like a few minutes. And that's basically only one two qubit gate that you need to know about. It is called the controlled not gate. And what this simply does is it has two qubits. And I look at my first qubit. And if it's in the 0 state, I don't do anything. If it's in the 1 state, then I flip the bit of the second qubit. So this is just a classical operation, but then you do this classical operation on two qubits. So these are all the gates you need. You can actually do any quantum computation using just these, let's see, one, two, three, four, five gates. So this is all you need to know about computing basically, because then you can do any computation one. Which is like, it's hard to show this is actually true, but it does work. And so the motivation behind this talk and what I will talk about is quantum circuit optimization. So taking the same quantum circuits, but somehow reducing a number of gates in it, while still performing the same computation, which is like analogous to what advanced compilers do for classical computers. But now I want to do it for a quantum computer. All right. So these quantum circuits, you have a special notation to write them down, sort of a graphical way to see them. And we have a special notation for the not gate. It's just like this, like, XOR symbol. And then a controlled not gate is like an XOR, but now it has a control wire attached to it. And we just compose them into a quantum circuit. So each line here represents a qubit. So this is three qubits. And the time goes from left to right. And it just says, on my first qubit, do a t gate, on my third qubit, do a not gate. Then do a c not gate between the first and the second, et cetera. You just do these operations in a row. So it tells you what instructions do we need to do on my quantum computer. Well, quite interestingly, you have different circuits that represent the same computation. And you have certain identities for these things. For instance, if I do two controlled not gates on the same qubits in a row, it's equivalent to doing nothing, because these nots cancel each other out. And similarly, doing two hard on my gates cancel each other out, these things also hold. So you have some circuit identities, which you can start to use to simplify your quantum circuits you're using. This is a bit complicated by the fact that some operations commute past one another. So if I have to see not gates, for instance, with put a not on the same qubit, it doesn't matter in which order I do them. So combining these two things of cancellations and commuting, you can already see it starts to add up what kind of simplifications you could do on your quantum circuit. And in fact, you can do a lot more of these simplification rules, and even more, and lots more. And this list just goes on and on, and people have been finding more elaborate lists to do better quantum circuit simplification. But this gets really unwieldy very quickly. And basically, the reason why I need so many rules is because the structure of a quantum circuit is very rigid. It's like it has a definite time ordering. You need to do this thing in this order. You have a definite amount of qubits. You can't increase the amount of qubits or decrease the amount of qubits intermediately. It's very strict what you can do. And this is where we use ZX diagrams to come over this problem. So ZX diagrams, what you have is circuits and circuits consist of gates. And ZX diagrams consist of what we call spiders. And these spiders come in two flavors, which we call Z-spiders and X-spiders. And they have these two colors, green and red. If you're colorblind, it'll probably be light gray and dark gray for the X-spider. And contrary to a quantum circuit, we can wire these things in any way or shape you want. So it's just like a graph, and I just say I want to connect all these things together. And there's no, like, we can still say it's like a time ordering when things go from left to right, but it's no longer really necessary. And only the connectivity matters. So I can, like, just move these things and continuously deform the thing, and it represents the same computation or the same linear map. So for instance, this one has two inputs and three outputs. This would be a linear map from two qubits as an input to three qubits as an output. And we can write every quantum gate as a ZX diagram. So for instance, the S gate is a single spider with a single input, single output, and a pi of a two phase. So if you remember, an S gate was a quarter rotation among the block sphere. So pi of a two is like a quarter rotation on the sphere. So you see it here. And the T gate was like a 1-8 rotation. So we see a pi of a four appear here. The Hanemar gate can be decomposed into three basic rotations. So we compose these three rotations together to get this more complicated Hanemar gate. And because the Hanemar gate is so important, we introduce a new symbol for it, this yellow square. And then a C node gate, a controlled node gate, is just a composition of two spiders in this particular manner. And the reason we write this is vertical lines, because it doesn't matter in which direction you do it. So you can see this in two different causal orderings, basically. And it actually turns out that you can represent any linear map between any number of qubits as a ZX diagram. So this is a universal language to talk about quantum computing. And the reason we like using ZX diagrams is because they come with a set of graphical rewrite rules. So if I have a ZX diagram, then I can change it according to this set of graphical rewrite rules. And it will still represent the same linear map, the same quantum computation. So for instance, the rule here at the left of the top, it tells me that if I have two spiders of the same color, so at the same type that are connected, I can just fuse them together. And the phases on it, they add up. And this one tells me what the Hadamard gate does with a spider. So it says that if I have a Hadamard gate in front of a spider, I can push it through the spider, and it changes the color of the spider. So these kind of rules are just very like, once you get used to them a bit, it's very natural to see what you can do. It's like, oh, I have a Hadamard gate. Let's push it through. Oh, I have two spiders of the same color. Let's fuse them together. And this is just a small set of rewrite rules. And it turns out that if you add one more rule, which is a bit complicated to specify, then this rule set is complete. So that means that if I have two diagrams and they represent the same quantum computation, I know there is a set of rewrite rules that will bring me from one thing to the other. So like the dozens of circular qualities as I showed in the beginning, like you can all replace them with just these rules plus one more, and then you have a complete set of configurations, all right? So this is why we're using ZX-calculus because it's a really powerful graphical tool to reason about quantum computation. Yeah, so a set of dozens of circular qualities, just a few simple rules. And this brings me to why I'm here, which is physics. So physics is an open source Python library. You can find it on GitHub now if you want. And the goal is that you can import quantum circuits and like transform it into like large ZX diagrams and simplify this ZX diagrams in an automatic manner and hopefully do interesting stuff with it. Particularly, we originally developed it for a quantum circuit optimization, but then we found out it also works really good for quantum circuit verification. So verifying that two quantum circuits actually implement the same unitary with the same computation. And something we're working on right now is doing quantum circuit simulation. So basically simulating what a quantum computer would do with this thing on a classical computer, which and yeah, so these three things. And I'm gonna give you a bit of a demo to show you how this works in physics. Let's see how much time do I have left. We have a lot of time, cool. All right, so this is just a Jupyter notebook, which I guess many of you have seen. I'm just gonna start with a few basic imports. The important import here is import physics as ZX. By the way, is this large enough for everyone? Like, can anybody see it in the back? Yeah. And now I'm just gonna start with presenting like this a simple circuit. And this uses the chasm notation, which is kind of like an assembly language for quantum circuits. So I'm just gonna say I have two qubits and I'm gonna do a CX, which is a controlled not gate between the first qubit and the second qubit. And then I'm gonna draw the circuits. And so we get this thing out, which like as I said, like the C not gate is represented by these two connected spiders. And to show you this is actually a ZX diagram and not a circuit, I can just move this stuff around. So it's not like an actual rigid thing. It's just a thing you can move around. And we can also convert it to a matrix to see it's actually is like the linear map. It should be and like if you know anything about quantum computing, you know, but the C not gate, there should be a one here, a one here, and a one here, and a one there. And there are STGP zeros, but it's great that works. Okay, so let's do a bit more complicated circuit. So this is just a few C not gates in a different orientation. It's an S gate and it's the inverse of an S gate and then some more rotation gates. I can just, if I want, I can just represent these gates as like a list of sort of simple representations. And I can convert it into an actual ZX diagram and I see like this is just like a graph of 14 vertices and 15 edges. And now we can start to simplify it. So if we look here at this thing, we see that we have these two green spiders that are connected to one another. So I know that the spider fusion rule tells me that I can fuse these things together into a single spider. And the same here for the red one, it's also connected to this red one so I can sort of fuse them together. So we have a function that does that. It's called spider simp. And we can fuse them together and we need to see that this thing is now a single node and it's used again like this. Well, we have a bit of more powerful rewrite strategy. We call full reduce, which applies like a certain heuristic set of rewrite rules we've developed. And it actually managed to reduce this complete diagram and just becomes a swap gate, which if you're a bit familiar with quantum circuit, you see three C nodes in this configuration which should read as a swap gate and then like this five or four goes through the swap gate and cancels with this one and this one goes through the swap gate and cancels with this one. So that's kind of what a simplification is doing automatically animation to a swap gate. Okay. So now let's do a bit more complicated stuff. So a thing I haven't explained really is what are your metrics for optimization in a quantum circuit, right? So what are the things that you want to minimize when you want to implement a quantum circuit on the quantum computer? And this depends heavily on what architecture you have for your physical quantum computer. For near-term quantum computers, the most obvious metric is total gate count and two qubit gate count. Total gate count is obvious, right? If you have less gates, it's better. And two qubit gates especially, because usually they introduce more noise to your computation and they take more time to perform. And also like the far parts, maybe you have to do some extra work to actually make it happen. So those are the two metrics you really care about for like near-term computing. There's also depth, but don't worry about it. But if you're thinking about like far ahead, fault-tolerant quantum computation, then the metrics sort of change and some things become easier to do, some things become harder to do. And a thing that becomes particularly hard to implement in a fault-tolerant manner is the T gate. This is for technical reasons. If you really want to know, quantum me after and I'll explain all about it. But so like an important goal for quantum circuit optimization for the fault-tolerant quantum computers is minimize the number of T gates. So we have this special method that does this. It's gonna show one example. So we have this slightly bigger circuit. It's an actual benchmark circuit we've been using. I think it implements a classical reversible function that calculates whether the first four bits, model of four are zero or something. And then stores the answer in the fifth qubit. But anyway, so this circuit is a bit longer. And we see it has 28 T gates. So that's like the metric you wanna improve with this method. So I apply this optimizer and I draw the resulting circuit and I get something that's indeed shorter. So that looks good. And if I look at stats, it's indeed T contributes to eight. So we went from 28 T gates to eight T gates. And this is actually the best known T gate for this circuit right now. Like before we did this work, it was 16 and we reduced it to eight. And like now there's other people to also get this number bit. So they got a bit of an idea because this is right now a bit of a black box where like I just put in a circuit and get something out. Like what is this doing behind the scenes? Let me just rerun this simplification. And I see like it does in the background. It does like a lot of stuff. It fuses on spiders, moves my identities. It does this thing, which I haven't talked about at all, but like it's complicated. And in the end, the result that you get is like something that is actually gonna looks like this. And there should be two things you notice about this. First, it does not look like a circuit at all. It looks like some weird jumble of wires. And second, there's these blue wires. And that's kind of like a shortcut for a wire with a Hadamard gate on it. Cause otherwise there would be Hadamard gates floating everywhere and that looks terrible. So we just use a blue wire. So with this thing, there's basically two problems you have to solve, which is how do you get from this arbitrary diagram back into a circuit diagram? And we found a few ways to do it, which are a bit much to go into now. But if you wanna know more, just ask me later. Yeah, so this is kind of what's happening in the background. And we use this information to get an optimized circuit back out. So that's circuit optimization, what I want to talk about. Now let's get the circuit's equality verification. So I've shown you that I get this starting circuit and I output a new circuit. But how do you know that they represent the same computation, right? So I can do it the easy way, which is I can just calculate the matrix that each of these computations and I just compare the matrices and see if they're equal. And if they're equal, then I know I've done the same computation. But of course, the entire reason we care about quantum computation is that these matrices aren't easy to compute. They take exponential memory in a number of qubits. So like this runs into problems quite quickly. So what we've developed instead, only for this case is five qubits. You can just do it manually. But what we've developed is a method which is I take in two circuits, which I wanna know if they're equal. And I take the first circuit and I take the inverse of the second circuit and then I compose them. And if their circuits are equal, they should be implementing the identity operation, right? Cause like if they're equal, I do the thing, I do the inverse of the thing, nothing happens. So what we've done, we do this and then we use our simplification strategy from ZX and see if it completely reduces to the identity. And if it does, then we have a certificate of equality that indeed these things are equal. So for this circuit, I can just run it and if these sets true, these things are equal, which like, let me show you a bit more detail what actually happens in this function. So first I copy like the original circuits. Then I add to that the inverse of the other circuits. So now C2 should contain an identity circuit. Then I make it into a ZX diagram. I reduce it fully with our simplification strategy and then just draw it and we indeed see, sorry, we indeed see that it's completely to the identity. So nothing happens, all right. And to show you that I'm actually not cheating, let me change a single gate in the first, the optimized circuit. So now it should contain an error. And if you verify quality, and he says false, they're not equal. And if we do it manually, we see that like we have some leftover gates. So it's indeed not identity. All right, so that's verification for this. And the last thing I wanna talk about and see how much time do I have? That's a lot. All right, so the last thing I wanna talk about is simulation, all right. So let me just get another circuits here that's even a bit bigger. And there's a T count of one out of five. So it's a bit more complicated circuits. It's nine qubits here. So if I have a circuit like this, so what I would usually do in a quantum computer, right, is I would have some simple starting states like usually just always like the old zero state. And then I would apply my chosen quantum circuit to it. And now my quantum system is in some state that I want to know something about because I've done this computation and wanna learn something about it. So possibly I will measure a few of the qubits. I will get some outcomes, some zeros and ones. And maybe I need to do the computation like a few thousand times to get enough statistics to actually derive something meaningful from it. Like the Google experiment that showed quantum supremacy a while back, like they did the same experiment like 40,000 times or whatever. So I can do it a lot of times. And then in the end, you get some, you get some basic probabilities out of some samples. And then hopefully you can use them to do something useful, right? So what you wanna do in classical simulation is you wanna do this problem, this one I just described, then on a classical computer, which of course is gonna be hard because if it was easy, we wouldn't care about quantum computers. So there's like a lot of research being done and trying to do this in smart ways. And you already see this like, if you heard anything about the Google announcement of quantum supremacy, where they claim to have a computation that did something that the classical computer could never do. And they said like a classical computer would take 40,000 years, like a long amount of time to do it. And then IBM a day later said, well, actually it would only take two days if we do it in this way. So like there's a lot of like, depending on how you do it, like the numbers differ immensely. And also we've gotten a lot better at classically-simulating quantum systems. So, and there's two methods, there's basically two methods right now that people use to do simulation quantum circuits. And the first is relatively straightforward, is I just, I prepare my initial quantum state and I represent it as some huge vector, like some huge matrix of elements in my classical computer. And then each gate that I apply it, I just modify this vector a little bit and I keep track of the entire vector the whole time. And in the end, I just do something with this vector. And this takes exponential amount of memory in a number of qubits, which, yeah, makes sense. And there's some smart things you can do to exploit sort of symmetries in the circuit or sparsity, whatever, to make this faster. But like this has sort of a hard limit around 70, 80, 90 qubits maybe in the future if we get better at this. So that's like the first method. The second method uses something called stabilized decompositions. And I don't wanna go into the details there because it's really complicated, but the interesting thing about that is it doesn't scale with a number of qubits. So you could have a circuit with thousands of qubits and you could still simulate it with stabilized decompositions. Stabilized decompositions scale with a number of T-gates used. So if I have a circuit with a few T-gates, even though it's many qubits, I can still easily simulate it using the stabilized decompositions. And that's the method we've implemented in physics. So let me just do a bit of simplification with the circuit and explain a bit more about this. So first we have the circuits, we can just simplify the physics and we get this complicated looking Zdex diagram with lots of connections here. And now what I wanna do is I wanna know some property about the circuit. So the property I wanna know is I wanna input some states. So this tells me just apply this state, input the state in the beginning of the circuit. And this says apply effect. So effect basically tells me I wanna know the probability that this particular outcome happens. So I just, I basically ask this now, like if I were to run this circuit on this input state, what's the probability I get this output, right? And I just reduce it and the output I get is this Zdex diagram. And now we see this Zdex diagram has no inputs, there's no incoming wires on the left. And if I scroll a bit to the right, we also see that it has no output wires to the right. So those has no outputs, which makes sense because I expect a number, right? I expect a probability to come out of this. So we have this complicated diagram and now this thing represents like the number I want to know. And so what I could do is I could just, for each of these spiders, I can represent this matrix and I can contract all these matrix like with like tensor network methods and I could do that. And for a small circle like this, that would work. But the other way I could do is, like each of these individual spiders, I can cut the spider open basically into two bits and then this would give me two separate diagrams. And then each of these diagrams, I can then calculate the value and then if I sum those values together, I still get the original outcome. So I can do this with this spider, I get two diagrams, but if I also split this one, then I get two diagrams for each of those two, so I have four diagrams and I can do it for this one and then I get two again for those, I get eight. So we see these skills exponentially with a number of spiders that are left here. And in particular, it skills exponentially with the spiders that have an odd multiple of five or four because those basically correspond to your T gates, which are like the hard part when doing this method. So, well it turns out that actually the best way to do is, is not to split open each individual spider because that takes two, you get two copies per spider. It turns out the complicated reasons that the best way to do it is you take six spiders and you decompose them with seven terms. And like these are just numbers that have to come out of this research. And then, so you still get like exponential scaling because like if I have six of these spiders that I want to split open, I get seven terms, if I have 12, I get seven times seven is 49, if I have 18, I get seven times seven times seven. So it skills exponentially. And you can easily calculate that like the amount of terms you would need to simulate this or like to calculate this value using this method, which require a 67,000 diagrams, 67,000 simplifications. But the interesting thing we can do now using ZX diagrams is whenever I cut open these spiders, then the resulting diagram I get is simpler and is smaller. So then I can rerun my simplification strategy on this new diagram and hopefully this cancels out some of the additional structure. So instead of replacing six spiders with seven diagrams and each of these seven diagrams, I can hopefully find some further reductions that will make my diagram smaller and require the next step to be like less painful, basically. So we implemented that. And if you do it on this circuit and it takes a while to compute because we haven't really thought about optimizing this yet. But it's now computing like, it's basically doing this thing where like it replaces six spiders by seven terms and each of these terms, it's gonna simplify and then replaces again six by seven, et cetera. And then in the end, we should see that some better resaving mode. Yeah, it's also the way it chooses these spiders is random. So like in different runs, it takes different amount of terms, but yeah. So it took 8,865 terms. So naively, I would use 67,000 terms to do this. And with our method, you use like 9,000 terms. It's like nine times less. And like in this skills up, right? Because like this is exponential behavior. So if you want to see that bigger diagrams just helps more and more. So like now it's actually slower than doing it directly, but yeah, like if you have bigger diagrams, you'll hopefully be better. So this is something we're working on now to see if this actually is better than what state of the art that people are using with this method. Yeah, and it's a show that actually gives correct answer. So this way with decomposing everything, we got the answer that the number we were calculating was this number. And if you calculate it directly, but just doing a simple method, we also get the same answer. So like it is indeed correct. So that's nice. Yeah, that's basically what I wanted to tell you. I realize if you've never seen this stuff before, it might be a lot. If you wanna know more, like go to our Github. You have some links to learn more about it. There's also a website, sedexcalculus.com, where there's some resources in order to like learn a bit more about sedex. If you really think like, oh, this is awesome and I wanna learn all about it, but I know nothing about quantum computing or quantum theory or whatever, I can highly recommend this book, which appeared like two years ago. It's built up the entire foundation of quantum theory using the language of these diagrams and sedexcalculus. So it's sort of like a graphical approach to like quantum computing basically. And with that advertisement, I thank you for your attention. So we have time for one or two questions. If anybody has something on their mind, I would like to ask the speaker. Thanks for a great talk, very interesting. I was curious about the optimization. Maybe you said it, but maybe I missed it. So can I choose what I wanna optimize using this? Sorry, can you choose what? What I wanna optimize, like if I wanna optimize T count or total gate count or... That's an interesting question. So for a long time, we found that so that there's two ways we can use our optimization. There's the thing I use here, which is called teleport produce, and it's basically only doing T count, T count optimization. And then the second thing you can do, which we call a re-extraction. So like I get this very compact to the x diagram and then I need to make it back into a circuit and there's a ways to do it, which is quite involved, but you can actually do it. And this results in a new circuit which usually looks completely different than the original one. And what we found is that unfortunately, this usually has more scene on gates than what you started out with. Although like we've recently done some improvements to the algorithm and now it works a lot better. Although on some stages, it's still worse. On the other circuits, we actually get way better results than other people. So it's kind of dependent on the type of circuit you're optimizing, whether it helps. There is currently no easy way to see when you should do this and like to apply this. So the answer to the question is not really. Thanks. Any other questions? I have a question actually on the proper way of using your algorithm. So have been, did you use that for a true implementation like with optics, having a circuit complicated and creating an optimized one? Sorry, I missed the first bit, but can you repeat it? So this is a theoretical way of optimizing circuits. I know that there is several implementation of quantum computing and photonics. Have you done some experiment using this technique on optimizing circuits using photonics, for example? No, most of the benchmark circuits we've used are these, they basically implement like classical reversible logic. So they implement adders or Grover oracles or stuff like that. We haven't looked at things for photonics. We have implemented a few quantum chemistry circuits and those seems to work really well as well. But if you have some suggestions on what we should try then you can tell me afterwards. Cool, last question. This looks like we're good. So let's find the speaker.