Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_chimera_converter(self):
h = {}
J = {(0, 4): -1.0, (6, 2): -3.0, (16, 0): 4}
chimera = oj.ChimeraModel(h, J, offset=0, unit_num_L=2)
self.assertEqual(chimera.chimera_coordinate(
4, unit_num_L=2), (0, 0, 4))
self.assertEqual(chimera.chimera_coordinate(
12, unit_num_L=2), (0, 1, 4))
self.assertEqual(chimera.chimera_coordinate(
16, unit_num_L=2), (1, 0, 0))
def test_chimera(self):
h = {}
J = {(0, 4): -1.0, (6, 2): -3.0}
bqm = oj.ChimeraModel(h, J, offset=0, unit_num_L=3)
self.assertTrue(bqm.validate_chimera())
J = {(0, 1): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=3)
with self.assertRaises(ValueError):
bqm.validate_chimera()
J = {(4, 12): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertTrue(bqm.validate_chimera())
J = {(0, 4): -1, (5, 13): 1, (24, 8): 2,
(18, 20): 1, (16, 0): 0.5, (19, 23): -2}
h = {13: 2}
chimera = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertEqual(chimera.to_index(1, 1, 1, unit_num_L=2), 25)
bqm = oj.ChimeraModel(h, J, offset=0, unit_num_L=3)
self.assertTrue(bqm.validate_chimera())
J = {(0, 1): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=3)
with self.assertRaises(ValueError):
bqm.validate_chimera()
J = {(4, 12): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertTrue(bqm.validate_chimera())
J = {(0, 4): -1, (5, 13): 1, (24, 8): 2,
(18, 20): 1, (16, 0): 0.5, (19, 23): -2}
h = {13: 2}
chimera = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertEqual(chimera.to_index(1, 1, 1, unit_num_L=2), 25)
self.assertTrue(chimera.validate_chimera())
def test_chimera(self):
h = {}
J = {(0, 4): -1.0, (6, 2): -3.0}
bqm = oj.ChimeraModel(h, J, offset=0, unit_num_L=3)
self.assertTrue(bqm.validate_chimera())
J = {(0, 1): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=3)
with self.assertRaises(ValueError):
bqm.validate_chimera()
J = {(4, 12): -1}
bqm = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertTrue(bqm.validate_chimera())
J = {(0, 4): -1, (5, 13): 1, (24, 8): 2,
(18, 20): 1, (16, 0): 0.5, (19, 23): -2}
h = {13: 2}
chimera = oj.ChimeraModel(h, J, unit_num_L=2)
self.assertEqual(chimera.to_index(1, 1, 1, unit_num_L=2), 25)
self.assertTrue(chimera.validate_chimera())
def _dict_to_model(self, var_type, h=None, J=None, Q=None, **kwargs):
if 'unit_num_L' in kwargs:
self.unit_num_L = kwargs['unit_num_L']
elif not self.unit_num_L:
raise ValueError(
'Input "unit_num_L" to the argument or the constructor of GPUSASampler.')
chimera = openjij.ChimeraModel(h=None, J=None, Q={(
(0, 0, 1), (0, 0, 4)): -1}, var_type=openjij.BINARY, unit_num_L=2, gpu=True)
return chimera