Utils¶
Solvers¶
-
solve_ising
(linear, quad, num_reads=10, sweeps=1000, beta_range=(1.0, 50.0))[source]¶ [deprecated] 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.
Note
solve_ising()
is deprecated. Use dwave-neal package instead like below.>>> from pyqubo import Spin >>> import neal >>> s1, s2, s3 = Spin("s1"), Spin("s2"), Spin("s3") >>> H = (2*s1 + 4*s2 + 6*s3)**2 >>> model = H.compile() >>> bqm = model.to_bqm() >>> sa = neal.SimulatedAnnealingSampler() >>> sampleset = sa.sample(bqm, num_reads=10) >>> samples = model.decode_sampleset(sampleset) >>> best_sample = min(samples, key=lambda s: s.energy) >>> pprint(best_sample.sample) # doctest: +SKIP {'s1': 0, 's2': 0, 's3': 1}
-
solve_qubo
(qubo, num_reads=10, sweeps=1000, beta_range=(1.0, 50.0))[source]¶ [deprecated] 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]
Note
solve_qubo()
is deprecated. Use dwave-neal package instead like below.>>> from pyqubo import Spin >>> import neal >>> s1, s2, s3 = Spin("s1"), Spin("s2"), Spin("s3") >>> H = (2*s1 + 4*s2 + 6*s3)**2 >>> model = H.compile() >>> bqm = model.to_bqm() >>> sa = neal.SimulatedAnnealingSampler() >>> sampleset = sa.sample(bqm, num_reads=10) >>> samples = model.decode_sampleset(sampleset) >>> best_sample = min(samples, key=lambda s: s.energy) >>> pprint(best_sample.sample) # doctest: +SKIP {'s1': 0, 's2': 0, 's3': 1}