Quantum Algorithms

Functions to set up common quantum algorithms in Qiskit for a given number of qubits.

All functions take the number of qubits as argument and return the corresponding Qiskit circuit. One can then use the Qiskit backend to transpile the circuit for a specific quantum device.

from quantum_gates.quantum_algorithms import (
    hadamard_reverse_qft_circ,
    ghz_circ,
    qft_circ
    qaoa_circ
)

nqubit = 2
circuit = hadamard_reverse_qft_circ(nqubit=2)
circ.draw('mpl')
quantum_gates.quantum_algorithms.hadamard_reverse_qft_circ(n_qubits: int)[source]

Generates the Qiskit circuit applying Hadamard gates on all qubits and the inverse Quantum Fourier transform.

A useful property of the circuit is that it maps the all 0 state to the equal superposition of all states, and back to the 0 state. As we know the ideal result, we can calculate fidelity metrics easily.

Parameters:

n_qubits (int) – Number of qubits.

Returns:

The Qiskit circuit before transpilation for a specific machine.

quantum_gates.quantum_algorithms.ghz_circ(n_qubits: int)[source]

Generates the GHZ circuit for n qubits.

The circuit first applies a Hadamard on the first qubit, and then iteratively applies CNOT gates with qubit i as control and i+1 as target, i = 0, …, n_qubits - 2.

Overall, the circuit generates the Greenberger–Horne–Zeilinger (GHZ) state from the zero state. The GHZ state is maximally entangled.

Parameters:

n_qubits (int) – Number of qubits.

Returns:

The Qiskit circuit before transpilation for a specific machine.

quantum_gates.quantum_algorithms.qft_circ(n_qubits: int)[source]

Generates the Quantum Fourier Transform circuit.

Parameters:

n_qubits (int) – Number of qubits.

Returns:

The Qiskit circuit before transpilation for a specific machine.

quantum_gates.quantum_algorithms.qaoa_circ(G, theta: float)[source]

Generates a Quantum Approximate Optimization Algorithm circuit.

Parameters:
  • G – NetworkX graph.

  • theta (float) – Angle to be optimized.

Returns:

The Qiskit circuit before transpilation for a specific machine.