dwavesystems / dwave-system

An API for easily incorporating the D-Wave system as a sampler, either directly or through Leap's cloud-based hybrid samplers
https://docs.ocean.dwavesys.com/
Apache License 2.0
90 stars 64 forks source link

Conversion from flux_biases (units of Phi0) to h (unitless) and vice-versa #513

Closed jackraymond closed 7 months ago

jackraymond commented 8 months ago

Both flux_biases and h apply time dependent longitudinal fields (fields conjugate to sigma^z in the Hamiltonian description, see documentation). At given point in the anneal s=t/t_a, h and flux_biases can apply equal longitudinal fields subject to rescaling. If a freeze-out phenomena is assumed at a given s, as relevant to quantum Boltzmann or Boltzmann sampling, flux_biases can be replaced by h or vice-versa. 'h' is typically unitless, whereas flux has units of Phi0, the conversion is a function of published QPU properties B(s) and M_AFM. This pull request adds code for this conversion.

jackraymond commented 8 months ago

@JoelPasvolsky suggested as a reviewer.

JoelPasvolsky commented 7 months ago

@jackraymond, I started reviewing now but is it possible you have a switched sign for your temperatures.h_to_fluxbias() function?

>>> fb = [0]*qpu.properties['num_qubits']
>>> fb[30] = temperatures.h_to_fluxbias(0.5)

>>> # What I expect is an equivalent to this (most spins down):

>>> sampleset = qpu.sample_ising({30: 0.5}, {}, num_reads=5000, auto_scale=False)
>>> print(sampleset)
  30 energy num_oc.
0 -1   -0.5    4923
1 +1    0.5      77

 >>> # What I get is the opposite (most spins up):

>>> sampleset = qpu.sample_ising({30: 0}, {}, num_reads=5000, auto_scale=False, flux_biases=fb)
>>> print(sampleset)
  30 energy num_oc.
0 -1    0.0     277
1 +1    0.0    4723
jackraymond commented 7 months ago

@jackraymond, I started reviewing now but is it possible you have a switched sign for your temperatures.h_to_fluxbias() function?

>>> fb = [0]*qpu.properties['num_qubits']
>>> fb[30] = temperatures.h_to_fluxbias(0.5)

>>> # What I expect is an equivalent to this (most spins down):

>>> sampleset = qpu.sample_ising({30: 0.5}, {}, num_reads=5000, auto_scale=False)
>>> print(sampleset)
  30 energy num_oc.
0 -1   -0.5    4923
1 +1    0.5      77

 >>> # What I get is the opposite (most spins up):

>>> sampleset = qpu.sample_ising({30: 0}, {}, num_reads=5000, auto_scale=False, flux_biases=fb)
>>> print(sampleset)
  30 energy num_oc.
0 -1    0.0     277
1 +1    0.0    4723

Yep - convention for flux_biases is opposite to the convention for h. Minus sign matters!

jackraymond commented 7 months ago

Also need to be added to this file I'm not sure that having these function under Temperature Utilities is optimal.

This repo contains conversions from GHz to kB T , and some other related functions. Not sure there is a better spot. The temperature estimators can use this function directly under the freeze-out hypothesis to estimate effective temperature, so the code will interface directly with other functions in the module.

However, happy to consider other options.

JoelPasvolsky commented 7 months ago

This repo contains conversions from GHz to kB T , and some other related functions.

I wasn't concerned with the source file, I mean that users looking to use flux bias as a substitution for an h bias might not look at this temperature-related doc section. For the docs, should these be bumped out to general Utilities page functions?

jackraymond commented 7 months ago

This repo contains conversions from GHz to kB T , and some other related functions.

I wasn't concerned with the source file, I mean that users looking to use flux bias as a substitution for an h bias might not look at this temperature-related doc section. For the docs, should these be bumped out to general Utilities page functions?

I'll create a 'Unit conversion' subsection, unless you have a better suggestion

randomir commented 7 months ago

@JoelPasvolsky, test failures here are caused by (private) changes in cloud-client 0.11.3. The fix for mock tests that tweak client internals is in https://github.com/dwavesystems/dwave-system/pull/515.

codecov[bot] commented 7 months ago

Codecov Report

Attention: Patch coverage is 79.31034% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 87.61%. Comparing base (7ddf451) to head (22f3153).

Files Patch % Lines
dwave/system/temperatures.py 79.31% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #513 +/- ## ========================================== - Coverage 90.88% 87.61% -3.27% ========================================== Files 24 24 Lines 1678 1704 +26 ========================================== - Hits 1525 1493 -32 - Misses 153 211 +58 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.