Ejemplo n.º 1
0
    def test_ignored_interactions(self):
        bqm = dimod.BQM.from_ising({
            'a': -4.0,
            'b': -4.0
        }, {
            ('a', 'b'): 3.2,
            ('b', 'c'): 1
        }, 1.5)

        sampler = ScaleComposite(dimod.TrackingComposite(dimod.ExactSolver()))

        sampleset = sampler.sample(bqm,
                                   scalar=.5,
                                   ignored_interactions=[('b', 'c')])

        # check that everything was restored properly
        dtest.assert_sampleset_energies(sampleset, bqm)

        self.assertEqual(
            sampler.child.input['bqm'],
            dimod.BQM.from_ising({
                'a': -2.0,
                'b': -2.0
            }, {
                'ab': 1.6,
                'bc': 1
            }, .75))
Ejemplo n.º 2
0
    def test_preprocessing(self):
        import dimod
        from dwave.preprocessing.lower_bounds import roof_duality
        from dwave.preprocessing.composites import ScaleComposite

        bqm = dimod.BinaryQuadraticModel.from_ising({'a': 10}, {
            'ab': -1,
            'bc': 1
        })
        result = roof_duality(bqm)
        self.assertFalse(bqm.variables - result)

        sampler = ScaleComposite(dimod.ExactSolver())
        result = sampler.sample(bqm, scalar=0.5)
        self.assertIn('scalar', result.info)
Ejemplo n.º 3
0
    def test_bias_range(self):
        bqm = dimod.BQM.from_ising({
            'a': -4.0,
            'b': -4.0
        }, {('a', 'b'): 3.2}, 1.5)

        sampler = ScaleComposite(dimod.TrackingComposite(dimod.ExactSolver()))

        sampleset = sampler.sample(bqm, bias_range=[-2, 2])

        # check that everything was restored properly
        dtest.assert_sampleset_energies(sampleset, bqm)

        self.assertEqual(
            sampler.child.input['bqm'],
            dimod.BQM.from_ising({
                'a': -2.0,
                'b': -2.0
            }, {('a', 'b'): 1.6}, .75))
Ejemplo n.º 4
0
 def test_api(self):
     sampler = ScaleComposite(dimod.ExactSolver())
     dtest.assert_sampler_api(sampler)
Ejemplo n.º 5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import dimod
import dimod.testing as dtest

from dwave.preprocessing.composites import ScaleComposite


@dtest.load_sampler_bqm_tests(ScaleComposite(dimod.ExactSolver()))
@dtest.load_sampler_bqm_tests(ScaleComposite(dimod.NullSampler()))
class TestScaleComposite(unittest.TestCase):
    def test_api(self):
        sampler = ScaleComposite(dimod.ExactSolver())
        dtest.assert_sampler_api(sampler)

    def test_bias_range(self):
        bqm = dimod.BQM.from_ising({
            'a': -4.0,
            'b': -4.0
        }, {('a', 'b'): 3.2}, 1.5)

        sampler = ScaleComposite(dimod.TrackingComposite(dimod.ExactSolver()))

        sampleset = sampler.sample(bqm, bias_range=[-2, 2])