qc2.algorithms.qiskit.vqe ========================= .. py:module:: qc2.algorithms.qiskit.vqe .. autoapi-nested-parse:: Module defining VQE algorithm for Qiskit-Nature. Classes ------- .. autoapisummary:: qc2.algorithms.qiskit.vqe.VQE Module Contents --------------- .. py:class:: VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, estimator=None, optimizer=None, reference_state=None, init_params=None, verbose=0) Bases: :py:obj:`qc2.algorithms.base.vqe_base.VQEBASE` Main class for the VQE algorithm with Qiskit-Nature. This class initializes and executes the VQE algorithm using specified quantum components like ansatz, optimizer, and estimator. .. attribute:: active_space Describes the active space for quantum simulation. Defaults to ``ActiveSpace((2, 2), 2)``. :type: ActiveSpace .. attribute:: mapper Strategy for fermionic-to-qubit mapping. Defaults to :class:`qiskit.JordanWignerMapper`. :type: QubitMapper .. attribute:: estimator Method for estimating the expectation value. Defaults to :class:`qiskit.Estimator` :type: BaseEstimator .. attribute:: optimizer Optimization routine for circuit variational parameters. Defaults to :class:`qiskit_algorithms.SLSQP`. :type: qiskit.Optmizer .. attribute:: reference_state Reference state for the VQE algorithm. Defaults to :class:`qiskit.HartreeFock`. :type: QuantumCircuit .. attribute:: ansatz The ansatz for the VQE algorithm. Defaults to :class:`qiskit.UCCSD`. :type: UCC .. attribute:: params List of initial VQE circuit parameters. Defaults to a list with entries of zero. :type: List .. attribute:: verbose Verbosity level. Defaults to 0. :type: int .. py:attribute:: active_space .. py:attribute:: mapper .. py:attribute:: estimator .. py:attribute:: optimizer .. py:attribute:: reference_state .. py:attribute:: ansatz .. py:attribute:: params .. py:attribute:: verbose :value: 0 .. py:method:: _get_default_reference(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper) -> qiskit.circuit.QuantumCircuit :staticmethod: Set up the default reference state circuit based on Hartree Fock. :param active_space: description of the active space. :type active_space: ActiveSpace :param mapper: mapper class instance. :type mapper: mapper :returns: Hartree-Fock circuit as the reference state. :rtype: QuantumCircuit .. py:method:: _get_default_ansatz(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper, reference_state: qiskit.circuit.QuantumCircuit) -> qiskit_nature.second_q.circuit.library.UCC :staticmethod: Set up the default UCC ansatz from a Hartree Fock reference state. :param active_space: Description of the active space. :type active_space: ActiveSpace :param mapper: Mapper class instance. :type mapper: QubitMapper :param reference_state: Reference state circuit. :type reference_state: QuantumCircuit :returns: UCC ansatz quantum circuit. :rtype: UCC .. py:method:: _get_default_init_params(nparams: List) -> List :staticmethod: Generates a list of initial circuit parameters for the ansatz. :param nparams: Number of parameters in the ansatz. :type nparams: int :returns: List of initial parameter values (all zeros). :rtype: List[float] .. py:method:: run(*args, **kwargs) -> qc2.algorithms.algorithms_results.VQEResults Executes the VQE algorithm. :param \*args: Variable length argument list to be passed to the :class:`qiskit_algorithm.VQE` class. :param \*\*kwargs: Arbitrary keyword arguments to be passed to the :class:`qiskit_algorithm.VQE` class. :returns: An instance of :class:`qc2.algorithms.qiskit.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.qiskit import VQE >>> 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 = VQE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... optimizer=SLSQP(), ... estimator=Estimator(), ... ) >>> results = qc2data.algorithm.run()