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

Is there a way to access the energy for solution states to create a graph of how the energy converges to minima? #489

Open wilhelmagren opened 1 year ago

wilhelmagren commented 1 year ago

Current Problem

We have a direct need to be able to plot how the energy of the states converges to local minima (ground-state of Ising Hamiltonian for which the CQM is constructed from) when using the LeapHybridCQMSampler.

Perhaps this is not possible due to how the hybrid solvers work. And if that's the case, is there anywhere I could read exactly how the hybrid solvers work so I know why we can't access the energies? Perhaps it's not at all an iterative solving process, and then of course, this would not be possible.

Additional context

Context: when solving the optimization problem with VQE using qiskit SDK we can define a callback for the solver. In this callback we are able to store the average energy for the states for each iteration of optimization. Is there any way to do something similar when solving on a Leap Hybrid Solver?

Closing words

I would be very appreciative if anyone could look at this and see whether or not this would be possible to do. Otherwise, please refer me to a place where this has been done already, or, refer me to an explanation as to why its not possible :)

Regards,

wilhelmagren commented 1 year ago

I can fill in with some more context if that helps.

For the qiskit VQE we define a log function in this way

from dataclasses import dataclass

@dataclass
class VQELog:
    values: list
    parameters: list
    def update(self, count, parameters, mean, _metadata):
        self.values.append(mean)
        self.parameters.append(parameters)
        print(f'Running circuit {count}', end='\r', flush=True)

log = VQELog([], [])

and then use the update method of the dataclass as a callback.

with Session(service=service, backend=backend) as session:
    vqe = SamplingVQE(
        sampler=Sampler(session=session),
        ansatz=ansatz,
        optimizer=optimizer,
        callback=log.update,
    )
    solver = MinimumEigenOptimizer(vqe)
    qc_result = solver.solve(qubo)

Is there any similar way you could define a callback when using the LeapHybridCQMSampler to store intermediate solution energies? Would appreciate any feedback on this :)

Regards,

arcondello commented 1 year ago

Hi @willeagren , unfortunately we don't return the burndowns from the hybrid solver - the only information we return is the amount of runtime and the amount of qpu access time. dwave-hybrid does provide open source hybrid solvers and hybrid solver construction tools if you want to see more details. Be aware however that the CQM solver is not re-implemented in dwave-hybrid at this time unfortunately.

wilhelmagren commented 1 year ago

Hi @arcondello, thanks for the reply. Do you know if it would be possible if we instead were using a BQM to sample from? I can't find anything concrete on the repo you linked that would do this.