View variable value after execution?

Is it possible to view and save the value of a variable after execution of a program on  Ocean IDE ?



  • Hi Ramy,

    Due to the probabilistic nature of QPU, it might return different solutions for different runs. Ocean stores the output from the sampler in dimod.SampleSet class object.

    If you want to save the values returned for all samples, you can do so either by converting the SampleSet to a serializable object and then dumping it to a JSON file or by "pickling" the object. Here is a good community post that describes the different ways to do this:

    If you are only interested in viewing and saving the value of variables in the lowest energy solution, you can do so by using sampleset.first.sample. This returns a dictionary with variable name as the key.

    For example:

    from dwave.system import EmbeddingComposite, DWaveSampler

    Q = {('x','x'): 1, ('y','y'):0,('x','y'):0.1}

    sampler = EmbeddingComposite(DWaveSampler())

    sampleset = sampler.sample_qubo(Q, num_reads= 100)

       x  y energy num_oc. chain_.
    0  0  1    0.0      56     0.0
    1  0  0    0.0      43     0.0
    2  1  1    1.1       1     0.0
    ['BINARY', 3 rows, 100 samples, 2 variables]

    {'x': 0, 'y': 1}

    Also, you can read more about the SampleSet object returned by a sampler here:

    Comment actions Permalink
  • Thanks Tanvi! That was helpful :)

    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post