Quantum Computer Programming w/ Qiskit

Quantum Computer Programming w/ Qiskit

sentdex

0:00 what is going on everybody and welcome

0:03 to a quantum computer programming tutorial series right out

0:08 of the gate I just want to stress I am NOT a quantum physicist I know

0:13 a little bit about things but I am just not an expert on quantum stuff okay

0:19 I would argue that it seems like nobody really truly is but I am less so

0:23 than most okay that might talk on this subject

0:25 anyways so my you my credentials are

0:30 Python you tuber especially give you a little

0:34 bit of understanding of my understanding of quantum

0:37 physics so with that out of the way I do want to at least give

0:40 a basic foundation of quantum at least in terms

0:44 of quantum computers I might say some wrong

0:47 things so I encourage you to go out and learn that yourself I think there's

0:51 really no shortage of material even just

0:54 on YouTube but just on the internet in general

0:57 in terms of concepts and visualizations and just

1:01 the theory of quantum mechanics and quantum computers

1:04 what there's almost nothing of is the actual

1:07 practical side of things so that's what I want

1:10 to come here and do so first of all what's a quantum computer so a quantum

1:14 computer is just made up of qubits

1:16 or quantum bits as opposed to our classical computer

1:19 which is made up of bits so the next question of course is what's a qubit

1:23 so a qubit is well first what's a bit so a bit is in your classical

1:29 computer it's just a is it's a transistor right and that that can be either

1:32 a 0 or a 1 and it gets its value from is it a high signal

1:37 so we send voltage through either it's a high signal or it's a low signal if

1:42 it's a high it's a 1 if it's a low it's a 0 so a bit

1:45 can be a 0 or a 1 a qubit on the other hand can be

1:50 a 0 a 1 or both wait that's illegal no I assure you apparently it can so

1:58 so it does this through two characteristics

2:03 that are unique to these quantum bits which are

2:07 superposition and entanglement so the idea of superposition

2:10 is it is anything it could be right

2:14 and it doesn't actually pick something until you

2:18 make the observation so so for example I think the mug is actually a pretty good

2:21 example right inside this mug there could be

2:23 water coffee tea I don't know hot fudge all kinds of things right and we

2:29 and in and so if this mug was in super position it would be all of those things

2:33 right and it's only when we look into it and be like Oh what do we

2:36 got do we does it collapse on one

2:38 of those values that's the concept of superposition

2:42 now to me and my you know I don't know lizard brain it says no there's

2:47 really only one thing in that cup so whatever but but I'm just saying hey that's

2:53 the property the next thing is entanglement

2:56 and the concept of entanglement is also magical

2:58 and this is kind of the if you've

3:00 ever heard the Einstein's spooky action at a distance

3:03 this is what it comes from so if two qubits are entangled a change in one

3:10 causes a change in another one instantaneously

3:14 and distances are relevant again I agree that's not

3:20 allowed it seems pretty spooky to me

3:22 but you know people much smarter than me assure

3:25 us that it's not actually spooky action

3:28 at a distance we're not violating certain laws like

3:31 transferring information faster than the speed of light

3:34 I mean that's what it seems like to me

3:36 but we are assured that is not is so anyway I'll leave the theorizing to other

3:43 people all I can say is we have these two properties how we have them

3:48 I don't know but we have them so cool hmm so that that's the difference between

3:55 a qubit and a regular bit now what

3:57 happens when we have these two characteristics is

3:59 in a classical computer the amount of like

4:02 states that you can represent right so each bit

4:05 has two states that it could plausibly be it could be a zero and it

4:09 could be a one right in a quantum computer it could be 0 1 or anything

4:15 in between so what or I hate to say anything that's incorrect I would say 0

4:20 1 or both states let's just stick

4:22 with that because it's like a multitude it's not like

4:25 it wouldn't be a scalar to my understanding

4:27 anyway I see the comment section is probably

4:29 blowing up with some experts anyways what

4:33 this means to us as programmers on the practical

4:35 side of things is a classical computer can

4:39 represent n bits times two states that's it

4:43 a quantum computer can represent two to the power of n bits States so this is

4:54 exponential this is massive it's a huge difference

4:59 right so how many states both we can

5:01 represent but also like consider so so quantum

5:08 computers are unlikely to just like replace classical

5:11 computers one because we kind of need classical

5:14 computers to work with quantum computers but also

5:17 it's not that quantum computers will solve all

5:20 the things that regular computers do or classical

5:22 computers do faster right it's not that it's

5:24 quantum computers will solve problems that classical

5:27 computers can't solve they just can't that it

5:30 would just be intractable impossible to solve right

5:34 or it would take a really long time

5:36 such as factoring numbers when it comes to like

5:40 factoring four prime numbers so for example breaking

5:42 encryptions one of those things gets thrown around

5:44 all the time that quantum computers could do

5:47 that's true so if you're somebody that owns

5:49 a database that today if somebody was

5:54 siphoning from it right now in twenty years

