Source code for qdk_chemistry.algorithms.phase_estimation.base

"""QDK/Chemistry phase estimation abstractions and utilities."""

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from abc import abstractmethod

from qdk_chemistry.algorithms.base import Algorithm, AlgorithmFactory
from qdk_chemistry.data import (
    AlgorithmRef,
    Circuit,
    QpeResult,
    QuantumErrorProfile,
    QubitOperator,
    Settings,
)

__all__: list[str] = ["PhaseEstimation", "PhaseEstimationFactory", "PhaseEstimationSettings"]


[docs] class PhaseEstimationSettings(Settings): """Settings for the Phase Estimation algorithm."""
[docs] def __init__(self): """Initialize the settings for Phase Estimation. Includes nested algorithm references for the circuit builder and circuit executor. """ super().__init__() self._set_default( "qpe_circuit_builder", "algorithm_ref", AlgorithmRef("qpe_circuit_builder", "qdk_iterative"), ) self._set_default( "circuit_executor", "algorithm_ref", AlgorithmRef("circuit_executor", "qdk_sparse_state_simulator"), )
[docs] class PhaseEstimation(Algorithm): """Abstract base class for phase estimation algorithms."""
[docs] def __init__(self): """Initialize the PhaseEstimation with default settings.""" super().__init__() self._settings = PhaseEstimationSettings()
[docs] def type_name(self) -> str: """Return the algorithm type name as phase_estimation.""" return "phase_estimation"
@abstractmethod def _run_impl( self, state_preparation: Circuit, qubit_hamiltonian: QubitOperator, *, noise: QuantumErrorProfile | None = None, ) -> QpeResult: r"""Run the phase estimation algorithm with the given state preparation circuit and Hamiltonian. This method implements the quantum phase estimation procedure: 1. The state preparation circuit initializes the system in the desired quantum state. 2. The unitary_builder constructs a unitary from the qubit Hamiltonian. 3. The circuit_mapper transforms the unitary into controlled-U operations, where the control qubits are ancilla qubits used for phase readout. 4. The circuit_executor runs the resulting quantum circuits on the target backend. 5. Measurement results are processed to extract the eigenvalue phase estimates. Args: state_preparation: The circuit that prepares the initial state. qubit_hamiltonian: The qubit Hamiltonian for which to estimate eigenvalues. noise: The quantum error profile to simulate noise, defaults to None. Returns: A QpeResult object containing the estimated phases and associated metadata. """
[docs] class PhaseEstimationFactory(AlgorithmFactory): """Factory class for creating PhaseEstimation instances."""
[docs] def __init__(self): """Initialize the PhaseEstimationFactory.""" super().__init__()
[docs] def algorithm_type_name(self) -> str: """Return the algorithm type name as phase_estimation.""" return "phase_estimation"
[docs] def default_algorithm_name(self) -> str: """Return the qdk_iterative as default algorithm name.""" return "qdk_iterative"