►
From YouTube: Demonstration cuQuantum Notebook
Description
Demonstration cuQuantum Notebook
Jin Sung Kim (NVIDIA)
A
System
so,
okay,
the
the
demonstration
I
wanted
to
do
today
was
a
vqe
using
crew
State
effect,
so
I've
adopted
these
materials
from
the
Google
Docs,
as
well
as
some
of
our
cool
Quantum
documents.
A
So
the
example
that
we
want
to
run
here
is
a
randomizing
hamiltonian
on
a
square
grid.
So
this
is
a
notorious
NP,
complete
problem
where
what
we're
going
to
have,
as
our
interactions
are
random,
ZZ
interactions
between
qubits
on
a
square
grid
and
a
random
transverse
field,
all
these
J
and
H
values
will
be
set
to
plus
or
minus
one
just
to
simplify
things
within
our
calculation.
A
So
first
thing
I'm
going
to
do
is
import
insert
Q,
Sim,
Circ
time
copying,
random.
A
All
right:
well,
let's
just
continue
so
the
first
thing
that
I
have
prepared
and
I
think
what
we'll
do
is
I'll
just
make
this
notebook
available
to
everyone
and
once
you're
able
to
spin
up
a
GPU
on
your
own
on
Pro
motor.
You
can
go
through
the
tutorial
yourself
and
do
this
for
yourself.
So
I
have
several
helper
functions
here,
the
predefined.
This
is
just
going
to
Generate,
random
terms
on
a
square
grid
and
then
a
random
instance
for
my
H
and
J
terms.
A
A
Our
onsides
is
just
to
encode
the
terms
of
the
hamiltonian
in
this
kind
of
simple
trotterized
Manner
and
then
we're
going
to
add
a
mixing
term
that
will
consist
of
just
simple
x,
rotations
on
every
qubit,
so
here
I'm
preparing
the
the
plus
layer-
and
this
is
what
the
circuit
will
look
like
for
a
square
grid
of
a
two
by
two
square
grid
and
each
panamards
on
every
qubit
I'm
going
to
Define
this
rotate
X
layer.
A
This
is
my
mixing
term
for
this
qaoa
type
onsets,
and
this
is
what
this
is
going
to
look
like.
So
a
partial
rotation,
partial
X
rotation
on
every
qubit,
we're
gonna
have
a
z
layer.
This
is
the
first.
This
is
the
transfers
field
on
our
hamiltonian
So.
Eventually
we're
going
to
parameterize
this.
A
A
So
these
three
ingredients
are
going
to
parameterize
our
onsets,
and
the
idea
here
is
we're
going
to
parameterize
our
circuit
and
then
attempt
to
find
the
energy,
the
the
parameterization
that
gives
us
the
lowest
energy
foreign,
so
we'll
put
it
all
together
to
generate
the
onsets
so
for
this
example,
I
will
have
run
a
5x5
qubit
grid.
So
this
is
going
to
be
a
25
qubit
simulation.
A
A
So,
okay,
it
looks
like
my
kernel
is
actually
dying.
Okay,
that's
fine!
So
for
this
onsat's
we're
gonna
put
all
of
these
layers
together,
so
I'll
prepare
the
plus
layer
and
then
do
my
Z
rotation
I'll.
Do
my
entangling
layer
and
then
I'll
do
my
mixing
term.
It's
a
random
x
or
parameterize
X
rotation
on
every
qubit
foreign.
A
So
here
I'm
going
to
Define
my
two
simulators.
So,
in
the
first
instance,
I
have
my
Circ,
my
default
Circ
simulator
as
a
back
end
and
then
I'm
going
to
have
my
coupon
to
enable
GPU
simulator.
So
I'll
set
my
number
of
gpus
equal
to
one
and
so
for
this,
so
first
I'll
run
the
default
simulator
with
100
shots
and
I've.
A
You
can
see
I've
pre-run
this
previously
and
the
CPU
runtime
gives
me
about
six
seconds
now,
if
I
swap
out
the
back
end
for
the
coupe
Quantum
back
end,
my
GP
runtime
is
a
fraction
of
a
second
now
at
this
point.
So
in
this
instance
is
0.9
seconds,
but
earlier
in
the
day
it
was
around
0.03
seconds.
A
So,
okay,
so
you
can
already
see
that
there's
like
a
significant
Improvement
in
the
computation
time
from
several
seconds
to
a
fraction
of
a
second,
but
rarely
where
this
capability
starts
to
shine.
Is
you
have
to
remember
that
this
is
only
one
instance
of
the
vqe
iteration?
So
really
we
want
to
iterate
over
the
circuit.
Do
this
many
times
and
optimize
our
parameters
in
order
to
find
what
the
lowest
energy
State
onsides
will
be
so
I'm
going
to
define
a
couple
of
other
helper
functions
here.
A
These
will
just
help
me
calculate
the
energy
expectation
for
this
type
of
hamiltonian.
It's
pretty
trivially
easy,
given
a
bit
string
to
calculate
the
energy
expectation
just
because
we
have
a
diagonal,
hamiltonian
and
then
I'll
have
this
other
other
function
here.
That
helps
me
calculate
the
expectation
value
so
putting
it
all
together.
For
this
single
instance,
single
Circuit
of
my
vqe,
then
I
can
calculate
the
expectation
value
of
my
hamiltonian
for
one
instance
of
this
iteration
foreign.
A
So
now,
let's
parameterize
the
onsets
and
we'll
actually
iterate
over
various
parameters
in
order
to
minimize
the
energy.
So,
in
order
to
do
this,
we'll
import
some
pi
and
then
we'll
symbolically
parameterize
each
of
our
parameterizations
of
our
circuit
so
recall
that
we
had
three
layers
that
could
be
parameterized
are
X
rotation,
layer,
our
Z
rotation
layer,
as
well
as
our
entangling
layer,
so
we'll
encode
all
of
these
as
alpha
beta
and
gamma
parameters,
so
I'm
rebuilding
my
circuit.
A
Now,
with
these
parameters
symbolically
and
then
I'm
going
to
sweep
over
each
of
these
parameters
with
a
sweep
size
of
10..
So
now,
I
have
in
this
sweep.
I
have
a
thousand
circuits
that
I
have
to
iterate
over.
So
now
you
can
start
to
see
where
having
a
hundred
X
Improvement
in
your
simulation.
Time
really
starts
to
shine
so
here
for
this
optimization
we're
just
going
to
do
a
Brute
Force,
optimization
we're
just
going
to
brute
force
over
every
possible
combination
of
our
three
parameters.
A
So,
just
by
doing
a
back
of
the
envelope
calculation
using
the
CPU
simulator
before
it
took
six
seconds
to
do
a
single
iteration
of
this
entire
vqe
circuit.
So
six
times,
one
thousand
circuits
that
you'll
have
to
run
to
explore
the
entire
parameter
space
that
takes
you
to
about
an
hour
and
a
half
of
compute
time,
but
using
crew
Quantum.
As
your
back
end,
you're
running
about
100
times
faster.
A
This
actually
will
run
in
about
30
seconds
on
a
single
GPU,
so
really
really
significant
performance
gains
that
take
your
simulation
time
from
something
that
you
would
have
to
wait
an
hour
and
a
half
for
it
to
something
where
you
could
literally
send
from
of
your
terminal
and
wait
for
your
results
to
come
back.
So
really
really
helps
streamline
your
workflow
and
accelerate
the
types
of
computations
that
you
want
to
do
for
a
large
number
of
qubits
a
reminder.
This
is
a
25
qubit
simulation.
A
Okay,
so
those
are
all
benchmarks
for
crew
statefic.
Let's
switch
over
to
kutenser
Nam,
so
I
want
to
just
highlight
some
of
the
functionality
that
we've
built
into
these
two
sdks,
so
we
actually
have
a
function
that
takes
a
Circ
circuit
or
a
kisket
circuit
and
converts
it
into
an
an
EIN,
some
expression.
So
nine
sum
expression
is
just
it
tells
you
the
order
and
indices
of
a
tensor
Network
and
the
order
in
order
to
contract
them.
A
So
this
is
kind
of
the
form
that
crew
tensor
net
ingests
and
does
the
contraction
of
a
tensor
Network.
So
we're
going
to
take
the
same.
We're
going
to
take
the
same
circuit,
we're
going
to
define
a
five
by
five
grid.
Take
the
exact
same
circuit
that
we
were
looking
at
before
and
then
we're
going
to
convert
it
into
a
nine
sum.
A
So
this
really
just
takes
one
line
to
do
circuit
to
insum,
takes
here
circuit
and
then
Define
spits
out
in
in
I
in
some
expression.
A
A
Qubits,
so
all
we're
going
to
do
is
a
sand
view
Trek
now
and
make
sure
the
coup
tensor
net
gives
us
the
same
state
Vector
the
the
default
State
Vector
simulator
will
give
back
so
I've
pre-run
this
and
indeed
could
tensor
net
runs
about
a
second
and
the
Q7
back-end
runs
in
about
eight
seconds
and
it
gives
us
the
same
state
vector
so
good
sanity
track
here,
but
where
tensor
Network
methods
really
Excel
is
when
you
want
to
look
at
large
systems
of
qubits.
A
So
this
is
kind
of
a
simple
toy
example
of
a
5x5
grid.
Let's
now
look
at
a
bigger
system,
so
a
36
qubit
grid.
So
this
takes
a
massive
amount
of
memory
to
do
the
state,
Vector
calculation,
but
it
turns
out
we
can
still
get
interesting
information
out
of
this
simulation
by
using
tensor
Network
methods.
So
we
can't
get
back
the
full
State
Vector,
because
even
just
representing
the
state
Vector
for
36
cubits
would
take
about
a
terabyte
of
ram.
A
A
I'm
going
to
prepare
the
same
circuit.
I'm
gonna
convert
my
circuit
to
an
iron
sum
and
then
I'm
gonna
pick
a
bit
string
to
sample
so
I'll
I'll
pick
the
all
zeros
bit
string
and
then
I'll
do
the
contraction
and
then
well
crew
tensor
net
will
do,
is
do
the
contraction
and
then
give
me
back
a
probability
amplitude
so
I'm
getting
what's
shown
here
is
the
Einstein
expression.
This
is
literally
just
the
list
of
indices
that
Q
tensor
Knight
Will
contract
over,
and
it
tells
me
for
theology
bit
string.
A
I
get
this
probability
amplitude
and
probability.
So
that's
great
We've
now
done
a
computation
of
36.
Qubits
I've
also
done
49
cubits
the
same
thing
and
you
can
get
back
some
interesting
information
about
your
system.
A
I'll,
do
one
final,
a
demonstration
of
the
capabilities
of
good
tensor
net,
where
we're
going
to
compute
the
reduced
density
Matrix.
So
what
we
can
do
here
is
pick
what
qubits
we
want
to
trace
over
and
get
the
reduced
density.
Matrix
of
we
can
actually
do
a
conditional
density
Matrix
as
well,
where
we
can
look
at
if
you
want
to
pick
and
choose
certain
qubits
to
be
assigned
zero
or
one
you
can
trace
over
that
as
well.
Could
tensor
net
will
do
the
contraction
and
then
so?
A
In
this
instance,
I
will
do
a
reduced
density
Matrix
of
the
first
four
qubits,
where
I
fix
the
first
two
qubits
to
the
one
value
so
we're
doing
a
conditional,
reduced
density,
Matrix
and
so
yeah
could
touch
your
net
we'll
just
spit
out
the
reduced
sensing
Matrix
as
this
gigantic
array,
so
yeah.
What
I'll
do
is
yeah,
maybe
Neil
you
can.
Let
me
know:
where
is
a
good
place
to
put
this
tutorial
and
then
you
all
can
play
around
and
look
at
a
coupon
to
them
yourselves.
A
So
that's
basically
all
I
wanted
to
show,
and
it's
a
little
bit
of
a
shamed.
I
can't
run
this
on
a
GPU
live
but
I
think,
hopefully
with
just
a
walkthrough
of
this
notebook.
Everyone
here
got
kind
of
the
gist
of
the
capabilities
of
who
Quantum
and
how
to
actually
use
it
in
practice.