5:57 with that if that data would still be

5:59 highly valuable I'd be careful if I was you

6:03 because probably in 20 years RSA encryption could

6:08 is done yinz so so these are things we

6:11 have to think about I don't really think we're there now and also as you'll

6:14 see when we actually do the practical side

6:16 of things quantum computers have noise and error and we don't quite yet know how

6:22 to remedy that for some problems it really doesn't

6:26 matter for other problems like breaking encryption for example

6:29 it makes a huge difference so yeah so so the problems that quantum computers are

6:34 going to be and currently are and going to be useful for our problems where like

6:39 the state space is just just massive right so

6:44 these exponential things so a good example

6:47 to think about is like anytime you have many

6:49 combinations so one example that I see gets

6:52 thrown around by you know people that are

6:54 trying to kind of sell the idea of quantum computers is like logistics so if

6:58 you're delivering packages and you've got a route

7:00 that you need to take you know each kind of intersection that you pass is

7:04 in theory a branch that you could have taken

7:06 and before long each each turn that you

7:09 you pass or take branches out and creates

7:12 this just again intractable number of other possibilities

7:17 that you could have taken a classical computer

7:19 kind of checks each each one it kind of in a brute-force manner sometimes we can

7:24 use things like gradient descent or you know

7:26 something like that to to sort of optimize

7:28 this task but a quantum computer just simply

7:33 can analyze all of them all at once given

7:35 the correct number of bits but it doesn't take long to have that correct number

7:39 of qubits it doesn't take that long to have

7:41 enough qubits because there it's exponential so like

7:45 logistics is one another one is like modeling

7:48 for like molecules those are things in like

7:51 chemistry right now classical computers can sort

7:55 of model things but classical computers the best thing

7:58 that classical computer do can do is like get close to statistics we can sort

8:04 of simulate probabilities but it's not real probability

8:08 right whereas a quantum computer as best I can

8:12 tell dare I say is probability like it just it's just it's true so that's

8:18 the difference right so another kind of really

8:21 simple example that I think is easy to fit

8:23 in one's brain is like let's say you're

8:26 you're organizing a charity event and you're gonna

8:28 seat people at a table and ideally you'd want those people all to get along so

8:32 they're in a nice donating mood well if you have five people then that would be

8:37 you know in you've got like five seats

8:39 at a table you the the combination of people

8:42 that you could like you know what combination

8:44 do you want to seat people you only

8:45 have five people but the combinations are five

8:48 factorial right so this means it's five times

8:52 four times three times two times one right

8:54 so that's hundred and twenty combinations but if

8:58 you just add one more person it's because you went from five to six it's 120

9:03 times six now right so six factorial seven

9:06 twenty right and then let's just jump all

9:09 the way to like ten people it's like three point six million all right so as you

9:13 keep just any just one more one more option things get crazy so these are

9:20 the types of things that like you know

9:22 a classical computer could obviously solve for the hundred

9:24 and twenty and the classical computer can do

9:26 a pretty good job when you start getting

9:28 to six million or three point six million let's say but as you continue to go

9:34 further and further the classical computer at some

9:38 point it's just not even possible because at some point you at you end up

9:42 having more more possibilities than there are like

9:46 you know atoms in the entire universe so

9:50 you just it's just impossible right and so

9:52 we can prove that already we can definitely

9:54 have quantum computers that will eventually exceed clock

9:57 anything a classical computer could do in terms

9:59 of large state spaces okay so I I think that's really all I really want

10:06 to talk about in terms of the fundamentals if

10:08 you've got questions feel free to ask them if I said something silly feel free

10:13 to correct me below like I said I'll

10:15 put some other resources in the description but let's

10:18 say you're interested in this stuff you know

10:20 you'll want a quantum computer what do you

10:22 do well it turns out as you might expect building a quantum computer I mean I

10:28 don't know exactly how much would go into it but I'm gonna imagine that if you

10:33 wanted to start from scratch it's probably like

10:35 at least a 100 million dollar enterprise you

10:38 you can buy like I've seen that d-wave has sold at least one quantum computer

10:43 for 15 million D waves quantum computers are

10:46 different from what appears to me to be everyone

10:50 else's and I'm not intelligent enough to explain

10:53 exactly why but something tells me that they're

10:56 questionable compared to the differences are questionable

11:00 at least so so let's I'm just going to throw out that they're probably about

11:05 a hundred million dollar device right like it so

11:07 you so if you Google's you know 50

11:10 qubit quantum computer or rpms or whatever so so

11:14 they're expensive whatever the heck they are so

11:16 what do these companies do with them well

11:18 it turns out they just connect them to the cloud and anybody can connect and run

11:23 these quantum circuits on them for free that's

11:29 incredible to me this seems like it's like

11:32 the equivalent of like if NASA was like hey you can drive the Mars rover just

11:37 connect to it and drive it around Mars that's what it seems like to me it's

11:41 this incredible but I think the thing is right now we're in a time where nobody

