def test_readme_sample(self):
        """readme sample test"""

        # pylint: disable=import-outside-toplevel,redefined-builtin

        def print(*args):
            """overloads print to log values"""
            if args:
                self.log.debug(args[0], *args[1:])

        # --- Exact copy of sample code ----------------------------------------

        import numpy as np
        from qiskit import BasicAer
        from qiskit.algorithms import AmplitudeEstimation
        from qiskit.circuit.library import NormalDistribution
        from qiskit_finance.applications import FixedIncomePricing

        # Create a suitable multivariate distribution
        num_qubits = [2, 2]
        bounds = [(0, 0.12), (0, 0.24)]
        mvnd = NormalDistribution(num_qubits,
                                  mu=[0.12, 0.24],
                                  sigma=0.01 * np.eye(2),
                                  bounds=bounds)

        # Create fixed income component
        fixed_income = FixedIncomePricing(
            num_qubits,
            np.eye(2),
            np.zeros(2),
            cash_flow=[1.0, 2.0],
            rescaling_factor=0.125,
            bounds=bounds,
            uncertainty_model=mvnd,
        )

        # the FixedIncomeExpectedValue provides us with the necessary rescalings

        # create the A operator for amplitude estimation
        problem = fixed_income.to_estimation_problem()

        # Set number of evaluation qubits (samples)
        num_eval_qubits = 5

        # Construct and run amplitude estimation
        q_i = BasicAer.get_backend("statevector_simulator")
        algo = AmplitudeEstimation(num_eval_qubits=num_eval_qubits,
                                   quantum_instance=q_i)
        result = algo.estimate(problem)

        print("Estimated value:\t%.4f" % fixed_income.interpret(result))
        print("Probability:    \t%.4f" % result.max_probability)

        # ----------------------------------------------------------------------

        with self.subTest("test estimation"):
            self.assertAlmostEqual(result.estimation_processed, 2.46, places=4)
        with self.subTest("test max.probability"):
            self.assertAlmostEqual(result.max_probability, 0.8487, places=4)
    def test_readme_sample(self):
        """ readme sample test """

        # pylint: disable=import-outside-toplevel,redefined-builtin

        def print(*args):
            """ overloads print to log values """
            if args:
                self.log.debug(args[0], *args[1:])

        # --- Exact copy of sample code ----------------------------------------

        import numpy as np
        from qiskit import BasicAer
        from qiskit.algorithms import AmplitudeEstimation, EstimationProblem
        from qiskit.circuit.library import NormalDistribution
        from qiskit_finance.applications import FixedIncomeExpectedValue

        # Create a suitable multivariate distribution
        num_qubits = [2, 2]
        bounds = [(0, 0.12), (0, 0.24)]
        mvnd = NormalDistribution(num_qubits,
                                  mu=[0.12, 0.24],
                                  sigma=0.01 * np.eye(2),
                                  bounds=bounds)

        # Create fixed income component
        fixed_income = FixedIncomeExpectedValue(num_qubits,
                                                np.eye(2),
                                                np.zeros(2),
                                                cash_flow=[1.0, 2.0],
                                                rescaling_factor=0.125,
                                                bounds=bounds)

        # the FixedIncomeExpectedValue provides us with the necessary rescalings

        # create the A operator for amplitude estimation by prepending the
        # normal distribution to the function mapping
        state_preparation = fixed_income.compose(mvnd, front=True)

        problem = EstimationProblem(
            state_preparation=state_preparation,
            objective_qubits=[4],
            post_processing=fixed_income.post_processing)

        # Set number of evaluation qubits (samples)
        num_eval_qubits = 5

        # Construct and run amplitude estimation
        q_i = BasicAer.get_backend('statevector_simulator')
        algo = AmplitudeEstimation(num_eval_qubits=num_eval_qubits,
                                   quantum_instance=q_i)
        result = algo.estimate(problem)

        print('Estimated value:\t%.4f' % result.estimation_processed)
        print('Probability:    \t%.4f' % result.max_probability)

        # ----------------------------------------------------------------------

        with self.subTest('test estimation'):
            self.assertAlmostEqual(result.estimation_processed, 2.46, places=4)
        with self.subTest('test max.probability'):
            self.assertAlmostEqual(result.max_probability, 0.8487, places=4)