Пример #1
0
    def test_load(self):
        filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                'data', 'coo_qubo.qubo')

        with open(filepath, 'r') as fp:
            bqm = coo.load(fp, dimod.BinaryQuadraticModel.empty(dimod.BINARY))

        self.assertEqual(
            bqm,
            dimod.BinaryQuadraticModel.from_qubo({
                (0, 0): -1,
                (1, 1): -1,
                (2, 2): -1,
                (3, 3): -1
            }))
Пример #2
0
    def test_functional_file_empty_BINARY(self):

        bqm = dimod.BinaryQuadraticModel.empty(dimod.BINARY)

        tmpdir = tempfile.mkdtemp()
        filename = os.path.join(tmpdir, 'test.qubo')

        with open(filename, 'w') as file:
            coo.dump(bqm, fp=file)

        with open(filename, 'r') as file:
            new_bqm = coo.load(file, dimod.BinaryQuadraticModel, dimod.BINARY)

        shutil.rmtree(tmpdir)

        self.assertEqual(bqm, new_bqm)
Пример #3
0
    def test_functional_file_SPIN(self):

        bqm = dimod.BinaryQuadraticModel({0: 1.}, {
            (0, 1): 2,
            (2, 3): .4
        }, 0.0, dimod.SPIN)

        tmpdir = tempfile.mkdtemp()
        filename = os.path.join(tmpdir, 'test.qubo')

        with open(filename, 'w') as file:
            coo.dump(bqm, fp=file)

        with open(filename, 'r') as file:
            new_bqm = coo.load(file, dimod.BinaryQuadraticModel, dimod.SPIN)

        shutil.rmtree(tmpdir)

        self.assertEqual(bqm, new_bqm)