11:45 totally knows what exactly are we going

11:47 to use quantum what all can we use quantum

11:49 computer computers for and so it's just like

11:52 a big kind of experiment right now so anyway

11:54 what a cool time to be alive that we can even play with these machines

11:58 so yes we will play with actual quantum

12:02 computers as well as simulator so I think

12:06 we've got the time let's go ahead and set the set the mood so first

12:13 of all I'm gonna be working in the following

12:15 I'm just gonna have this quantum computing tutorial

12:17 and then we're going to we're gonna install

12:21 something so let me get out of the way-

12:23 I'm assuming everybody at if you're following

12:25 this tutorial please know the basics of Python

12:27 and installing packages if you don't I will try my best to put a link

12:33 to the basics tutorial in the description but otherwise

12:36 go to Python programming net go to the fundamentals

12:38 and learn Python the basics of Python it

12:42 you honestly could learn the basics of Python

12:44 I feel like in a day maybe that's unfair but days uh okay so yeah

12:51 so cool so moving on what we're gonna need for this series is some form

12:58 of piff I'm gonna be using Python three

13:00 seven so really I would say pip three seven

13:02 but depending on what operating system yeah it's

13:05 gonna vary but mostly pip install and then

13:08 we're going to be using kiss kit that's Qi s k i— t— hi i'm gonna

13:16 be doing things in a jupiter notebook so jupiter lab if you want to use jupiter

13:21 notebook you can use whatever editor you want

13:24 matplotlib and then kiss kits IBM Q and then

13:31 provider and so if that doesn't give it

13:33 away we're gonna be using IBM's quantum computers

13:36 so there's a lot of providers like d-wave has them in the cloud Google has I

13:41 think in the cloud Microsoft definitely does

13:43 and then yeah IBM I'm sure there's other providers

13:47 I'm spacing out right now I kind

13:49 of poked around everybody's and honestly the IBM is

13:53 in my opinion the best by far first of all you can get set up I'm

13:58 gonna hopefully I'm gonna be yakking and explaining

14:00 things but you can honestly get set up

14:02 and running in like a minute or not a minute let's say two minutes on IBM

14:08 stuff so anyway shouts out to IBM for forgetting this right and then kiss kit I

14:15 don't know if it's people at IBM who made kiss kit or what but they seem

14:18 to be entangled I'm so cool so install those things I'm not gonna run it because

14:26 I've already installed those instead what I'm gonna

14:29 do Jupiter lab Oh also on at least Linux I found that a kiss kit IBM

14:37 cube provider might get installed with kiss kit

14:40 and then it's like you already have this it's fine and then I attempted to use

14:43 it and it didn't work so I needed to do a sudo pip install upgrade force

14:48 reinstall of that and I also got

14:51 a warning about mismatching version numbers after force installing

14:57 it everything was great but if you have

15:00 a problem please let me know even though I

15:02 think IBM is doing a phenomenal job here with this all of this stuff is is

15:06 fairly buggy for what it is it's awesome but just expect to be mean to be

15:14 patient I'll also try to put the slack for a kiss kick kiss get has

15:18 like a slack channel and at least when I needed help I got help pretty quick

15:23 and it was actually useful help so anyway I'll try to remember to put

15:26 that in there but yeah there's there's so

15:28 many things to talk about it in point you

15:30 to and stuff so I might forget something

15:32 but if I forget someone doesn't remind me

15:33 and I'll put it in there anyway Jupe Space Lab to open a new book okay so let's

15:47 get this good enough okay so let me name this kiss kit 1 or something like

15:56 that obviously just I'm assuming you guys aren't

15:59 amateurs but kiss get one just name it

16:02 something that isn't kiss kit dot pi because

16:04 watchlist ipython notebook you get away with it

16:06 probably anyway just a good idea not

16:10 to name it exactly the thing that you're going

16:12 to use so let us go ahead and get started but actually before we get started

16:18 you could actually start with kiss gate but you're gonna have a hard time so I

16:24 might have to do some blurring if I screw this up but I'm gonna show you

16:28 guys how to set up I think because we're gonna run on a quantum computer first

16:31 but so so probably before we get started the next thing we should do is go

16:35 to quantum- computing dot IBM comm so let me see if I can just bop over

16:42 there yeah so you'll have to make an account and if I think you can just

16:49 connect your Google account anyway I forget how simply I set a gut set up here

16:54 but anyway you'll need to do that and then you click on this my face

16:59 is on it let me do this cool this little account icon if you click

17:09 on that and then you go to my account

17:10 you'll see you'll have a token here hopefully

17:12 I'm not showing anything else so I don't

17:15 think I am and just click copy token which

17:18 reminds me I need to copy over a token dang it I'm gonna have to edit

17:25 this video let me do it so actually I might have to edit this video so

17:32 I am going to have my token in a separate file because I just don't want

17:37 to show it but you don't necessarily have to have to do that I just don't

17:41 want to end up showing it on on camera so token so I saved mine

