Exemplo n.º 1
0
    def test_energy_equivalence(self):
        binpoly = BinaryPolynomial({'abc': 1, 'bc': 1, 'ab': -1, '': 0}, 'BINARY')
        spipoly = binpoly.to_spin()

        variables = list(binpoly.variables)
        for config in itertools.product((0, 1), repeat=len(variables)):
            binary_sample = dict(zip(variables, config))
            spin_sample = {v: 2*x - 1 for v, x in binary_sample.items()}
            self.assertAlmostEqual(spipoly.energy(spin_sample), binpoly.energy(binary_sample))
Exemplo n.º 2
0
    def test_energy_equivalence_only_linear(self):
        spipoly = BinaryPolynomial({'a': 5, 'b': -3}, 'SPIN')
        binpoly = spipoly.to_binary()

        variables = list(binpoly.variables)
        for config in itertools.product((0, 1), repeat=len(variables)):
            binary_sample = dict(zip(variables, config))
            spin_sample = {v: 2*x - 1 for v, x in binary_sample.items()}
            self.assertAlmostEqual(spipoly.energy(spin_sample), binpoly.energy(binary_sample))