>> Earlier I talked with Dr. Sara Kaiser
about how she got into quantum,
how she got into tech,
and some of the stuff that she does.
Now she's actually going to walk us through a demo using Q#.
You don't want to miss this, check it out.
[MUSIC].
>> Hey Sarah. Talk us through
the demo and tell us what we're looking at.
>> Yeah. I'm going to show a couple Hello World examples for Q#,
what it looks like to use Qubits.
Qubits are the direct analog to bits in your classical computer.
They're kind of the fundamental unit of
information in a quantum computer.
We'll look at how we actually use those.
Then I'll show an example of an algorithm
called the Bernstein-Vazirani algorithm that
actually shows a pretty clear example
of the speedups that you can get with quantum hardware.
>> Awesome.
>> We've got a demo here.
I've got basically some code cells like a Jupyter Notebook.
You can see a good Hello
World example is basically you just
make a string that print something out.
I've defined a function here called Greeting.
You can see it takes the argument's name, which is a string type.
So Q# is a strongly typed language.
I like types I like seeing. Hopefully you are.
>> Yeah, same.
>> What should go where?
Now that the kernels spun up,
this lets me know that that's been added to our environment.
There are tons of different ways to run Q#.
I'm currently running from a Jupyter Notebook.
So I'm basically going to ask
the Jupyter Notebook to simulate this function,
and pass at the parameter that I want.
So Hello World, Christine.
>> Nice. I love it,
and I love that there's also a heart there. That's awesome.
>> Yeah, I'm sorry.
Tech does not have enough sparkles and hearts in it,
so you'll find this all over in my commit messages.
That's a good first bit.
If we go and talk
a little bit about using Qubits and what that looks like.
Qubits in Q#, think of them as a resource
that you request from the runtime when you need them,
and you return them when you're done.
I'm going to start here by opening one of the libraries.
Q# comes with a ton of
really great libraries with a lot of stuff just
already defined and you don't have to re-implement them.
Here, I have an operation.
Operations here meaning I'm actually going
to interact with something that's not deterministic.
Qubits are not necessarily deterministic.
What I'm going to make is actually basically a quantum coin.
This is a quantum random number generator.
That's what QRNG stands for.
Here, I'm using the using statement
to ask our runtime for a Qubit.
I'm going to do an operation on it.
That's this H here.
This is the Hadamard operation and
basically puts our Qubit in superposition.
You've possibly heard that word
before in relationship to quantum stuff,
but it basically means I'm putting it in
a linear combination of both zero and one,
and then I'm just going to measure and reset to that Qubit.
What I would expect if I simulate this is
basically a 50-50 head coin toss.
I can simulate that a bunch of times.
This is like a really basic,
I guess, Hello World but for Qubits.
You basically make this coin flip machine.
Now that we've seen at least the basic Hello World,
our Qubit Hello World,
let's actually look at what
an application might look like for this.
First I have to set up a little bit about a problem.
I'm going to give you Christine,
a function which takes a dot product
between an input string
and a secret string that's hidden in this function.
Basically you have a bit string that goes in,
it has a secret bit string,
and you dot-product them together.
I will also give you a quantum oracle.
Quantum physicists are really whimsy about their naming.
There's tons of Merlin, and Arthur,
and Oracles and stuff all over in the theory papers.
There's even magic states, which is awesome.
But a quantum oracle is basically a way that we can take
a classical function like the f of x function that we have here,
and run it on a quantum computer.
It's like the necessary wrapper, if you will,
to make it easy to run
that classical function on our quantum computer.
Basically, I'll give you both of those things.
We're going to try to figure out what
the secret string that's hidden in this function is.
Now, I get that this does not seem a terribly practical problem,
but I think it's a good toy problem to
demonstrate what we can do with quantum hardware.
If we were trying to solve this classically, into that function,
we basically have to probe each bit of the secret,
because if it's a dot product,
we just put a one in the position of
the secret that we want to
learn and we just scan it all the way through.
That would take us, if our secret is n bits long,
n queries or uses of that function.
For the quantum strategy that we're going to use here,
it's only going to take us one query.
Like n scaling to
a one scaling is a pretty good speedup if you ask me.
>> I think so. That's very impressive.
>> Certainly, in real applications you'll have
some other overhead and everything balances out.
This isn't exactly the speedup you would get,
but this is a good example of
a subroutine that you could use in your quantum algorithms.
I'm going to again open
some libraries here that are going to help us.
I'm going to add
the definition for our oracle that I mentioned earlier.
You can see here, the details here aren't super important,
but basically we have an operation here that's going to
do the dot product
because that's basically what our function f does.
It does a dot product.
We can define those.
Then we can actually run our Bernstein-Vazirani algorithm,
where we're going to leverage superposition to
basically query all of the possible bits of our secret at once.
Again, we're using Qubits,
so we've got an operation here.
Our inputs are, how many Qubits are there?
Do we want to use basically,
and what is the secret?
Here I'm passing an integer
as our secret and we'll convert it to a bit string.
Our result here should be
basically the same as the secret that we put in.
That's our expected result.
Here again, we're using statement to get some Qubits.
We're using some really neat patterns like the within
apply blocks from Q# that make it really easy.
Quantum algorithms often have this pattern of
like prepare your Qubits,
do some things, and then unprepared them.
Q# has this built-in block style within apply,
which means basically Q# does a lot of
the undoing and cleaning up after myself for me.
That's a really good example of
this domain-specific design of the language.
You can maybe think of it as analogous to
automated memory management as
opposed to having to do that manually.
>> Yeah we can evaluate that.
We've got that in our memory,
and let's just simulate it.
Ideally, you should return to us the number 19.
If we work this out in binary,
and this is 16,17,18,19, okay, cool.
My binary skills are okay.
Here you can see we were again using this
simulate call in the Jupyter Notebook,
and what that's doing is that's running on
the simulator or simulated quantum device on my laptop here.
You can simulate up to about 30 cubits
on reasonable laptop hardware.
But that isn't as
exciting as running on hardware
so let's actually run it on hardware.
There is basically this new service called Azure Quantum,
where the devices that Microsoft is developing and
other partners are developing will be available
as basically instances on Azure.
I can connect to a workspace on Azure right now from
the IonQ partner, and let's see.
Everything I've connected to the workspace,
and I'm going to set my target device as the IonQ,
QPU, or quantum processing unit.
>> Nice.
>> This is really exciting, and so there's a number of
different hardware partners that are on Azure Quantum already.
It's in preview right now.
You can sign up on the Azure Quantum or
Microsoft Quantum website to get into that preview.
>> That's awesome.
>> There we go.
>> Yeah. We'll zoom out. There we go.
You can see here I've submitted this job and it's running.
There are some q times here,
so we'll pop over and let me just take a look
at my jobs so I can just straight peer for my notebook.
You can see here all of the different jobs
I've sent out to different devices and device simulators,
so this is the one that we're waiting on right now.
I'm going to grab the results from
the one I ran a little bit earlier.
>> Perfect.
>> I actually also ran it on a [inaudible] hardware.
These are two different hardware partners,
and maybe it's not super exciting or surprising,
but we basically get back from
the hardware a histogram of what secret.
Basically, the algorithm isn't going to get
exactly the same answer every time because of noise in the device.
But we can see here with like 95 percent probability,
we got again 19 in binary,
and on our IonQ device, same thing.
>> Yeah.
>> I don't know. It may seem kind of silly to be like,
we put a 19 and we got 19 [inaudible] out.
But this was actually running on quantum devices
at almost absolute zero
somewhere on the other side of the country.
The possibilities that we have to actually develop
with this are really, really cool.
>> No, I love that. That's incredible,
and the fact that you can do all of that like from
a Jupyter Notebook makes
it feel more accessible too because as you're pointing out,
it's great that you have this,
if you could do it on your local hardware,
that maybe could do 30 cubits, right?
But if you're wanting to do bigger problems,
they could take up more than that,
being able to do that remotely and do
that on the Cloud and have more experimentation.
That's really awesome. I love that.
Where can people go to learn more from you about Q Sharp?
>> Definitely come checkout and hang out on stream with me,
twitch.tv/crazy the number 4pi314.
It's my original Internet username and I'm sticking to it.
You can come ask whatever questions
you want about quantum computing,
see what it looks like to actually
write software for a quantum computer.
I'd also encourage you to check out qsharp.community.
That's a community group that myself and some
other MVPs help maintain to show off
other projects that folks are doing with Q Sharp
and just interact with folks who are actually using it.
I'd also encourage you to check out WIQCA,
Women in Quantum Computing and Applications.
It's a really fun meetup group where basically we feature
talks and profiles of
women who are actually working in quantum computing.
I've written a book called learn
Quantum Computing with Python and Q Sharp.
It assumes no quantum background and
allows you with your classical developer skills,
build up what you need to know
about quantum computing by literally building a simulator
yourself in Python and then seeing how that
is manifesting in Q Sharp in the Quantum Development Kit,
and then using that to actually
do chemical simulations in Q Sharp.
>> That's awesome. So you're telling
me that I don't need to have a quantum background,
but if I am a developer,
I can read your book and go through that whole process?
>> Yeah.
>> That's awesome. In addition to the textbooks,
you've written some other books too,
from what I understand, right?
Some that are really geared towards,
a little bit different audience.
>> Yeah. We cater to all agents here.
I really enjoy showing what's exciting about tech to everyone.
I brought a couple of copies here.
We've got Robotics for Babies,
Neural Networks for babies,
which is always ahead,
and ABCs of Engineering.
I only have a fur baby.
I always bring them when folks have kids and it's really fun
to see a kid get really excited about learning about those things.
>> That's awesome, and what got you interested
in writing books geared at babies?
>> That's a good question. One of my academic colleagues,
Chris Ferrie, who's the co-author with me on those books.
He has four kids,
he had actually written some
of these baby books like for quantum computing,
which started out as a Reddit troll and then spun out of control,
and now he's an award-winning children's book author.
>> Wait, backup, so this started as like
a troll and then it became like a real thing.
>> Yes. Basically what happened was
someone on Reddit said you
can't explain quantum computing to a baby.
He said, watch me.
He posted basically an imager thread of the pages of the book.
People are like you need to self-publish this.
He self-published on Amazon.
Then at one point,
Mark Zuckerberg posted a picture
of him reading this book to his kid,
and then he had publishers out the Wazoo.
>> That's so good. I love it so much.
Well, Sarah, thank you so much was so great talking with you.
I love learning about your background.
I love that you've made me feel
like even I can understand some of the stuff now.
It's a lot more approachable.
Keep up the great work and I'll see you in Animal Crossing.
>> Thanks so much, Christina.
Has been really great to talk.
>> Love it. That does it for this series on CodeStories.
I want to thank Dr.
Sara Kaiser for taking the time to share her story with us.
It's amazing and for showing us so much cool code.
If you want to know more about her,
you can find her at her website, sckaiser.com.
You can also check out more resources on getting started
with Q Sharp at Microsoft.com/learn,
got some really good resources there.
I've also got links in the show notes in the description to
Sarah's Twitch stream and some of
the blog posts and books that she's written,
and while you are there,
just go ahead and subscribe to us on YouTube.
I'm a Microsoft developer and we're going to see you next time.
[MUSIC]