def test_simple2(self): """ simple2 test """ # Computes the cost using the exact eigensolver # and compares it against pre-determined value. result = NumPyMinimumEigensolver(self.qubit_op).run() quantum_solution = get_portfoliodiversification_solution( self.instance, self.n, self.q, result) ground_level = get_portfoliodiversification_value( self.instance, self.n, self.q, quantum_solution) np.testing.assert_approx_equal(ground_level, 1.8)
def test_portfolio_diversification(self): """ portfolio diversification test """ # Something of an integration test # Solve the problem in a classical fashion via CPLEX and compare the solution # Note that CPLEX uses a completely different integer linear programming formulation. if not _HAS_CPLEX: self.skipTest('CPLEX is not installed.') x = None classical_optimizer = ClassicalOptimizer(self.instance, self.n, self.q) x, classical_cost = classical_optimizer.cplex_solution() # Solve the problem using the exact eigensolver result = NumPyMinimumEigensolver(self.qubit_op).run() quantum_solution = get_portfoliodiversification_solution( self.instance, self.n, self.q, result) ground_level = get_portfoliodiversification_value( self.instance, self.n, self.q, quantum_solution) if x is not None: np.testing.assert_approx_equal(ground_level, classical_cost) np.testing.assert_array_almost_equal(quantum_solution, x, 5)
def test_portfolio_diversification(self): """ portfolio diversification test """ # Something of an integration test # Solve the problem in a classical fashion via CPLEX and compare the solution # Note that CPLEX uses a completely different integer linear programming formulation. x = None try: classical_optimizer = ClassicalOptimizer(self.instance, self.n, self.q) x, classical_cost = classical_optimizer.cplex_solution() except Exception: # pylint: disable=broad-except # This test should not focus on the availability of CPLEX, so we just eat the exception. self.skipTest("CPLEX may be missing.") # Solve the problem using the exact eigensolver result = NumPyMinimumEigensolver(self.qubit_op).run() quantum_solution = get_portfoliodiversification_solution(self.instance, self.n, self.q, result) ground_level = get_portfoliodiversification_value(self.instance, self.n, self.q, quantum_solution) if x is not None: np.testing.assert_approx_equal(ground_level, classical_cost) np.testing.assert_array_almost_equal(quantum_solution, x, 5)