Utils

Solvers

solve_ising(linear, quad, num_reads=10, sweeps=1000, beta_range=(1.0, 50.0))[source]

Solve Ising model with Simulated Annealing (SA) provided by neal.

Parameters:
  • linear (dict[label, float]) – The linear parameter of the Ising model.
  • quad (dict[(label, label), float]) – The quadratic parameter of the Ising model.
  • num_reads (int, default=10) – Number of run repetitions of SA.
  • sweeps (int, default=1000) – Number of iterations in each run of SA.
  • beta_range (tuple(float, float), default=(1.0, 50.0)) – Tuple of start beta and end beta.
Returns:

The solution of SA.

Return type:

dict[label, bit]

>>> from pyqubo import Spin, solve_ising
>>> s1, s2, s3 = Spin("s1"), Spin("s2"), Spin("s3")
>>> H = (2*s1 + 4*s2 + 6*s3)**2
>>> model = H.compile()
>>> linear, quad, offset = model.to_ising()
>>> solution = solve_ising(linear, quad)
solve_qubo(qubo, num_reads=10, sweeps=1000, beta_range=(1.0, 50.0))[source]

Solve QUBO with Simulated Annealing (SA) provided by neal.

Parameters:
  • qubo (dict[(label, label), float]) – The QUBO to be solved.
  • num_reads (int, default=10) – Number of run repetitions of SA.
  • sweeps (int, default=1000) – Number of iterations in each run of SA.
  • beta_range (tuple(float, float), default=(1.0, 50.0)) – Tuple of start beta and end beta.
Returns:

The solution of SA.

Return type:

dict[label, bit]

>>> from pyqubo import Spin, solve_qubo
>>> s1, s2, s3 = Spin("s1"), Spin("s2"), Spin("s3")
>>> H = (2*s1 + 4*s2 + 6*s3)**2
>>> model = H.compile()
>>> qubo, offset = model.to_qubo()
>>> solution = solve_qubo(qubo)

Asserts

assert_qubo_equal(qubo1, qubo2)[source]

Assert the given QUBOs are identical.

Parameters:
  • qubo1 (dict[(label, label), float]) – QUBO to be compared.
  • qubo2 (dict[(label, label), float]) – QUBO to be compared.