qc2.algorithms.pennylane.pebase =============================== .. py:module:: qc2.algorithms.pennylane.pebase .. autoapi-nested-parse:: Module defining QPE algorithm for PennyLane. Classes ------- .. autoapisummary:: qc2.algorithms.pennylane.pebase.PEBase Module Contents --------------- .. py:class:: PEBase(qc2data=None, active_space=None, mapper=None, device=None, reference_state=None, verbose=0) Bases: :py:obj:`qc2.algorithms.base.base_algorithm.BaseAlgorithm` .. py:attribute:: qc2data :value: None .. py:attribute:: format :value: 'pennylane' .. py:attribute:: verbose :value: 0 .. py:attribute:: circuit :value: None .. py:attribute:: num_evaluation_qubits :value: None .. py:attribute:: active_space .. py:attribute:: device :value: 'default.qubit' .. py:attribute:: mapper .. py:attribute:: qubits .. py:attribute:: electrons .. py:attribute:: reference_state .. py:method:: _get_default_reference(qubits: int, electrons: int) -> pennylane.numpy.ndarray :staticmethod: Generate the default reference state for the ansatz. :param qubits: Number of qubits in the circuit. :type qubits: int :param electrons: Number of electrons in the system. :type electrons: int :returns: Reference state vector. :rtype: np.ndarray .. py:method:: _init_qubit_hamiltonian() Initializes the qubit Hamiltonian for the quantum phase estimation algorithm. This method retrieves the qubit Hamiltonian representation of the target molecule from the `qc2data` object. It requires prior initialization of `qc2data` with the molecular data. :raises ValueError: If `qc2data` is not set correctly. .. attribute:: e_core The core energy of the system. :type: float .. attribute:: qubit_op The qubit operator representing the Hamiltonian. :type: Operator .. py:method:: _phase_to_energy(phase: float) -> float :staticmethod: Convert a phase from 0 to 1 to an energy from -pi to pi. :param phase: The phase to convert. :type phase: float :returns: The energy corresponding to the given phase. :rtype: float .. py:method:: _build_circuit(dev: str, qubits: int, num_estimation_wires: int, reference_state: pennylane.numpy.ndarray, unitary_op: pennylane.operation.Operator, device_args=None, device_kwargs=None, qnode_args=None, qnode_kwargs=None) -> pennylane.QNode :staticmethod: :abstractmethod: Constructs and returns a PennyLane QNode for quantum phase estimation. This method sets up a quantum circuit on a specified quantum device using the provided parameters. It initializes the qubits, applies necessary quantum operations including the unitary operator, and prepares the reference state. :param dev: Identifier for the PennyLane quantum device to be used. :type dev: str :param qubits: Total number of qubits in the circuit. :type qubits: int :param num_estimation_wires: Number of qubits designated for phase estimation. :type num_estimation_wires: int :param reference_state: Initial state of the qubits, typically representing the Hartree-Fock state. :type reference_state: np.ndarray :param unitary_op: Operator that defines the unitary evolution in the circuit. :type unitary_op: Operator :param device_args: Additional positional arguments for the quantum device. Defaults to None. :type device_args: list, optional :param device_kwargs: Additional keyword arguments for the quantum device. Defaults to None. :type device_kwargs: dict, optional :param qnode_args: Additional positional arguments for the QNode. Defaults to None. :type qnode_args: list, optional :param qnode_kwargs: Additional keyword arguments for the QNode. Defaults to None. :type qnode_kwargs: dict, optional :returns: The constructed QNode with the specified ansatz for phase estimation. :rtype: QNode .. py:method:: get_phase() :abstractmethod: Retrieves the estimated phase after the QPE algorithm has been run. :returns: The estimated phase. :rtype: float .. py:method:: run(*args, **kwargs) -> qc2.algorithms.algorithms_results.QPEResults Executes QPE algorithm. :param \*args: - device_args (optional): ``qml.device`` arguments. - qnode_args (optional): ``qml.qnode`` arguments. :param \*\*kwargs: - device_kwargs (optional): ``qml.device`` keyword arguments. - qnode_kwargs (optional): ``qml.qnode`` keyword arguments. :returns: An instance of :class:`qc2.algorithms.pennylane.vqe.VQEResults` class with all VQE info. :rtype: VQEResults **Example** >>> from ase.build import molecule >>> from qc2.ase import PySCF >>> from qc2.data import qc2Data >>> from qc2.algorithms.pennylane import QPE >>> from qc2.algorithms.utils import ActiveSpace >>> >>> mol = molecule('H2O') >>> >>> hdf5_file = 'h2o.hdf5' >>> qc2data = qc2Data(hdf5_file, mol, schema='qcschema') >>> qc2data.molecule.calc = PySCF() >>> qc2data.run() >>> qc2data.algorithm = QPE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... num_evaluation_qubits=3, ... device="default.qubit" ... ) >>> results = qc2data.algorithm.run()