示例#1
0
 def test_factory(self):
     """
     Test factory method implementation to create instances of various Extrapolators.
     """
     self.assertIsInstance(Extrapolator.factory(mode="window"),
                           WindowExtrapolator)
     self.assertIsInstance(Extrapolator.factory(mode="poly"),
                           PolynomialExtrapolator)
     self.assertIsInstance(Extrapolator.factory(mode="diff_model"),
                           DifferentialExtrapolator)
     self.assertIsInstance(Extrapolator.factory(mode="pca"),
                           PCAExtrapolator)
     self.assertIsInstance(Extrapolator.factory(mode="l1"),
                           SieveExtrapolator)
     self.assertRaises(QiskitNatureError,
                       Extrapolator.factory,
                       mode="unknown")
示例#2
0
 def test_poly_window_extrapolator(self):
     """
     Test extrapolation using an WindowExtrapolator using a data window/lookback of 3 points
     and an internal polynomial extrapolator with degree = 1. This test confirms that no
     extrapolation is performed on points before the data window, i.e, the first two points,
     and that the extrapolation of the parameters on the last three points has a error below
     a threshold when compared to the actual parameter values.
     """
     points_interspersed = [0.3, 0.5, 0.7, 0.8, 1.5]
     window_extrapolator = Extrapolator.factory(
         "window", extrapolator=PolynomialExtrapolator(degree=1), window=3)
     params = window_extrapolator.extrapolate(points=points_interspersed,
                                              param_dict=PARAM_DICT)
     self.assertFalse(params.get(0.3))
     self.assertFalse(params.get(0.5))
     sq_diff_1 = [(actual - expected)**2
                  for actual, expected in zip(params[0.7], PARAM_DICT[0.7])]
     self.assertLess(sum(sq_diff_1), 1e-1)
     sq_diff_2 = [(actual - expected)**2
                  for actual, expected in zip(params[0.8], PARAM_DICT[0.8])]
     self.assertLess(sum(sq_diff_2), 1e-2)
     sq_diff_3 = [(actual - expected)**2
                  for actual, expected in zip(params[1.5], PARAM_DICT[1.5])]
     self.assertLess(sum(sq_diff_3), 1e-2)