17:47 in a file called token dot next and then if I go back to where we are

17:53 pasta boom done don't have to edit nice so you would copy that token and then

17:59 you would use it in a moment so just take note or you could copy it I

18:04 think you'll be fine we won't do any

18:05 copying and pasting until we need it anyways

18:07 so now what we're ready to do is import kiss get as q all of the like

18:13 official kiss kit tutorials that I've seen

18:15 do from Kiska import asterisk I think that's

18:19 the only thing I would complain about don't do that guys it's not that bad form

18:25 that form and then Matt plot lib

18:27 in line and kiss kit just simply somewhere along

18:33 the lines is imported I think when you

18:34 do your visualization tools they just import matplotlib

18:37 and then this is just notifying Jupiter notebook

18:39 to plot in line like in the actual

18:42 notebook so if you are not in Jupiter notebook you don't need a tight man plot

18:49 limit line okay so now we're going

18:52 to define our actual circuits so again with quantum

18:55 computers we're working with the bits so so we that's how far down we're going

19:01 so I it's painful as a Python programmer I know but we got to start

19:06 at the bit level and this is partly

19:08 why we're going why I don't see quantum computers

19:12 at least and not anywhere in the near

19:14 term replacing classical computers because we actually kind

19:17 of need to work with both of them so with with with what we're gonna do

19:24 here generally you'll have you know Python doing

19:27 the most of your logic or a bunch of your logic and then for a certain

19:30 task you'll pass it through a quantum computer get

19:34 your your response so the way it works

19:36 generally is you're going to define your circuit

19:38 right in Python and then you it's just kind of a representation of the circuit

19:43 you pass it through the quantum computer

19:45 the quantum computer does its thing and then actually

19:48 what it does is even though so it runs it through and it runs it through

19:52 these qubits and then spits back out the answer and it spits out the answer

19:56 in bits so classical bits and again this will

20:01 make more sense I think as we actually

20:03 work with this so anyway I'm just trying to explain as we go so we we

20:07 have to build these circuits and these circuits

20:08 or these like bit circuits welcome to CS 101

20:13 so cute dot quantum circuit and then what we're gonna say is 2 comma 2 another

20:21 thing that I kind of noticed was the the shorthand here for how to actually get

20:27 away with this varies so I've I've I've kind of been running through a bunch

20:32 of different you know documentation and stuff like

20:34 that and over time this appears to have changed

20:37 and it might change some more in the future but so sometimes you'll just see two

20:41 here and I'm not sure how that would have ever worked but anyways it it has

20:45 worked for me so anyway whatever I guess

20:50 I guess you could probably get away with two

20:52 if all you were doing was pluck we're

20:54 like not actually running it and taking measurements

20:56 anyway I've personally found that confusing but what

21:00 these each value means is basically the it's

21:02 two qubits and then we'll have two classical bits so then what we're going to do

21:09 is circuit circuit dot X so this is a a not gate so we're gonna

21:16 say we're gonna apply a not gate to qubit 0 so by default these bits are

21:23 going to start as zeros so we're going to say ok cubits cubits zero not so

21:29 we're just flipping it okay so now qubit zero is so let's say just to make

21:35 it super clear so currently qubit let's just

21:40 assume these are qubits it's just a 0

21:42 0 we're saying ok qubit cubed 0 not now so then we're gonna say 0 1

21:48 or 1 0 trying to help now what we're gonna do is apply a circuit dot

21:57 Z X this is a control knot or a C naught and this basically intent it's

22:04 it's I guess maybe the more probably one of the more common ones and this will

22:10 entangle the to two qubits so you're gonna

22:12 pass two through here but also what it

22:15 does is let me just note it here so it's a C naught or controlled-not

22:21 and it flips second qubit cube qubit value

22:28 if and only if the first qubit qubit is

22:36 a one writer is on basically so so we'll see X and then it's going to be

22:43 0 and 1 so in theory you could actually you could put other qubits in here

22:47 we only have to anyways so but what we're saying so we flip this so

22:50 this circuit now or this qubit rather is

22:53 1 so already knowing that it flips the second

22:57 qubit so it flips qubit 1 if the first qubit is a 1 is let's say

23:03 is a 1 just to be clear so what will happen right so what we should

23:08 get in return at least up to this point right should be a 1 1 right

23:12 because we flipped qubit 0 to be a 1 so then what we could say is

23:18 we don't have to say this as again was kind of confusing to me when I

23:22 was going through things but we take our measurement

23:24 so when we measure it's important to understand

23:27 that as soon as you take your measurement

23:28 if you did have qubits in superposition they will collapse into a value so more

23:36 on that later but just know that at this point

23:39 now we're actually measuring we're looking inside

23:41 the the Schrodinger's box with the cat right

23:45 so we're going to see what's in the coffee mug so we measure mmm and then

23:51 again I didn't quite understand this but it

23:54 slowly began to make sense we specify the actual qubit register how it is going

24:00 to map to the classical bit register so we're

