Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature feature #552

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

jackraymond
Copy link
Contributor

Add generators for the background susceptibility correction to binary quadratic models.
Generalize the maximum_pseudolikelihood estimator for multidimensional parameter inference: use cases include estimation of the background susceptibility, estimation of a conversion factor from flux biases to (unitless) linear fields, estimating relative rescaling of h at freezeout when using h_gain.
Add type hinting, improve documentation.
Standardize formatting (black) on temperature.py and related tests.

@jackraymond
Copy link
Contributor Author

@LoganLim2271 has offered to review.
Seems like my environment is not standard since some tests are failing. Will correct those now.

@jackraymond
Copy link
Contributor Author

Can't reproduce these failing tests in a new python 3.13 environment. The errors relate to SciPy return object, but scipy 1.15 (default install) and mos trecent 2.2.1 both throw no errors for me.

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 84.38819% with 37 lines in your changes missing coverage. Please review.

Project coverage is 85.81%. Comparing base (1bb84c6) to head (9a60c0b).

Files with missing lines Patch % Lines
dwave/system/temperatures.py 84.38% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #552      +/-   ##
==========================================
- Coverage   88.75%   85.81%   -2.94%     
==========================================
  Files          21       21              
  Lines        1654     1777     +123     
==========================================
+ Hits         1468     1525      +57     
- Misses        186      252      +66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jackraymond
Copy link
Contributor Author

@kevinchern is also willing to take a look

Copy link

@LoganLim2271 LoganLim2271 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to look at this intermittently, some minor comments

dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kevinchern kevinchern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some to-dos

  1. typeset: math, URLs, variable/code name
  2. complete docstrings, e.g., args and return types

What are the motivation for the many customizable arguments? For example,

  1. passing in degenerative_fields
  2. optimization method (is there a robust method)
  3. univariate case versus calling multivariate case with, e.g., f(x)->f([x])

dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
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)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default excludes 0.
Should note the following in the docstring:

  1. The arbitrary choice of 0.001 and
  2. There is a check for when T=0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't the optimization methods in scipy return boundary values? i.e., no need to check for T=0 and leave it to scipy to return 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't trust scipy to handle the case beta=Infinity (T=0) correctly. It turns out this is a very common outcome since the main usage is for heuristic optimizers that return local minima exclusively (or disproportionately).

method works well under default operation, 'bisect' can be
numerically more stable for the scalar case (Temperature estimation
only).
bisect_bracket: Relevant only if optimize_method='bisect' and for a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above: method-specific args could be packed into a kwargs_opt=None arg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good suggestion. For legacy reasons I didn't think of it (was originally matlab translated to python within sciPy dependence).

):
# Only local minima (or maxima) observed
x = np.sign(max_excitation) * float("Inf")
if max_excitation == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this special case

dwave/system/temperatures.py Outdated Show resolved Hide resolved
# Infinite results from all local minima, well defined limit
x_bootstraps = x * np.ones(num_bootstrap_samples)
else:
# To do: Add to examples!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
dwave/system/temperatures.py Outdated Show resolved Hide resolved
return -1 / x, -1 / x_bs


def maximum_pseudolikelihood(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has become a very long function with many branches. Could it be split up and organized into smaller functions for the various cases and checks? That would make it much easier to review and maintain, and would also allow for better documentation and comments.

@jackraymond
Copy link
Contributor Author

Some to-dos

1. typeset: math, URLs, variable/code name

2. complete docstrings, e.g., args and return types

What are the motivation for the many customizable arguments? For example,

1. passing in `degenerative_fields`

2. optimization method (is there a robust method)

3. univariate case versus calling multivariate case with, e.g.,  f(x)->f([x])
  1. This is a recent addition. Could hardcode True, will think about this.
  2. For well posed problems all methods are robust, convex optimization. I should probably take greater advantage of this to simplify the code. However, need to better document the catching/special treatment of pathological cases.
  3. Called functions in numpy and SciPy rely on the same distinction is the main one. Its hard work to continually turn scalars into lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants