Beispiel #1
0
    def test_vartype_is_stored(self, vartype, expected_output_vartype):
        bqm = dimod.BinaryQuadraticModel(
            {0: 0.5, 2: -2.0, 3: 3},
            {(2, 1): 0.5, (1, 0): 0.4, (0, 3): -0.1},
            vartype=vartype,
        )

        serializable = bqm_to_serializable(bqm)

        assert serializable["vartype"] == expected_output_vartype
Beispiel #2
0
    def test_offset_is_stored(self, offset):
        bqm = dimod.BinaryQuadraticModel(
            {0: 0.5, 2: -2.0, 3: 3},
            {(2, 1): 0.5, (1, 0): 0.4, (0, 3): -0.1},
            offset,
            vartype=dimod.BINARY,
        )

        serializable = bqm_to_serializable(bqm)

        assert serializable["offset"] == offset
Beispiel #3
0
    def test_all_linear_coefficients_are_stored(self):
        bqm = dimod.BinaryQuadraticModel(
            {0: 1, 1: 2, 2: 3},
            {(1, 2): 0.5, (1, 0): 0.7, (0, 2): 0.9},
            -10,
            vartype=dimod.BINARY,
        )

        serializable = bqm_to_serializable(bqm)

        assert set(serializable["linear"]) == {(0, 1), (1, 2), (2, 3)}
Beispiel #4
0
    def test_all_quadratic_coefficients_are_stored(self):
        bqm = dimod.BinaryQuadraticModel(
            {0: 0.5, 2: -2.0, 3: 3},
            {(2, 1): 0.5, (1, 0): 0.4, (0, 3): -0.1},
            -5,
            vartype=dimod.BINARY,
        )

        serializable = bqm_to_serializable(bqm)

        assert set(serializable["quadratic"]) == {
            (1, 2, 0.5),
            (0, 1, 0.4),
            (0, 3, -0.1),
        }