24:05 going to say 0 1 here and then again whoops 0 1 so it's going

24:11 to be a direct representation of qubits to class

24:15 or rather yeah qubits to classical bits what

24:18 this means is the value after we take our measurement the value for qubit 0 is

24:24 what we're going to return for classical bit

24:26 zero and then the same thing for number

24:29 1 so what we should get at this point when we take this measurement is one

24:35 one as classical bits so again with quantum

24:39 computers you take in that whatever the the circuitry

24:42 is right you're gonna probably use

24:44 a classical computer to build the circuit logically

24:47 with with beautiful programming languages like Python then

24:52 you're gonna pass them through this this quantum machine

24:55 which is gonna run this quantum circuit

24:58 with qubits and then after we got the qubit

25:01 answer we're going to translate that answer back

25:04 to classical bits so that we can pass

25:07 that then back to our beautiful Python language

25:11 and do the next things that we plan to do for now we're just building circuits

25:15 so that's that's all we're going to do

25:17 so so we take that measurement and then what we can do at this point is

25:23 there's some really cool methods in here whoever

25:26 made these I don't know if you're watching

25:28 probably not but whoa so circuit draw what we get is a ASCII representation

25:35 of this circuit um that is really cool

25:40 that the amount of thinking that goes into making

25:43 a visualization like this this way is really

25:48 cool so awesome job whoever made that so

25:51 another option you have is circuit dot draw

25:54 and then is it back-end I have to check

25:57 oh no its output I always want to say back-end but its output equals MPL

26:00 this is matplotlib so now you get a more

26:04 pretty representation but I really like these I

26:06 really like this one yeah anyway here is

26:12 kind of how they denote the measurement so

26:14 actually the first time I was started I

26:16 was like looking at the actual outputs here

26:19 I was a little confused because I didn't know what was this right and so

26:24 this is the symbol for measurement same thing

26:25 here it's a plus sign rather than I'm sure

26:28 that's the that's coming from historical things

26:31 but like why isn't like this is an X but then a controlled-not looks like this I

26:36 don't know it's a little confusing but anyway you can see here you've got

26:39 your your your classical bit number here and then here

26:44 I don't know I just like this one better I think but anyway you can see

26:48 here this is our not gate right and then this is our controlled not gate like

26:52 it's based on this value here and then these M's we take in our measurement just

26:56 a nice way for us to kind of see where we're headed so from here we

27:02 can actually run these things through our quantum

27:07 machines now you can either run it through

27:08 an actual quantum machine or you can run it through a simulator so you would use

27:12 the simulators just when you're doing R&D but then

27:15 when you're actually ready to do your true

27:17 research you want to see what the actual answer is that's when you're gonna feed

27:20 it through a you know an actual quantum computer so you can you can do either

27:27 of these two things but I know everybody is going to want to at least try

27:32 once to run things on a quantum computer

27:34 this way when you're done you can actually update

27:36 your resume and call yourself a quantum programmer now so so in order to do

27:41 this mmm I'm gonna show you guys and you

27:44 may follow along but especially if you're following

27:47 along on the day of release feel free to do it but the queues will probably

27:52 be quite long so do what you want but anyway what we're gonna do is make

27:58 some space and what we're gonna say is from kiss kit we're going to import IBM

28:02 q and then we're gonna say IBM Q dot save underscore account and then you would

28:13 put your token in here so you might even still have it copied paste it

28:17 in there for me I saved my token to a file so I'm actually gonna say oops

28:21 I'm going to sit one of these days I'm going to say open token texts

28:30 open token text dude we'd better wrap it up a token text and then dot read

28:40 and then close it all off cool so I could run that it's going to say

28:46 the credential is already exists because I've already

28:47 done this so you actually only need to do

28:49 this once it saves it so in your other programs you don't really need to do

28:53 that so you only need to run that one time and then to use it subsequently

28:57 just do IBM Q dot load underscore account and there we go so it's an account

29:07 it tells you hey this is an IBM Q account blah blah blah and then now

29:11 what we can do is actually start working with IBM q which is this here which

29:16 then gives us access to these following back

29:19 ends so continuing along to actually send it

29:24 send something to those backends what we're going

29:27 to say is provider first of all is

29:30 going to be equal to IB M Q dot get underscore provider and we're going to say

29:39 IBM dash Q that's our provider and then we have a bunch of backends now

29:44 there's a few ways that we can access these backends one is you could just look

29:47 and pick one of these if we go to the home page you can see here

29:52 like IBM Q or IBM yeah IBM q ml born has a Q of 87 jobs which

29:57 is a ton of jobs I don't know what the deal is when I'm like when

30:01 I was working with this initially there there's

30:03 like no competition there was like the queues

30:06 were all super short but today it's just

30:09 going nuts so interesting anyways and the jobs

30:14 seem to be taking longer like I said

30:16 there's a lot of variability here it's buggy might not be the right word but it

30:21 you patients will be required sometimes anyway IBM

