Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.application.algorithm.bernstein-vazirani

Bernstein-Vazirani Algorithm

The Bernstein-Vazirani algorithm is a quantum algorithm that efficiently determines a hidden bit string s using only one query to a quantum oracle. It is a foundational example of quantum speedup over classical algorithms, demonstrating how quantum circuits can solve specific problems more efficiently than their classical counterparts.

This implementation builds the quantum circuit for the Bernstein-Vazirani algorithm and executes it on a specified quantum backend.

The algorithm uses a quantum oracle Uf that computes f(x) = s·x (mod 2), where s is the hidden string and x is the input bit string.

The algorithm requires only one query to the oracle to determine the hidden string s, while classical algorithms would require n queries for an n-bit string.

Bernstein-Vazirani Algorithm

The Bernstein-Vazirani algorithm is a quantum algorithm that efficiently
determines a hidden bit string s using only one query to a quantum oracle.
It is a foundational example of quantum speedup over classical algorithms,
demonstrating how quantum circuits can solve specific problems more
efficiently than their classical counterparts.

This implementation builds the quantum circuit for the Bernstein-Vazirani
algorithm and executes it on a specified quantum backend.

The algorithm uses a quantum oracle Uf that computes f(x) = s·x (mod 2),
where s is the hidden string and x is the input bit string.

The algorithm requires only one query to the oracle to determine the hidden
string s, while classical algorithms would require n queries for an n-bit
string.
raw docstring

add-oracle-fnclj

(add-oracle-fn hidden-string n-qubits)

Build the quantum circuit for Bernstein-Vazirani oracle Uf.

Parameters:

  • hidden-string: Vector of bits representing the hidden string s
  • n-qubits: Number of input qubits

Returns: A function that takes a quantum circuit and applies the Bernstein-Vazirani oracle Uf to it.

Build the quantum circuit for Bernstein-Vazirani oracle Uf.

Parameters:
- hidden-string: Vector of bits representing the hidden string s
- n-qubits: Number of input qubits

Returns:
A function that takes a quantum circuit and applies the Bernstein-Vazirani oracle Uf to it.
sourceraw docstring

bernstein-vazirani-algorithmclj

(bernstein-vazirani-algorithm backend hidden-string)
(bernstein-vazirani-algorithm backend hidden-string options)

Implement the Bernstein-Vazirani algorithm to find a hidden bit string.

The algorithm determines a hidden n-bit string s efficiently, given access to a quantum oracle that computes f(x) = s·x (mod 2) where s·x is the dot product. Classical algorithms require n queries, while BV requires only 1 quantum query.

Algorithm steps:

  1. Initialize |0⟩^⊗n|1⟩ (n input qubits + 1 ancilla)
  2. Apply Hadamard to all qubits: |+⟩^⊗n|-⟩
  3. Apply oracle function f(x) = s·x (mod 2)
  4. Apply Hadamard to input qubits
  5. Measure input qubits to get s directly

Parameters:

  • backend: Quantum backend implementing the QuantumBackend protocol to execute the circuit
  • hidden-string: Vector of bits [0 1 0 1 ...] representing the hidden string s
  • options: Optional map with execution options (default: {:shots 1024})

Returns: Map containing:

  • :result - Measured bit string (should match hidden-string)
  • :hidden-string - The original hidden string
  • :success - Boolean indicating if measurement matched hidden string
  • :final-state - Final quantum state before measurement
  • :circuit - Description of the quantum circuit used
  • :execution-result - Backend execution results

Example: (bernstein-vazirani-algorithm [1 0 1 0] backend) ;=> Should measure [1 0 1 0]

Implement the Bernstein-Vazirani algorithm to find a hidden bit string.

The algorithm determines a hidden n-bit string s efficiently, given access to
a quantum oracle that computes f(x) = s·x (mod 2) where s·x is the dot product.
Classical algorithms require n queries, while BV requires only 1 quantum query.

Algorithm steps:
1. Initialize |0⟩^⊗n|1⟩ (n input qubits + 1 ancilla)
2. Apply Hadamard to all qubits: |+⟩^⊗n|-⟩ 
3. Apply oracle function f(x) = s·x (mod 2)
4. Apply Hadamard to input qubits
5. Measure input qubits to get s directly

Parameters:
- backend: Quantum backend implementing the QuantumBackend protocol to execute the circuit
- hidden-string: Vector of bits [0 1 0 1 ...] representing the hidden string s
- options: Optional map with execution options (default: {:shots 1024})

Returns:
Map containing:
- :result - Measured bit string (should match hidden-string)
- :hidden-string - The original hidden string
- :success - Boolean indicating if measurement matched hidden string
- :final-state - Final quantum state before measurement
- :circuit - Description of the quantum circuit used
- :execution-result - Backend execution results

Example:
(bernstein-vazirani-algorithm [1 0 1 0] backend)  ;=> Should measure [1 0 1 0]
sourceraw docstring

bernstein-vazirani-circuitclj

(bernstein-vazirani-circuit hidden-string)

Build the quantum circuit for Bernstein-Vazirani algorithm.

Parameters:

  • hidden-string: Vector of bits representing the hidden string s
  • n-qubits: Number of input qubits

Returns: A quantum circuit implementing the Bernstein-Vazirani algorithm using the provided hidden string.

Build the quantum circuit for Bernstein-Vazirani algorithm.

Parameters:
- hidden-string: Vector of bits representing the hidden string s
- n-qubits: Number of input qubits

Returns:
A quantum circuit implementing the Bernstein-Vazirani algorithm using the provided hidden string.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close