dwavesystems / dwave-cloud-client

A minimal implementation of the REST interface used to communicate with D-Wave Solver API (SAPI) servers.
https://docs.ocean.dwavesys.com/projects/cloud-client/en/stable/
Apache License 2.0
59 stars 40 forks source link

REST SAPI, qubit index is shifted (by a predictable amount 🤔) on output vs. input #528

Closed almosnow closed 2 years ago

almosnow commented 2 years ago

Hi all,

I'm using the Solver API to return information about a previously completed problem on your Leap platform. To do this I am querying the /problems//info endpoint and I get back the usual object w/ data, params, answer, etc...

On data, there's an object with all the properties from the submitted problem, with a key called lin that according to your docs is:

Linear coefficients (base64-encoded little-endian doubles). One value per working qubit in the same order as solver’s qubits 
property; NaN indicates an inactive qubit.

Which seems to be right and I'm able to get a list of the active qubits just by querying which ones are not NaN and retrieving their index, in one particular problem that I'll be using as an example, this list has 35 elements, and it looks like this:

[ 2433, 2463, 2464, 2478, 2479, 2494, 2509, 2524, 2539, 2553, 2568, 2583, ... ]

OTOH, on answer, there's an object that describes the solution of the sampling task, with a key called active_variables that contains:

Base-64–encoded string of the indices of the problem’s active variables.
The indices are 4-byte little-endian integers.

When I parse this data I get another list of indices which, in my example, also has 35 elements and looks like this:

[ 2467, 2497, 2498, 2512, 2513, 2528, 2543, 2558, 2573, 2587, 2602, 2617, ... ]

I presume that both lists should be equivalent, as they both refer to the qubits that were active during the sampling, but as you can see the indices do not correspond to each other. Not only that but if you sort them and compute the difference between each list there appears to be two groups of them which are shifted by a fixed number from one another, see pic:

image

I'd like to understand why is this happening, so that I'm able to map back qubits from the answer back to the initial embedding I specified on the problem definition. I know this is handled by your SDK but I am building my own custom client based on your API (as some sort of learning experience) and would like to replicate some features like this one on my own code.

Hope you can throw some clarity into this for me,

Thanks!

almosnow commented 2 years ago

Hi again, can you help me a bit w/ this? I wouldn't mind reading docs if it's there somewhere,

Thanks.

fionahanington commented 2 years ago

The rest api documentation is here: https://docs.dwavesys.com/docs/latest/doc_rest_api.html

let us know if you aren't able to find what you're looking for in the docs

almosnow commented 2 years ago

Hi Fiona, thanks,

I am not able to find anything that has to do with the "shifting" that I observe between the submitted qubit indexes and the ones I get back in the answer of the problem,

Perhaps I'm missing something about how the solvers work behind the scenes?

almosnow commented 2 years ago

My bad everyone,

The lin property on the data object contains the indexes of an enumeration of all the qubits from a solver, not the actual qubit number, for instance (qubit index) 0 -> means -> (actual qubit #) 30 on this particular topology (Advantage_system4.1).

Now that I re-read the docs, this,

One value per working qubit in the same order as solver’s qubits property

makes a lot of sense, but on a first glance I didn't get it. Perhaps it could be reworded in a more explicit way for future readers.

fionahanington commented 2 years ago

thanks for the suggestion