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

dwave.system.temperatures.fast_effective_temperature does not accept dwave.samplers.sa.SimulatedAnnealingSampler #553

Open
VolodyaCO opened this issue Jan 15, 2025 · 4 comments

Comments

@VolodyaCO
Copy link

Description
I'm trying to get the effective temperature using the fast_effective_temperature function on a simulated annealing sampler, but I'm getting the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[44], [line 1](vscode-notebook-cell:?execution_count=44&line=1)
----> [1](vscode-notebook-cell:?execution_count=44&line=1) fast_effective_temperature(qpu_model.sampler, num_reads=1000, sampler_params={"beta_range" : [target_beta]*2})

File ~/miniforge3/envs/jt310/lib/python3.10/site-packages/dwave/system/temperatures.py:769, in fast_effective_temperature(sampler, num_reads, seed, h_range, sampler_params, optimize_method, num_bootstrap_samples)
    [766](https://file+.vscode-resource.vscode-cdn.net/env/lib/python3.10/site-packages/dwave/system/temperatures.py:766)         raise ValueError('h_range[1] exceeds programmable range')
    [768](https://file+.vscode-resource.vscode-cdn.net/env/lib/python3.10/site-packages/dwave/system/temperatures.py:768) prng = np.random.RandomState(seed)
--> [769](https://file+.vscode-resource.vscode-cdn.net/env/lib/python3.10/site-packages/dwave/system/temperatures.py:769) h_values = h_range[0] + (h_range[1]-h_range[0])*prng.rand(len(sampler.nodelist))
    [770](https://file+.vscode-resource.vscode-cdn.net/env/lib/python3.10/site-packages/dwave/system/temperatures.py:770) bqm = dimod.BinaryQuadraticModel.from_ising({var: h_values[idx] for idx,var in enumerate(sampler.nodelist)}, {})
    [772](https://file+.vscode-resource.vscode-cdn.net/env/lib/python3.10/site-packages/dwave/system/temperatures.py:772) #Create local sampling_params copy - default necessary additional fields:

AttributeError: 'SimulatedAnnealingSampler' object has no attribute 'nodelist'

To Reproduce

From the code it's clear that the SimulatedAnnealingSampler initialiser does not create a property/attribute called nodelist.

Expected behavior
If no structure is given to SimulatedAnnealingSampler when instiantiating it, i.e., no initialisation arguments are needed, I'd expect the temperature routine to fail. Maybe the temperature routine should not accept any dimod.Sampler as sampler.

@jackraymond
Copy link
Contributor

jackraymond commented Jan 16, 2025

Note that this estimator calculates the temperature based on the rate of local excitations. By definition, an SA sampler yields a rate of excitations close to 1/beta_range[1], so this method is not required.

fast_effective_temperature assumes that the sampler operates on a fixed size problem (sampler.nodelist), with an informative bounded range of linear biases (h_range). For a sampler like SA that is not constrained in this way you need to specify the problem (a bqm):

T, _ = maximum_pseudolikelihood_temperature(bqm, sampleset=SimulatedAnnealingSampler().sample(bqm, num_reads=num_reads))

@VolodyaCO
Copy link
Author

@jackraymond my comment just comes from a typing annotation perspective. Since the SA sampler is a dimod.Sampler, the function should accept it and run without errors. If there's no way of distinguishing samplers on a fixed size problem, I propose that we include raising a more informative error when the maximum_pseudolikelihood_temperature is given a SA instance.

@VolodyaCO
Copy link
Author

This issue might be closed once #552 is merged in

@jackraymond
Copy link
Contributor

I'll make a correction as part of the pull request, thanks for following up and clarifying. Type restriction should be dimod.StructuredSolver based on my argument, but I'll probably add support for dimod.Sampler since its only a technicality that prevents this.

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

No branches or pull requests

2 participants