c3 icon indicating copy to clipboard operation
c3 copied to clipboard

Quantity Object returns wrong values if max_val >> value (or min_val << value)

Open MaxNaeg opened this issue 4 years ago • 1 comments

Describe the bug

If the min or max value of a Quantity object are set to a very different order of magnitude compared to the actual value, the normalized value that is stored is very close to zero/one. When trying to recover the original value with get_value() machine imprecision leads to a completely wrong result.

To Reproduce

Quantity(10e9,min_val=0e9, max_val=10e30).get_value() will give 0

Expected behavior

Quantity(10e9,min_val=0e9, max_val=10e30).get_value() should return 10e9

Environment

  • OS: ubuntu18
  • Python Version: 3.8

MaxNaeg avatar Nov 09 '21 09:11 MaxNaeg

This is a precision error from applying a transform from physical range to [-1, 1]. It has not been working properly if you exactly hit the bound, too, so the corresponding methods (e.g. https://github.com/q-optimize/c3/blob/5f20637896f404c9f7d7f6e77f2e351db23f5710/c3/c3objs.py#L256) should be reworked. Till then, a workaround is to not set huge bounds.

nwittler avatar Nov 10 '21 13:11 nwittler