# import dimod
# import numpy as np
# import pylab as plt

linear = {0: -1, 1: -1}
quadratic = {(0, 1): 2}
bqm = dimod.BinaryQuadraticModel(linear, quadratic, 0.0, dimod.BINARY)  # 0.0 is the value for offset
bqm_ising = bqm.change_vartype(dimod.SPIN, inplace=False)

response = dimod.ExactSolver().sample(bqm)
for sample, energy in response.data(['sample', 'energy']):
    print(sample, energy)

def Test_offset_values(offset):
    linear = {0: -1, 1: -1}
    quadratic = {(0, 1): 2}
    bqm = dimod.BinaryQuadraticModel(linear, quadratic, offset, dimod.BINARY)  # 0.0 is the value for offset
    bqm_ising = bqm.change_vartype(dimod.SPIN, inplace=False)
    response = dimod.ExactSolver().sample(bqm)
    for sample, energy in response.data(['sample', 'energy']):
        print(sample, energy)
        
for offset in [0., 1., 10]:
    print ('offset=',offset)
    Test_offset_values(offset)
    
    



Q = {('x1', 'x2'): 1, ('x1', 'z'): -2, ('x2', 'z'): -2, ('z', 'z'): 3}

from dwave.system import DWaveSampler, EmbeddingComposite

sampler = DWaveSampler()

#from dwave.system import DWaveSampler, EmbeddingComposite
#sampler = DWaveSampler()
#sampler_embedded = EmbeddingComposite(sampler)


linear = {1: 1, 2: 2, 3: 3, 4: 4}  # linear term in the Ising hamiltonian h_i s_i terms
# And the quadratic terms s_i \dot s_j terms
quadratic = {(1, 2): 12, (1, 3): 13, (1, 4): 14,  
             (2, 3): 23, (2, 4): 24,
             (3, 4): 34}
bqm_k4 = dimod.BinaryQuadraticModel(linear, quadratic, 0.5, dimod.SPIN)

#bqm_k4
bqm_k4.vartype

import dimod
>>> linear = {1: 1, 2: 2, 3: 3, 4: 4}
>>> quadratic = {(1, 2): 12, (1, 3): 13, (1, 4): 14,
...              (2, 3): 23, (2, 4): 24,
...              (3, 4): 34}
>>> bqm_k4 = dimod.BinaryQuadraticModel(linear, quadratic, 0.5, dimod.SPIN)
>>> bqm_k4.vartype
<Vartype.SPIN: frozenset([1, -1])>
>>> len(bqm_k4.linear)
4
>>> bqm_k4.contract_variables(2, 3)
>>> len(bqm_k4.linear)
3
>>> bqm_no3_qubo = bqm_k4.binary