30:26 q get provider I mean cool so now what we could do is for for beck

30:31 and in provider backends we're going to try this is going to be a terrible cubit

30:39 cubit underscore count equals len back-end dot properties

30:45 'don't cubits we're trying because one of them

30:49 is a simulator accepts werner you were gonna

30:52 handle the exception we're just going to say

30:53 cubit count equals simulated and then we're going

30:59 to print and we'll just make this a nice

31:01 f string we're going to say back-end dot name has and then we're going to say

31:07 back-end dot status and then dot pending

31:11 jobs queued and qubit count qubits cool hopefully

31:22 that works no cube always spelled qubit run okay qubit qubit count area qui bit

31:34 and we spelled cued wrong terribly wrong let's

31:39 run that one we're done okay so um it's

31:46 in simulated huh cubic count back and properties

31:49 cube do we spell we spoke qubits wrong

31:51 again that's why cubits cubits that's why you

31:54 don't on yeah that's why you don't not

31:59 handle your exceptions but anyway so so real quickly we can just kind of see ok

32:04 well the chasm simulator does have any cubed

32:07 that's cuz it's a simulator so it should

32:09 run pretty quick and then I bet they don't even have a queue for it

32:12 and then here we can see okay there's

32:15 fourteen cute eighty-seven cube we can see immediately when

32:18 we're actually running our script and then later

32:19 you can even work this in to pick

32:22 the exact back end right before you want to run so you get the lowest queue

32:27 so long as it has enough cubits so

32:29 different ones have different cubits right the biggest

32:31 one available to me has fourteen cubits whereas

32:33 the rest of them have five so at least

32:38 right now the lowest queue is IBM cube Burlington so we could say okay let's use

32:42 that one mm so the next thing that we're gonna say is from kiss kit dot

32:47 tools monitor import job underscore monitor what

32:53 this does is it tells us where we are

32:55 in the queue and then where we are when we actually go to run the job

32:58 so we're gonna say back-end is going

33:00 to be equal to provider dot get underscore back

33:03 back-end and then we're going to pass

33:06 the name so we said IBM cube Burlington we'll

33:09 just go with that one that's fine so that gives us our back-end then we're gonna

33:13 actually say our job is going to be Q dot execute and then we're gonna execute

33:20 the circuit that we built and then we're going to say the back end is whatever

33:24 back-end we chose and then shots this is how many times we want to send it

33:29 through because again every time you take

33:32 a measurement it collapses to one value so we

33:35 want to send enough shots through to get

33:37 a decent representation so I'm just gonna say

33:39 504 now so then after well as we run CUDA execute it's gonna stored a job

33:45 but we also want to do the job monitor for that job so let's hope

33:51 that works and if it does I probably have to pause and wait as we see

33:55 what kind of cue I'm in okay we

34:00 are fourth and cue mmm sometimes this runs pretty

34:02 quick like historically like I said if I was fourth in line it would take less

34:06 than a minute but lately it's been taking a lot longer so we will see I'm

34:12 gonna code that at least the next block and if it's done then it's done

34:17 and if it's not done I'll probably just

34:18 pause or something and then if you're running one

34:21 you can either pause or you can just break the current you know just hit stop

34:24 and then run it on a simulator and then later come back and run it you

34:28 know maybe when you're gonna go eat dinner

34:29 or something wait in line and actually run

34:32 the code but anyway so so yeah so once that actually runs we end up getting

34:39 something from the job which in this case will be a result of it'll be it

34:45 basically be 500 results which are just

34:47 these counts of what are the the actual bit

34:50 values that we got in return and it'll

34:53 be 500 examples because we ran this through

34:56 the circuit 500 times so now we're going

34:58 to say it's from kiss kit dot visualization we're

35:02 going to import plot underscore histogram and again

35:05 just like that ASCII thing and even this is really cool for matplotlib like

35:09 these are all very hard visualizations to make so

35:12 really impressed with whoever did all the visualizations

35:14 for for kiss couture I assume it was

35:17 probably multiple people but anyway pretty cool one

35:20 spot line closer so apply histogram and then

35:24 from mat plot live I'm going to import style you may or may not need

35:27 to do this if you're on a dark theme like me you will at least if you

35:31 want to see numbers and then so I'm gonna say style dot use and I'm going

35:36 to all this dark background and then we're

35:42 going to say result equals job dot results so in this case it will be these like

35:47 it'll be a result object actually but basically

35:50 what it like I said what it is is it's going to be a collection

35:55 of bit values right so it should be a collection of you know in this case

36:02 there's there's four possibilities because it could be a 1 1 a 1 0 0 1

36:08 or a 0 0 in theory it really could only be one of those things but you'll

36:15 see in a second so job dot result and then let's do counts equals results dot

36:22 get underscore counts for the circuit and then

36:28 we will do plot underscore histo gram

36:33 for the counts and then we'll say legend well

36:40 we actually don't really for this one we don't

36:42 need a legend that's where are we in the job still in third place Oh terrible

