def test_discard(self):
        linear = {0: -0.5, 1: -0.3, 2: -0.8}
        quadratic = {(0, 1, 2): -1.7}

        sampler = HigherOrderComposite(ExactSolver())
        response = sampler.sample_ising(linear, quadratic, penalty_strength=10,
                                        discard_unsatisfied=True)

        self.assertEqual(response.first.sample, {0: 1, 1: 1, 2: 1})
        self.assertAlmostEqual(response.first.energy, -3.3)
        self.assertTrue(np.prod(response.record.penalty_satisfaction))
    def test_already_qubo_2(self):
        linear = {0: -0.5, 1: -0.3}
        quadratic = {(0, 1): -1.7}

        sampler = HigherOrderComposite(ExactSolver())
        response = sampler.sample_ising(linear, quadratic, penalty_strength=10,
                                        keep_penalty_variables=True,
                                        discard_unsatisfied=True)

        self.assertEqual(response.first.sample, {0: 1, 1: 1})
        self.assertAlmostEqual(response.first.energy, -2.5)
        self.assertTrue(response.first.penalty_satisfaction)
    def test_penalty_variables(self):
        linear = {0: -0.5, 1: -0.3, 2: -0.8}
        quadratic = {(0, 1, 2): -1.7}

        sampler = HigherOrderComposite(ExactSolver())
        response = sampler.sample_ising(linear, quadratic, penalty_strength=10,
                                        keep_penalty_variables=True,
                                        discard_unsatisfied=True)

        self.assertEqual(len(response.first.sample), 5)
        self.assertAlmostEqual(response.first.energy, -3.3)
        self.assertTrue(response.first.penalty_satisfaction)