def deprecate(self):
     """show deprecate message"""
     warn_deprecated("0.2.0",
                     DeprecatedType.ENUM,
                     self.__class__.__name__,
                     new_name="NewEnum",
                     stack_level=3)
Exemple #2
0
 def __init__(self):
     super().__init__(self.__class__.__name__)
     warn_deprecated(
         "0.4.0",
         DeprecatedType.CLASS,
         "PseudoProperty",
         DeprecatedType.CLASS,
         "Interpretable",
         additional_msg=
         ("The PseudoProperty class is deprecated. Instead, of requiring an `interpret()` "
          "method on the Property base-class, this is now handled via the `Interpretable` "
          "protocol."),
     )
    def sample(self, problem: BaseProblem,
               points: List[float]) -> BOPESSamplerResult:
        """Run the sampler at the given points, potentially with repetitions.

        Args:
            problem: BaseProblem whose driver should be based on a Molecule object that has
                     perturbations to be varied.
            points: The points along the degrees of freedom to evaluate.

        Returns:
            BOPES Sampler Result

        Raises:
            QiskitNatureError: if the driver does not have a molecule specified.
        """
        self._problem = problem
        self._driver = problem.driver

        if isinstance(self._driver, DeprecatedBaseDriver):
            warn_deprecated(
                "0.2.0",
                DeprecatedType.CLASS,
                f"{self._driver.__class__.__module__}.{self._driver.__class__.__qualname__}",
                new_name=
                "ElectronicStructureMoleculeDriver or VibrationalStructureMoleculeDriver",
                additional_msg="from qiskit_nature.drivers.second_quantization",
            )
        elif not isinstance(self._driver,
                            (ElectronicStructureMoleculeDriver,
                             VibrationalStructureMoleculeDriver)):
            raise QiskitNatureError(
                "Driver must be ElectronicStructureMoleculeDriver or VibrationalStructureMoleculeDriver."
            )

        if self._driver.molecule is None:
            raise QiskitNatureError(
                "Driver MUST be configured with a Molecule.")

        # full dictionary of points
        self._raw_results = self._run_points(points)
        # create results dictionary with (point, energy)
        self._points = list(self._raw_results.keys())
        self._energies = []
        for res in self._raw_results.values():
            energy = res.total_energies[0]
            self._energies.append(energy)

        result = BOPESSamplerResult(self._points, self._energies,
                                    self._raw_results)

        return result
Exemple #4
0
 def __init__(self, name: str) -> None:
     """
     Args:
         name: the name of the property.
     """
     self._name = name
     warn_deprecated(
         "0.5.0",
         old_type=DeprecatedType.CLASS,
         old_name="qiskit_nature.properties.Property",
         new_type=DeprecatedType.CLASS,
         new_name="qiskit_nature.second_q.properties.Property",
         category=NatureDeprecationWarning,
     )
Exemple #5
0
 def __init__(self, values: Optional[ListOrDictType] = None):
     """
     Args:
         values: an optional object of `list` or `dict` type.
     """
     warn_deprecated(
         "0.5.0",
         old_type=DeprecatedType.CLASS,
         old_name="qiskit_nature.ListOrDict",
         additional_msg=
         (". Qiskit Nature will now always produce dictionary-style auxiliary operators."
          ),
         category=NatureDeprecationWarning,
     )
     if isinstance(values, list):
         values = dict(enumerate(values))
     elif values is None:
         values = {}
     super().__init__(values)
    def _run_single_point(self, point: float) -> EigenstateResult:
        """Run the sampler at the given single point

        Args:
            point: The value of the degree of freedom to evaluate.

        Returns:
            Results for a single point.
        Raises:
            QiskitNatureError: Invalid Driver
        """

        # update molecule geometry and thus resulting Hamiltonian based on specified point

        if isinstance(self._driver, DeprecatedBaseDriver):
            warn_deprecated(
                "0.2.0",
                DeprecatedType.CLASS,
                f"{self._driver.__class__.__module__}.{self._driver.__class__.__qualname__}",
                new_name=
                "ElectronicStructureMoleculeDriver or VibrationalStructureMoleculeDriver",
                additional_msg="from qiskit_nature.drivers.second_quantization",
            )
        elif not isinstance(self._driver,
                            (ElectronicStructureMoleculeDriver,
                             VibrationalStructureMoleculeDriver)):
            raise QiskitNatureError(
                "Driver must be ElectronicStructureMoleculeDriver or VibrationalStructureMoleculeDriver."
            )

        self._driver.molecule.perturbations = [point]

        # find closest previously run point and take optimal parameters
        if isinstance(
                self._gss.solver,
                VariationalAlgorithm) and self._bootstrap:  # type: ignore
            prev_points = list(self._points_optparams.keys())
            prev_params = list(self._points_optparams.values())
            n_pp = len(prev_points)

            # set number of points to bootstrap
            if self._extrapolator is None:
                n_boot = len(prev_points)  # bootstrap all points
            else:
                n_boot = self._num_bootstrap

            # Set initial params # if prev_points not empty
            if prev_points:
                if n_pp <= n_boot:
                    distances = np.array(point) - np.array(
                        prev_points).reshape(n_pp, -1)
                    # find min 'distance' from point to previous points
                    min_index = np.argmin(np.linalg.norm(distances, axis=1))
                    # update initial point
                    self._gss.solver.initial_point = prev_params[
                        min_index]  # type: ignore
                else:  # extrapolate using saved parameters
                    opt_params = self._points_optparams
                    param_sets = self._extrapolator.extrapolate(
                        points=[point], param_dict=opt_params)
                    # update initial point, note param_set is a dictionary
                    self._gss.solver.initial_point = param_sets.get(
                        point)  # type: ignore

        # the output is an instance of EigenstateResult
        result = self._gss.solve(self._problem)

        # Save optimal point to bootstrap
        if isinstance(self._gss.solver, VariationalAlgorithm):  # type: ignore
            # at every point evaluation, the optimal params are updated
            optimal_params = result.raw_result.optimal_point
            self._points_optparams[point] = optimal_params

        return result
 def __init__(self):
     warn_deprecated("0.3.0", DeprecatedType.CLASS, "DeprecatedClass1",
                     DeprecatedType.CLASS, "NewClass")
     self.value = 10