36:47 and then obviously everyone's job is a little

36:50 different so some people's jobs are pretty quick

36:52 like when we go to run this I feel kind of bad because everyone's gonna be

36:56 running jobs but our jobs are actually really

36:59 quick like we don't really take that much time to run this little simple circuit

37:03 but anyway so then anyway whenever this is

37:06 ready we would run this now unfortunately I'm

37:08 still third in line don't really see any

37:10 reason to stay here second in line I don't want to sit for too much longer

37:14 but while we wait I will say shouts out to the recent new channel members I

37:20 am sure Chung Chris Austin Meyer Dean ariya

37:25 and Corey Schaeffer thank you all very much

37:28 for your support you guys are awesome especially

37:30 Corey Schaeffer if you like Python programming tutorials

37:33 and you want more check out Corey shavers

37:36 channel if you just type that in to search

37:37 you'll find his channel really good good tutorials so anyways I am Oh our job

37:43 is running look at that perfect timing so

37:46 our job is running hopefully we don't get

37:48 any errors if you do get errors is it job that Aaron maybe get errors I

37:53 forget what it is there is a way to to access your her actual errors

37:57 but even this job is taking a while so I said I think something's going on today

38:01 that is making things run a little longer

38:04 than normal people I thought it was quantum

38:07 computing I thought it was supposed to be

38:09 fast Oh has successfully kisk it visualization visualization

38:16 I was like oh no do we hit an error huh I just type out visualization

38:20 let's try one more time cool so we get our counts now this is why we

38:24 can't actually break encryption so as you can

38:28 see the the most common response was one

38:32 one which is the the one we were supposed to get but as you can see

38:36 we got some zero zero sum zero one and some one zero why is that we

38:40 have quantum noise notice how everything in quantum

38:44 physics just sounds awesome like this is a quantum

38:46 tutorial I'm a quantum teacher this is

38:49 quantum errors but anyway it's because of noise and a lot of noise my gosh maybe

38:57 that's what's going on I don't know what's going

38:59 on if they're like throwing a party in the same room that they have the quantum

39:02 machines who really knows but they're susceptible

39:04 to noise like a change in temperature even right

39:06 so these qubits are stored at like as close to like absolute zero as possible it

39:13 is colder than outer space right as far as we know it's like the coldest it's

39:19 the closest place that we know of which is also nuts by the way anyways mmm

39:24 so okay so a sense that took so long I think the next thing I'm going

39:29 to do is just run this through a simulator if you're finding it to go

39:33 fast feel free to keep running it through the real backends also if if you you

39:40 can run it either through the back end you can run it through the actual chasm

39:44 simulator which is this one here or there

39:47 is the local version that you could run

39:49 but for now I think I'm actually just going to run things on the chasm simulator

39:52 so I'm just going to change the back end before I forget to Kasim Kasim I

39:59 don't need to type that I can just copy a copy pasta and now what I'd

40:07 like to do is actually change our circuit a bit so so what I'm gonna do I

40:14 think we'll just copy what we have up here I'm just gonna copy that come down

40:19 here pasta so we're still going to be a 2/2 we start we started by flipping

40:25 X but instead what I want to do this time is use a Hadamard gate probably

40:32 butchered his name as well anyway what

40:36 this does is it puts whatever qubit you pass

40:38 here and a superposition so now we'll see the result of whether this qubit was

40:43 a 0 and a 1 depending on how many shots we end up taking so again we'll

40:50 take 500 shots though just so we do see what the result is so we've so

40:55 this one was in is entangling qubit 0

40:59 and 1 together so we already saw entanglement

41:01 but we did not see superposition and really

41:03 superposition is I mean they're part they're both

41:07 pretty valuable but superposition is the one that's

41:10 maybe more bonkers but I don't know entanglement

41:12 is pretty pretty Bunker's as well anyway

41:14 so we're gonna run them through the simulator

41:16 and so we've got the backend simulator buhbuh

41:19 blah circuit draw we take the measurement there so

41:22 let's go ahead and draw that circuit make sure it makes sense so as you can

41:25 see we have the atom art gate here but otherwise you've still got that see not

41:29 gate and then we take our measurements so

41:31 the only thing that we flipped is rather

41:32 than flipping qubit zero now we're saying actually

41:37 cubed zero so when we flipped it we just

41:39 said cubed 0 is 1 basically now what we're saying is qubit 0 is actually

41:43 in superposition and then we're running the rest

41:45 of the circuit so that's our circuit now we

41:48 can actually run that on the back end so again we're just gonna say job

41:54 that executes monitor job so we're actually using

41:56 the the chasm simulator so we'll still connect run

42:00 the job and then we'll get our result so copy this come down here pasta

42:08 that this time as you can see we got two major results either a 0 0 or 1

42:14 1 makes total sense because again we're using this C not gate and the only time

42:19 it will flip that second bit is if the first qubit is a 1 so it's

42:23 either going to be at 0 0 or a 1 1 exactly what we expected

