Bernstein-Vazirani Algorithm in Qiskit

mdzubair9492

Md. Zubair

Posted on March 25, 2024

Bernstein-Vazirani Algorithm in Qiskit

To understand it first there is a prerequisities to understand,

Phase Kickback:
Suppose we have a system of two qubits , two qubits are in differetn state, now we want to get the phase of one qubit to another, there comes phase kickback.

Let a system of two qubits q1q0 . Here Taking q0 as |-> state and q1 as |+> state. Now we want q1 also as |-> . here we can apply a cx gate where control is q1 and target is q0,

Image description

So now we can jump into the main algorithm.

Problem Statement: Suppose we have a blackbox which contain a secret number and our goal is to get the secret number by giving query to the blackbox.

  1. Classical Approach: In classical approach for a n bit secret number we have to give n query . This works as follows,

Image description

Image description

  1. Quantum Approach": In this approach we only need 1 query to get the secret key.

Image description

Image description

Here |x> is our query and |y> is auxiliary as this is reversible. For |y> we will use |1> state for using the phase kickback technique.

Now what oracle does here ? The oracle is basically put cx gate where the secret key has 1. Now let's think about why we need to put cx gate here. First off all all qubits in |x> is in superposition of |+> state and the auxiliary is in |-> state. If we know if we again apply H gate on |-> state and then if we measure if we will get |1> which is our requirement.

Now let's see the implementation part of this algorithm ,

Image description

If we want to see how our circuit looks like,

Image description

Now let's see whether it has sucessfully generated the secret key or not .

Image description

đź’– đź’Ş đź™… đźš©
mdzubair9492
Md. Zubair

Posted on March 25, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related