# Accuracy of first.energy of LeapHybridSampler

It seems to me that the values of first.energy returned by LeapHybridSampler may not be accurate.

Probably, the accuracy is 7-8 digits in decimal, although the exact value can be computed very easily.

For example, the attached sample code outputs the following result:

----start output ------

energy_first=-1854397923

energy_comp.=-1854397899

energy_diff.=24

energy_comp.=-1854397899

energy_diff.=24

----end output--------

Does anyone know the reason why the accuracy is limited?

I think 7-8 digit accuracy may not be sufficient for some applications.

----start sample code--------

from dwave.system import LeapHybridSampler

import dimod

from random import seed, randint

import numpy as np

n = 100

time_limit = 10

seed(0)

Q = {}

for x in range(n):

for y in range(x,n):

Q[(x,y)]=randint(-10000000, 10000000)

bqm = dimod.BQM.from_qubo(Q)

result = LeapHybridSampler().sample(bqm, time_limit=time_limit)

solution = list(result.first.sample.values())

energy_first = int(result.first.energy)

print(f'energy_first={energy_first}')

energy_computed= sum([solution[x]*solution[y]*Q[(x, y)] for x, y in Q.keys()])

print(f'energy_comp.={energy_computed}')

print(f'energy_diff.={energy_computed-energy_first}')

## Comments

David J(Report)Hello,

This appears to be due to rounding error.

By default Ocean calculates the energy value using float64, the default floating point precision for 64 bit systems.

One suggestion offered was to try scaling down the problem, which might help mitigate some of the rounding error.

This article gives a pretty good idea what you are seeing here:

https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems

Hopefully this helps to better understand the problem.

Please sign in to leave a comment.