def test_empty_fix(self):
        linear = {1: -1.3, 4: -0.5}
        quadratic = {(1, 4): -0.6}

        sampler = FixedVariableComposite(ExactSolver())
        response = sampler.sample_ising(linear, quadratic)
        self.assertIsInstance(response, SampleSet)

        self.assertEqual(response.first.sample, {4: 1, 1: 1})
        self.assertAlmostEqual(response.first.energy, -2.4)
    def test_empty_bqm(self):
        bqm = BinaryQuadraticModel(linear={1: -1.3, 4: -0.5},
                                   quadratic={(1, 4): -0.6},
                                   offset=0,
                                   vartype=Vartype.SPIN)

        fixed_variables = {1: -1, 4: -1}
        sampler = FixedVariableComposite(ExactSolver())
        response = sampler.sample(bqm, fixed_variables=fixed_variables)
        self.assertIsInstance(response, SampleSet)
    def test_sample(self):
        bqm = BinaryQuadraticModel(linear={1: -1.3, 4: -0.5},
                                   quadratic={(1, 4): -0.6},
                                   offset=0,
                                   vartype=Vartype.SPIN)

        fixed_variables = {1: -1}
        sampler = FixedVariableComposite(ExactSolver())
        response = sampler.sample(bqm, fixed_variables=fixed_variables)

        self.assertEqual(response.first.sample, {4: -1, 1: -1})
        self.assertAlmostEqual(response.first.energy, 1.2)
        def test_empty_bqm(self):
            bqm = BinaryQuadraticModel({
                1: -1.3,
                4: -0.5
            }, {(1, 4): -0.6},
                                       0,
                                       vartype=Vartype.SPIN)

            fixed_variables = {1: -1, 4: -1}
            with self.assertWarns(DeprecationWarning):
                sampler = FixedVariableComposite(ExactSolver())
            response = sampler.sample(bqm, fixed_variables=fixed_variables)
            self.assertIsInstance(response, SampleSet)
        def test_sample(self):
            bqm = BinaryQuadraticModel({
                1: -1.3,
                4: -0.5
            }, {(1, 4): -0.6},
                                       0,
                                       vartype=Vartype.SPIN)

            fixed_variables = {1: -1}
            with self.assertWarns(DeprecationWarning):
                sampler = FixedVariableComposite(ExactSolver())
            response = sampler.sample(bqm, fixed_variables=fixed_variables)

            self.assertEqual(response.first.sample, {4: -1, 1: -1})
            self.assertAlmostEqual(response.first.energy, 1.2)
        def test_instantiation_smoketest(self):
            with self.assertWarns(DeprecationWarning):
                sampler = FixedVariableComposite(ExactSolver())

            dtest.assert_sampler_api(sampler)
from dimod.vartypes import Vartype

import dimod

from dimod import BinaryQuadraticModel
from dimod import FixedVariableComposite, ExactSolver, RoofDualityComposite
from dimod import SampleSet

try:
    import dwave.preprocessing as preprocessing
except ImportError:
    preprocessing = False

if preprocessing:

    @dimod.testing.load_sampler_bqm_tests(FixedVariableComposite(ExactSolver())
                                          )
    @dimod.testing.load_sampler_bqm_tests(
        FixedVariableComposite(dimod.NullSampler()))
    class TestFixedVariableComposite(unittest.TestCase):
        def test_instantiation_smoketest(self):
            with self.assertWarns(DeprecationWarning):
                sampler = FixedVariableComposite(ExactSolver())

            dtest.assert_sampler_api(sampler)

        def test_sample(self):
            bqm = BinaryQuadraticModel({
                1: -1.3,
                4: -0.5
            }, {(1, 4): -0.6},
    def test_instantiation_smoketest(self):
        sampler = FixedVariableComposite(ExactSolver())

        dtest.assert_sampler_api(sampler)