Well-Studied Task Execution Quality Metrics#
This tutorial covers benchmarks for algorithm-specific and task-specific metrics.
from qcmet import QFT
from qcmet.devices import IdealSimulator, NoisySimulator, AerSimulator
import matplotlib.pyplot as plt
The well-studied task execution quality metrics consist of:
Variational quantum eigensolver (VQE)
Specific implementation for the 1D Fermi-Hubbard model (VQE1DFermiHubbard)
Hamiltonian simulation
Specific implementation for the 1D Fermi-Hubbard model (Simulation1DFermiHubbard)
Quantum fourier transform (QFT)
QScore
Quantum Fourier Transform (QFT)#
The QFT benchmark measures how well a quantum computer can implement the Quantum Fourier Transform algorithm.
The QFT is a key subroutine in many quantum algorithms including:
Shor’s algorithm for factoring
Quantum phase estimation
Hidden subgroup problem solutions
# Setup QFT benchmark
qft = QFT(
qubits=4, # QFT on 4 qubits
)
# Generate circuits
qft.generate_circuits()
print(f"Generated {len(qft.circuits)} QFT circuits")
Generated 1 QFT circuits
# Look at QFT circuit
print("QFT circuit structure:")
print(qft.circuits[0])
QFT circuit structure:
┌───┐┌───┐ »
q_0: ┤ X ├┤ H ├─■────────■─────────────■──────────────────────────────»
├───┤└───┘ │P(π/2) │ ┌───┐ │ »
q_1: ┤ X ├──────■────────┼───────┤ H ├─┼────────■────────■────────────»
├───┤ │P(π/4) └───┘ │ │P(π/2) │ ┌───┐»
q_2: ┤ X ├───────────────■─────────────┼────────■────────┼───────┤ H ├»
└───┘ │P(π/8) │P(π/4) └───┘»
q_3: ──────────────────────────────────■─────────────────■────────────»
»
meas: 4/═════════════════════════════════════════════════════════════════»
»
« ┌───────┐ »
« q_0: ───────────────X──┤ Rz(π) ├─────X───────────────────────────────»
« │ ┌┴───────┴┐ │ »
« q_1: ───────────X───┼─┤ Rz(π/2) ├─X──┼──────────────────────■────────»
« │ │ ├─────────┤ │ │ ┌───┐ │ »
« q_2: ─■─────────X───┼─┤ Rz(π/4) ├─X──┼───────■────────┤ H ├─┼────────»
« │P(π/2) ┌───┐ │ ├─────────┤ │ ┌───┐ │P(-π/2) └───┘ │P(-π/4) »
« q_3: ─■───────┤ H ├─X─┤ Rz(π/8) ├────X─┤ H ├─■──────────────■────────»
« └───┘ └─────────┘ └───┘ »
«meas: 4/════════════════════════════════════════════════════════════════»
« »
« ┌───┐ ░ ┌─┐
« q_0: ───────────■──────────────■─────────■────────┤ H ├─░─┤M├─────────
« │ ┌───┐ │ │P(-π/2) └───┘ ░ └╥┘┌─┐
« q_1: ─■─────────┼────────┤ H ├─┼─────────■──────────────░──╫─┤M├──────
« │P(-π/2) │ └───┘ │P(-π/4) ░ ║ └╥┘┌─┐
« q_2: ─■─────────┼──────────────■────────────────────────░──╫──╫─┤M├───
« │P(-π/8) ░ ║ ║ └╥┘┌─┐
« q_3: ───────────■───────────────────────────────────────░──╫──╫──╫─┤M├
« ░ ║ ║ ║ └╥┘
«meas: 4/══════════════════════════════════════════════════════╩══╩══╩══╩═
« 0 1 2 3
# Run on device
device = AerSimulator()
qft.run(device, num_shots=2048)
# Analyze
results_qft = qft.analyze()
print("\nQFT Results:")
for key, value in results_qft.items():
print(f" {key}: {value}")
QFT Results:
fidelity: [1.0]
normalized_fidelity: [1.0]
Comparing QFT Performance Across Simulators#
# Test QFT on different devices
devices = {
'Ideal': IdealSimulator(),
'Noisy': NoisySimulator(),
}
qft_comparison = {}
for device_name, device in devices.items():
print(f"\nTesting QFT on {device_name} simulator...")
qft_test = QFT(qubits=4)
qft_test.generate_circuits()
qft_test.run(device, num_shots=2048)
result = qft_test.analyze()
qft_comparison[device_name] = result
print(f" Fidelity: {result.get('fidelity', 'N/A')}")
Testing QFT on Ideal simulator...
Fidelity: [1.0]
Testing QFT on Noisy simulator...
Fidelity: [0.9926757812499999]
What the Numbers Mean#
Fidelity: Measure of how close the output state from your real QFT circuit is to the ideal QFT output
The higher the fidelity, the better the performance of QFT by the device.
Normalised Fidelity: Measure of how close the output state from your real QFT circuit is to the ideal QFT output normalized against a fully depolarized output distribution.
The higher the normalised fidelity, the better the performance of QFT by the device.
F will be between 0 and 1.
F = 1 indicates that the output states are identical to the ideal states.
F = 0 indicates that the output states are orthogonal to the ideal states.
Other Benchmarks#
QCMet furthermore implements the QScore, VQE (1D Fermi-Hubbard), and Hamiltonian simulation (1D Fermi-Hubbard) as well studied task benchmarks. See the respective implementations for further details.