42:27 and as you can see since we use

42:28 a simulator it's simulating a perfect quantum machine which

42:33 we don't have but that's why you don't

42:35 see the other options because it's it's simulating

42:37 as if we had a quant a perfect quantum computer we don't so if I if

42:43 we were to run this exact same circuit feel free to if you want but if

42:46 we were to run this exact same circuit

42:48 on an actual quantum machine we would have

42:52 found that we got vastly different results right

42:54 or not vastly different we would have found

42:56 that it was 0 0 and 1 1 were the highest bars but we would have

42:59 also seen some noise ok so finally just in case you know you're on the airplane

43:06 right and you don't have you didn't feel like paying 20 bucks for the Wi-Fi you

43:11 can also run locally on a simulator so that's the last thing I'm going to show

43:17 before we bounce out of here so the other option is from kiss can't kiss kit

43:22 import air so this is your simulator framework

43:26 or a kiss kit and then we're gonna

43:29 say the sim back-end equals air get underscore

43:34 back-end Kasim Kasim simulator and again there's also

43:39 multiple backends here you've got the chasm simulator

43:42 a unit teri simulator and then a date

43:47 vector I think but we can also iterate over them so I'll do that real quick so

43:51 we could say for back-end in air don't get back in flips bat back ends prints

44:00 back-end dirt get back ends really what did I do wrong here air get back end

44:13 is it back oh I try to do the same thing before all right good ok

44:18 so we've set our sim back into already be the chasm simulator but as you can

44:23 see you get state vector and unitary so

44:25 again this is what represents and is most

44:30 closely like the actual quantum machine that you're

44:33 going to use right you're going to pass

44:35 it through a quantum machine and each time

44:39 you make one pass you get one measurement

44:41 right things can be in superposition but as soon

44:43 as you take a measurement you that superposition

44:47 collapses down to that value right so you're going to pass 500 times so there's

44:52 the return you get from the chasm simulator

44:55 is going to be counts for however many shots

44:57 you passed state vector on the other hand

45:00 you could actually just pass one time what

45:02 you'll get back is all of the possible

45:05 states right because it's a simulator okay so

45:08 one thing to take into consideration though is

45:10 if you're actually working on real quantum like

45:13 problems the state vector simulator is going

45:15 to be a problem because you're going to have

45:17 to store all of the states and memories

45:19 so the whole point of quantum machines is

45:21 so we don't have to do that or that we're going to solve problems that we

45:25 can't do that on a classical computer so this is really cool and it comes

45:28 with a bunch of extra visualization type stuff

45:30 that we can do same thing here they're

45:33 all really good but but the chasm simulator

45:36 is most closely related to what we're actually

45:38 doing here so anyway so once we've got the sim back-end again we can run all

45:44 of these exact same things so I'll just

45:46 take this pasta and then rather than back-end

45:50 will say sim back-end and then we'll do

45:53 this loop wait for add because we're running 500 shots so don't forget and again

46:04 our simulator locally is also perfect so we don't

46:07 have any error so we only get zeros

46:11 around one one but okay I'd say that's enough

46:14 it looks like I've been recording now

46:16 for 46 minutes that's a good introduction to quantum

46:19 computers like I said not an expert but there you go moving forward I don't know

46:24 you know I don't know how long this series will be when the next video is

46:27 coming out I'm going to keep tinkering around

46:28 I think it's really cool it's a it's

46:30 a completely new paradigm it's a new way for us to have to think about computing

46:35 so it's just really interesting to me

46:38 and I also think it's just awesome that you

46:40 can run things on a real quantum computer like I said I'd find it similar

46:44 to if they if NASA let you control

46:46 the Mars rover so anyway really cool to continue

46:51 along like I said I'll put some some

46:53 further resources in the text-based version of this tutorial

46:56 also if you just go to that quantum- computing to IBM comm and then click

47:01 the little thing it looks like a jupiter

47:02 notebook you get start here and that has

47:04 a bunch of links to further information there's

47:07 also a textbook that i linked in the text-based

47:09 version of the tutorial why are you taking so long thank you it's got a whole

47:13 bunch of information here I would at least you know if you really want you

47:17 can go through all of this kind of stuff here and then there's the advanced one

47:22 so you've got advanced and fundamentals there's

47:24 a bunch of stuff there's just so much information

47:26 and like I said I think its side I think iBM has done a really good

47:29 job of just getting all this stuff out

47:32 there and making it really quick and simple

47:34 to get running right so yeah pretty cool

47:37 also again things might be buggy also if

47:42 especially the day I released this video chances

47:45 are the queues are gonna be massive you

47:47 might want to wait you might just want to use the simulator and then run it

47:51 later or something like that but okay that's

47:54 all for now questions comments concerns feel free

47:57 to leave them below come join us in the discord that's discord GG slash sent Dex

48:01 again thank you to the new channel members

48:03 and I will see you guys in another video

Study with Looplines Download Captions Watch on YouTube