qc2.algorithms.qiskit.oo_vqe ============================ .. py:module:: qc2.algorithms.qiskit.oo_vqe .. autoapi-nested-parse:: Module defining oo-VQE algorithm for Qiskit-Nature. Classes ------- .. autoapisummary:: qc2.algorithms.qiskit.oo_vqe.oo_VQE Module Contents --------------- .. py:class:: oo_VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, estimator=None, optimizer=None, reference_state=None, init_circuit_params=None, init_orbital_params=None, freeze_active=False, max_iterations=50, conv_tol=1e-07, verbose=0) Bases: :py:obj:`qc2.algorithms.qiskit.vqe.VQE` Main class for orbital-optimized VQE with Qiskit-Nature. This class extends the VQE class to include orbital optimization. It supports customized ansatzes, active space definitions, qubit mapping strategies, estimation methods, and optimization routines. Orbital optimization is performed alongside VQE parameter optimization using analytic first and second derivatives .. attribute:: freeze_active If True, freezes the active space during optimization. :type: bool .. attribute:: orbital_params List of orbital optimization parameters. Defaults to a list with entries of zero. :type: List .. attribute:: circuit_params List of VQE circuit parameters. Defaults to a list with entries of zero. :type: List .. attribute:: oo_problem An instance of :class:`~qc2.algorithms.utils.orbital_optimization.OrbitalOptimization` problem class. Defaults to None. :type: OrbitalOptimization .. attribute:: max_iterations Maximum number of iterations for the combined circuit-orbitals parameters optimization. Defaults to 50. :type: int .. attribute:: conv_tol Convergence tolerance for the optimization. Defaults to 1e-7 :type: float .. attribute:: verbose Verbosity level. Defaults to 0. :type: int .. py:attribute:: freeze_active :value: False .. py:attribute:: orbital_params :value: None .. py:attribute:: circuit_params .. py:attribute:: oo_problem :value: None .. py:attribute:: max_iterations :value: 50 .. py:attribute:: conv_tol :value: 1e-07 .. py:method:: run() -> qc2.algorithms.algorithms_results.OOVQEResults Optimizes both the circuit and orbital parameters. :returns: An instance of :class:`qc2.algorithms.qiskit.vqe.OOVQEResults` class with all oo-VQE info. :rtype: OOVQEResults **Example** >>> from ase.build import molecule >>> from qc2.ase import PySCF >>> from qc2.data import qc2Data >>> from qc2.algorithms.qiskit import oo_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 = oo_VQE( ... active_space=ActiveSpace( ... num_active_electrons=(2, 2), ... num_active_spatial_orbitals=4 ... ), ... mapper="jw", ... optimizer=SLSQP(), ... estimator=Estimator(), ... ) >>> results = qc2data.algorithm.run() .. py:method:: _circuit_optimization(theta: List, kappa: List) -> Tuple[List, float] Get total energy and best circuit parameters for a given kappa. :param theta: List with circuit variational parameters. :type theta: List :param kappa: List with orbital rotation parameters. :type kappa: List :returns: Optimized circuit parameters and associated energy. :rtype: Tuple[List, float] .. py:method:: _get_energy_from_parameters(theta: List, kappa: List) -> float Calculates total energy given circuit and orbital parameters. :param theta: List with circuit variational parameters. :type theta: List :param kappa: List with orbital rotation parameters. :type kappa: List :returns: Total ground-state energy for a given circuit and orbital parameters. :rtype: float .. py:method:: _get_rdms(theta: List, sum_spin=True) -> Tuple[numpy.ndarray, numpy.ndarray] Calculates 1- and 2-electron reduced density matrices (RDMs). :param theta: circuit parameters at which RDMs are calculated. :type theta: List :param sum_spin: If True, the spin-summed 1-RDM and 2-RDM will be returned. If False, the full 1-RDM and 2-RDM will be returned. Defaults to True. :type sum_spin: bool :returns: 1- and 2-RDMs. :rtype: Tuple[np.ndarray, np.ndarray]