dwave.system.temperatures.maximum_pseudolikelihood_temperature#

maximum_pseudolikelihood_temperature(bqm: BinaryQuadraticModel | None = None, sampleset: None | SampleSet | Tuple[ndarray, List] = None, en1: ndarray | None = None, num_bootstrap_samples: int = 0, seed: int | None = None, T_guess: float | None = None, optimize_method: str | None = None, T_bracket: Tuple[float, float] = (0.001, 1000), sample_weights: ndarray | None = None) Tuple[float, ndarray][source]#

Returns a sampling-based temperature estimate.

The temperature T parameterizes the Boltzmann distribution as \(P(x) = \exp(-H(x)/T)/Z(T)\), where \(P(x)\) is a probability over a state space, \(H(x)\) is the energy function (BQM) and \(Z(T)\) the partition function (a normalization constant). Given a sample set (\(S\)), a temperature estimate establishes the temperature that is most likely to have produced the sample set. An effective temperature can be derived from a sample set by considering the rate of excitations only. A maximum-pseudo-likelihood (MPL) estimator considers local excitations only, which are sufficient to establish a temperature efficiently (in compute time and number of samples). If the BQM consists of uncoupled variables then the estimator is equivalent to a maximum likelihood estimator.

The effective MPL temperature is defined by the solution T to

\[0 = \sum_i \sum_{s \in S} f_i(s) \exp(f_i(s)/T),\]

where f is the energy lost in flipping spin i against its current assignment (the effective field).

The problem is a convex root solving problem, and is solved with SciPy optimize. In the case that all samples define local minima or maxima (all energies en1 are same sign) SciPy is bypassed and the maximizing value (T=0) is returned. This limit might be realized in low temperature samplesets.

If the distribution is not Boltzmann with respect to the BQM provided, as may be the case for heuristic samplers (such as annealers), the temperature estimate can be interpreted as characterizing only a rate of local excitations. In the case of sample sets obtained from D-Wave annealing quantum computers the temperature can be identified with a physical temperature via a late-anneal freeze-out phenomena.

Parameters:
  • bqm (dimod.BinaryQuadraticModel, optional) – Binary quadratic model describing sample distribution. If bqm and site_energy are both None, then by default 100 samples are drawn using DWaveSampler, with bqm defaulted as described.

  • sampleset (samples_like or SampleSet, optional) – A set of samples, assumed to be fairly sampled from a Boltzmann distribution characterized by bqm.

  • en1 (nd.array, optional) – Effective fields as an np.ndarray (site labels not required). Derived from the bqm and sampleset if not provided. First dimension indexes samples, second dimension indexes sites. Ordering doesn’t matter, but should be consistent with sample_weights.

  • num_bootstrap_samples (int, optional, default=0) – Number of bootstrap estimators to calculate. For now, the sampleset must have uniform sample_weights to deploy this option. An aggregated or weighted sampleset must be disaggregated with repetitions.

  • seed (int, optional) – Seeds the bootstrap method (if provided) allowing reproducibility of the estimators.

  • T_guess (float, optional) – User approximation to the effective temperature, must be a positive (non-zero) scalar value. Seeding the root-search method can enable faster convergence. By default, T_guess is ignored if it falls outside the range of T_bracket.

  • optimize_method (str, optional, default=None) – Optimize method used by SciPy root_scalar method. The default method works well under default operation, ‘bisect’ can be numerically more stable for the scalar case (temperature estimation only.

  • T_bracket (list or Tuple of 2 floats, optional, default=(0.001,1000)) – Relevant only if optimize_method=’bisect’. If excitations are absent, temperature is defined as zero, otherwise this defines the range of Temperatures over which to attempt a fit when.

  • sample_weights (np.ndarray, optional) – A set of weights for the samples. If sampleset is of type SampleSet set this is default to sampleset.record.num_occurrences, otherwise uniform weighting is the default.

Returns:

The optimal parameters and a list of bootstrapped estimators (T_estimate, T_bootstrap_estimates):

  • T_estimate: a temperature estimate

  • T_bootstrap_estimates: a list of bootstrap estimates

Return type:

Tuple

Examples

Draw samples from a D-Wave Quantum Computer for a large spin-glass problem (random couplers J, zero external field h). Establish a temperature estimate by maximum pseudo-likelihood.

Note that due to the complicated freeze-out properties of hard models, such as large scale spin-glasses, deviation from a classical Boltzmann distribution is anticipated. Nevertheless, the T estimate can always be interpreted as an estimator of local excitations rates. For example T will be 0 if only local minima are returned (even if some of the local minima are not ground states).

>>> import dimod
>>> from dwave.system.temperatures import maximum_pseudolikelihood_temperature
>>> from dwave.system import DWaveSampler
>>> from random import random
>>> sampler = DWaveSampler()
>>> bqm = dimod.BinaryQuadraticModel.from_ising({}, {e : 1-2*random() for e in sampler.edgelist})
>>> sampleset = sampler.sample(bqm, num_reads=100, auto_scale=False)
>>> T,T_bootstrap =  maximum_pseudolikelihood_temperature(bqm, sampleset)
>>> print('Effective temperature ',T)    
Effective temperature  0.24066488780293813