[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Questions about the DoubleAsFixedPoint function running out of memory #669

Open
AidPaike opened this issue Apr 21, 2023 · 0 comments
Open
Labels
Kind-Bug Something isn't working

Comments

@AidPaike
Copy link
AidPaike commented Apr 21, 2023

Describe the bug

There was something wrong when I tried to print the result of DoubleAsFixedPoint. After debugging, I found two errors in its source code.

  1. When integerBits or fractionalBits is negative, it undergoes no validation, and logically, it will execute successfully if the sum of integerBits and fractionalBitsis greater than 0. However, negative numbers are meaningless here. For example, the official documentation's description of integerBits states: "Assumed number of integer bits (including the sign bit)."
  2. Another error is running the following program will lead to an overflow. The content of the error is in this line the related line
    let intConstant = Floor(rescaledConstant);
    , the value of rescaledConstant is too big to calculate.

To Reproduce

namespace Test {
    open Microsoft.Quantum.Logical;
    open Microsoft.Quantum.Diagnostics;
    open Microsoft.Quantum.Oracles;
    open Microsoft.Quantum.Convert;
    open Microsoft.Quantum.Arrays;
    open Microsoft.Quantum.Math;
    open Microsoft.Quantum.Arithmetic;
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;
    
    @EntryPoint()
    operation main() : Unit {
        mutable integerBits = 4;
        mutable fractionalBits = 64;
        mutable value = 9.1;
        mutable APIResult = DoubleAsFixedPoint(integerBits, fractionalBits, value);
        Message($"{APIResult}");
    }
}

Expected behavior

  1. Add fact statements to the FixedPointAsBoolArray function to prompt integerBits and fractionalBits should be positive.

  2. The overflow problem with the Floor is traced to the Truncate function.

Actual behavior

image-20230419125742169

System.OverflowException: “Arithmetic operation resulted in an overflow.”

System information

  • OS: [Windows, Ubuntu]
  • .NET Core Version: [6.0.300]
  • QDK "Microsoft.Quantum.Sdk/0.28.263081"

Additional context

We can submit a PR to fix this bug QuantumLibraries.

@AidPaike AidPaike added the Kind-Bug Something isn't working label Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Kind-Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant