How To Code A Quantum Computer
작성자 정보
 작성자 bryanai
 작성일
컨텐츠 정보
 조회 1,640
본문
https://www.youtube.com/watch?v=JOJ5zihcd6Q
How To Code A Quantum Computer
Have you ever wondered how we actually program a #quantumcomputer ? #Entanglement, which #Einstein called "Spooky action at a distance" and Superposition, which describes how quantum systems can have probability of being in multiple states at the same time, Allow for us to implement special algorithms which would not work on classical computers. Somehow measurement of a state instantaneously determines properties of an entangled partner particle, regardless of distance.
In this video, I aim to explain what quantum entanglement is, some of the math behind it, and how to create it in physical systems. #Physics can get incredibly confusing on a small scale because we as humans don't directly perceive how we interact with the laws of #quantummechanics, so join me as we explore what quantum entanglement really is.
Join My Discord: / discord
Become a patron: https://patreon.com/user?u=100800416
for access to my animation source code, video scripts, and research materials
Also check out my instagram: / lukasinthelab
 **Classical Computers and Compilers**: The video starts by explaining how classical computers work, focusing on how humanwritten code in languages like Python or Java is translated by compilers into machine code (binary ones and zeros) which the computer can execute using logic gates.
 **Introduction to Quantum Computers**: It transitions to quantum computers, introducing fundamental concepts of quantum mechanics such as superposition and entanglement, which form the basis for quantum logic gates, the building blocks of quantum computation.
 **Quantum Programming Basics**: The video emphasizes that programming quantum computers involves writing code in highlevel programming languages like IBM's Qiskit, which are then compiled and executed on quantum hardware, similar to classical computers but using quantumspecific operations.
 **Quantum Logic Gates and Implementation**: It explains the physical implementation of quantum logic gates using various methods (e.g., lasers, currents) and highlights the challenge of multiqubit gates due to their interaction with the environment, which can lead to errors.
 **Example Algorithm  DeutschJozsa**: The video concludes with a walkthrough of a quantum algorithm, the DeutschJozsa algorithm, demonstrating how it can solve specific problems more efficiently than classical algorithms by leveraging quantum superposition and entanglement.
How To Code A Quantum Computer  YouTubehttps://www.youtube.com/watch?v=JOJ5zihcd6Q
Transcript:(00:00) in this video I'm going to answer one question how do we actually program a quantum computer to do this we're going to have to take a tour through computer science and physics first we'll look at how coding works on classical computers so that we have a baseline for comparisons then I'll talk about compilers the software on classical computers that translates your code into computer language next I'll talk about what this computer language actually is this involves the binary ones and zeros(00:30) that that you often see in movie hacking scenes then we'll shift over to quantum computers I'll explain quantum mechanics superposition and entanglement using them to build up Quantum logic gates these logic gates are the operations that we actually use to act on cubits then lastly I'll discuss a specific problem for quantum computers oh also this is part one of a twopart series since I don't want this video to be too long I'll actually code the problem on IBM's quantum computers in the next(00:59) video anyway anyways to understand how to program a quantum computer you must first understand how to program a classical computer lots of you probably already know about the programming languages like python C Java and others but if you don't it doesn't matter these are programming languages that allow us to interface with computers by typing in things that are more or less similar to human languages by typing a specific set of commands and then running the resultant code containing file you can make your(01:28) computer execute those commands for example this is some code that I had chat GPT write because I'm too lazy that counts to 10 what you may not know is that the programming language that you type is not actually what the computer runs a compiler is a special program that converts programming language into machine language different languages have different compilers and each is a translator for that specific programming language the way that compilers do this is pretty complicated and Beyond the scope of this video so we can just think(01:56) of them as black boxes that take human written code as an input and output Mach machine code machine code is the actual code for your specific program that a computer runs a sequence of ones and zeros that tell the individual bits in the CPU how to operate importantly here I want to remind everyone that to the computer everything is ones and zeros the text on your screen the operating system the YouTube window that you're using to watch this video everything is ones and zeros the reason that I'm drawing a(02:24) contrast here between the regular ones and zeros that the computer sees and the specific ones that the compiler translates is because the computer can't run the program that you write from the sequence of ones and zeros that display what you wrote on the screen the computer needs to translate that sequence of ones and zeros into an actionable sequence of ones and zeros that it can use and that's what the compiler does but how does this machine code work machine code is a set of instructions that tell the computer(02:52) about the specific bits to operate on it contains ones and zeros which when read by a computer can be interpreted as direct instructions as to where it should send electrical signals the way that these operations are physically carried out is with logic gates logic gates are the fundamental building blocks of classical computers and work by taking electrical signals as inputs and giving different signals as outputs based on the inputs they receive these are actual physical circuits made up of bits for example an and gate can be(03:22) constructed which only lets current flow if both of the wires that go into it have current flowing meaning that both of the inputs are ones there are other operations that we can make other than and and we can chain these logic gates together to make more complicated circuits which can add and subtract numbers and bust information around to other bits once we can add subtract and transfer information around our computer we have all the building blocks necessary to run programs so to recap the code that we write as humans is translated by a(03:53) compiler or some other program into machine code this machine code is run on the processor where it instructs the computer to do a spefic specific series of mathematical operations using logic gates these circuits execute the actual computation by modifying individual bits inside the computer and create an output performing all of the instructions in the code now that we know how classical computers work we can talk about quantum computers quantum computers are also coded with high level coding programming languages like IBM's kcit these(04:24) programming languages are run on classical computers compiled on classical computers and then finally executed on Quantum Hardware I'm going to build up our intuition about programming quantum computers from the opposite way that I talked about classical computers when I talked about classical computers I talked about the highlevel code first then the compiler and then the machine code and then the bits for quantum computers since it's hard to have an intuition for a type of computer that does not exist at scale yet I'll first(04:52) talk about the building blocks the individual bits and the circuits the first of these building blocks are the principles of superp position and entanglement from quantum mechanics before I get into explaining quantum mechanics first let's define a system in physics a system is just what physicists decide to analyze with math usually we treat systems as isolated from the environment because considering all interactions with surroundings makes the math impossible for instance in high school physics we often ignore air(05:22) resistance because it's too complicated and it doesn't really significantly impact the results of our calculation physicists choose what's vital based on its impact on the outcome now a Quantum system is a physical system following the laws of quantum mechanics typically it's extremely cold or very small with some exceptions examples include electrons in hydrogen atom orbitals electrons in superconductors and ions which are charged atoms trapped in an electric field in quantum mechanics superp(05:53) position is where a given Quantum system has some probability of being in multiple States at the same time and it is not known even into the particle itself until a measurement is carried out these states could be energy spin angular momentum or some other important physical quality it really doesn't matter and different types of cubits use different properties depending on what works best for the case of that system once measurement occurs the superp position collapses and the particle is forced into a definite State(06:24) the probability with which a particle collapses into a given state in the superp position is dictated by the mathematical coefficients in front of each state in the superp position just Square the coefficients to get the expected probability that we'll measure the system in that state now the reason that this collapse happens is a hotly debated philosophical topic that's outside the scope of this video but it turns out that whatever your interpretation of quantum mechanics is it doesn't actually change the way a(06:51) quantum computers algorithms work so we'll worry about that in another video entanglement is another quantum phenomenon that is useful in Quantum computing computers when two or more Quantum systems are entangled measurement of the state of one system directly and immediately informs the state of the other before you ask no this does not allow for faster than light communication a simple example of an entangled state is a bell state in this Bell State we have a state with two Quantum particles there are four(07:20) possible combinations of the two bits 0 0 01 1 0 and 1 1 however in this Bell State we have prepared it such that there's a 50% chance of 0 0 and a 50% chance of 1 one the other two states have no probability and will not be measured in reality on a noisy quantum computer they'll be measured a very small amount but the point is that if we measure zero in the first Cubit then we are guaranteed to measure zero in the second Cubit if we measure one in the first Cubit then we're guaranteed to measure one in the second Cubit so the(07:50) state is entangled anyways we can combine super position and entanglement in Quantum algorithms to solve problems the way to do this is not obvious and is completely different depending on the type of problem you're solving in the same way that solving different problems on classical computers requires different code but how do we actually Implement these algorithms for simplicity's sake because they're the most concrete example to explain I'm going to talk about how to implement programs on neutral atom(08:17) quantum computers that said the general process will be similar for all types of quantum computers but the main difference being in the interaction between software and Hardware meaning the physical way in which we implement the quantum logic gates importantly the concepts of superposition and entanglement can be applied to any type of quantum computer whether it's neutral atoms superc conducting cubits spin cubits trapped ions or any others I'm talking about neutral atoms here for concreteness but I could be talking about any type of(08:45) quantum computer and the only thing that changes is how to physically implement the logic gates similarly to the classical logic gates a Quantum logic gate is just an operation that takes a cubit in a given State and changes it in some known and repeat aable way we can do these Gates on one or two cubits think classically we have the knot gate which flips a single bit and the and gate which takes two bits as inputs and only returns one if both of the inputs are one in neutral atom cubits instead of making circuits(09:16) like with classical bits these Quantum logic gates are implemented by shooting lasers at the individual atoms in different Hardware implementations this is the step that changes for superc conducting cubits for example instead of shooting a laser we'd apply some specific current anyways by shooting a laser at a specific frequency or color at our cubits we can change the state of our Cubit how do we know what frequency or what color to use well that comes down to knowing the frequency of the transition between the zero and the one(09:43) state if we know the transition frequency then we can do some math to calculate the frequency we need to drive at with a laser the actual frequency we drive at depends on the specific logic gate that we want to apply okay so now that we can Implement single Cubit Quantum Gates we can make a small leap to mult multiple Cubit Quantum Gates these are still logic gates except instead of putting our individual cubits into a superp position they entangle them these are the quantum analoges to classical two bit operations like and(10:13) one major difference however is that in a quantum computer all of our logic gates must have the same number of inputs and outputs this is different from classical computers where an and gate has two inputs and one output there's actually a deep physical meaning for this that has to do with the reversibility of on some computers but I'll do a separate video on that in different Cubit platforms multic Cubit gates are implemented in different ways but usually it's done by forcing some known interaction between two cubits in(10:41) our neutral atom system usually that involves promoting one of our atoms to a ridberg state this is a high energy state with the electron far away from the nucleus this charge separation between the positive nucleus and the negative electron creates a dipole moment which is an electric field that is generated when charges are separated from one another this dipole moment electric field interacts with nearby atoms preventing them from entering a ridberg state since the state of our high energy atom now dictates what(11:08) states the other atoms can be in they have now become entangled entanglement in other systems looks quite different but often it involves making the two cubits interact one another by some mechanism this is a major reason that in Quantum Computing two Cubit gates are significantly more difficult to implement than single Cubit Gates because forcing the cubits to interact with one another naturally means that they can also interact with their environment and lose information okay so now that we know a bit about superos and entanglement how(11:39) do we actually program a quantum computer well since we can build Quantum logic gates we can run an algorithm by stringing these together this is the equivalent of machine code for quantum computers it's the individual sequence of logic gates to be applied to our Quantum bits in order to carry out our computation often sequences of quantum logic gates are referred to to as a circuit while talking about individual logic gates is useful for education and for Hardware research in the real world we would never program a classical(12:08) computer directly with logic gates instead we code with programming languages similarly for quantum computers we do the same thing we make Quantum programming languages as an abstraction which need to be translated into machine code the same way as classical computers but it's also significantly easier to think in terms of code than in terms of what's happening to the individual bits so let let's go to one of these programming languages and see what it's like one major difference is apparent right away(12:35) classical computers are programmed on well classical computers when you want to write code to run on your MacBook or your Lenovo you write the code on that machine and then run it on the same machine quantum computers on the other hand are not coded directly on the quantum computer instead we use classical computers to interface with them we do this for two reasons one because quantum computers are currently not powerful enough to run any type of user interface so the alternative is to do it by hand and two classical computers are already(13:06) perfectly good for writing and compiling code so there's no reason to reinvent the wheel here coding a quantum computer starts off very similar to coding a classical computer we load up a notebook and we write some code in our favorite Quantum Computing coding language I'm going to use kcit which is IBM's coding library for quantum computers which is written in Python we can write some code in The Notebook here I'm just going to write some random mostly useless code to show you how it works and then we can run(13:33) that code when we run the code it compiles as it's running and translates the code from human language into a series of quantum logic gates which need to be applied to our cubits these logic gates are interpreted by a classical computer which triggers the actual Quantum Hardware to fire the specific laser pulses that correspond to the desired Gates this is the step where the algorithm is actually run on the quantum computer finally the result is measured and we get our answer now that we've gone through the general(14:01) process let's try working through an actual example I'm going to use a toy problem toy problems are problems that aren't super useful for anything in the real world but they're good teaching examples because they demonstrate how a system works in this case this toy problem shows how a quantum computer works very well so it's a great teaching example the algorithm is called the Dey algorithm which is the simplest version of the deuts josa algorithm now to be clear the deuts josa algorithm is also(14:28) not useful but the deut algorithm is the simplest case and it's easiest to show for a teaching example when I actually code up the algorithm in Kiss kit for the second video I'll code the deuts josa version but for now we're going to work with the simplest case here's the problem we want to solve imagine we have a function let's call it f on a configuration of two bits such that it is either one constant meaning all configurations are mapped to the same value or two balanced exactly half of the configurations(14:57) mapped to one and the other half m map to zero we know advance that our function is one of these two categories but we don't know which let's think first about the most efficient way to do this problem using a classical computer usually the way we think about this is to ask ourselves what is the worst case scenario when I run a given algorithm this is because code is often reused so you're likely to run into this worst case scenario at some point the worst possible scenario for our classical algorithm would be(15:25) where the function is balanced but also where the first two outputs that are recorded are both zero or both one meaning that the function looks like it's constant at first thus for us to be absolutely 100% sure whether our function is constant or balanced we need to evaluate three of the inputs this means that we need to run the function three times since we're coding a general solution and we don't know how this function will work we always have to prepare for this worst case scenario now what about the quantum case(15:54) it turns out that in the quantum case we can get away with running the function only once but first we have to understand what it means to even operate with this function on our cubits and to do that I need to explain some notation in Quantum Computing we use bracket notation we do this because it's super useful shorthand and prevents us from having to write long complicated math functions to describe the physical state that we are in bracket notation is really just a way to disguise linear algebra a bra is a row vector and a k is(16:22) a column Vector the gate operations like the hadamar gate and the not gate that I was talking about before are actually m es now if you don't know linear algebra you don't really need to know what this means because one of the conveniences of bracket notation is that for some Quantum Computing stuff you can kind of just sweep this under the rug and that's what I'm going to do in this case anyways just think of things in terms of the two bit States 0 and one when we apply our function to an input configuration AB we map the(16:51) General State AB to the state a B plus F of a here the B plus F of a is modulo 2 meaning that the result is divided by two which can only be 0 or 1 the first step of our algorithm is to prepare two cubits in 0 and 1 respectively we then apply the hadamar gate to both cubits I'll show what the mapping is for the hadamar gate here below the hadamar gate Maps 0 to 0 1 / < tk2 and 1 to 0  1 / < tk2 anyways we get the following result so by apply L it individually to each Cubit we've actually put our(17:31) quantum computer into a superposition of all possible answers we can see this by just Distributing out all of the terms using the distributive property so we have 0 0 1 0 0 1 and 1 1 the second step is function evaluation we operate the function on our second Cubit this is just done with a gate the same way the hadamar gate or other gates are applied now I won't tell you how the function is implemented because I don't know not because I don't understand how function implementation works but we're(18:02) doing this for a general case in reality this function could be any constant or balanced function and so I can't tell you a specific implementation because telling you that also tells you the function remember we're just trying to do this for a general case so we don't want to be specific here anyways if we apply the function to our second Cubit this takes our state to the following algebraic mess okay don't worry I'm going to explain what this means here we can do some case workk to get a better sense(18:30) for what's going on if F of 0 is 1 then we get the following where our first term picks up a relative minus sign if F of 0 is 0 then nothing happens so we can rewrite the state as follows to express this in some more compact math notation this equation says the exact same thing as the equation before only now we've reexpressed it by doing a little bit more algebra we get to the following state since we haven't done any two Cubit operations the second Cubit is not entangled with the first Cubit and actually the second Cubit isn't really(19:06) important anymore so we can forget about it this superposition depends on the outputs of f if we measure our quantum computer we get the following if f is constant then f of0 equals F of 1 it doesn't matter whether they're both one or zero just that the values are the same so let's take F of 0 = f of 1 = 1 for our example if this is the case then our equation becomes the following the other term vanishes because 1  1 equal [Music] 0 if f is balanced then F of0 does not equal F of one and we get opposite(19:47) values by similar reasoning we can equally show that we only measure one notice again this algorithm doesn't actually care about how the function f ever works it only cares that the function satisfied our criteria meaning that the function was either constant or balanced one more thing I just want to add in usually entanglement is generated inside the function f so we won't explicitly see it but you can get entangled States all right so that was the two Cubit case of the de josa algorithm which is called the de
관련자료

링크

이전

다음