How to implement the Bernstein-Vazirani Quantum Algorithm With Qiskit

Learn how to implement one of the most important quantum algorithms

Do you want to get started with Quantum Machine Learning? Have a look at Hands-On Quantum Machine Learning With Python.

The Bernstein-Vazirani algorithm identifies a secret binary string in a single run. For example, a classical algorithm would need 𝑛 runs for a string of 𝑛 digits. Therefore, this algorithm is one of the first to show how quantum algorithms could effectively break cryptography.

The following circuit diagram depicts the Bernstein-Vazirani algorithm we implement today. It consists of five parts:

  1. a set of qubits in superposition in the |+⟩ state, where each qubit represents a digit.
  2. an auxiliary qubit in the state |−⟩.
  3. a quantum oracle representing the secret key
  4. bringing the qubits out of superposition
  5. measurement of the qubits
Image by author

You'll need Python and Qiskit to run the source code provided in this post. Look at this post if you haven't set up your working environment yet.

We start with the qubits representing the digits of the secret string.

--

--

Frank Zickert | Quantum Machine Learning

You're interested in quantum computing and machine learning. But you don't know how to get started? Let me help