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

PrepareSparseMultiConfigurationalState function excitations is empty array out of memory error #670

Open
AidPaike opened this issue Apr 21, 2023 · 0 comments
Labels
Kind-Enhancement New feature or request Status-NeedsApiReview This PR requires an API review before merging in.

Comments

@AidPaike
Copy link

Describe the bug

Running the following programs, PrepareSparseMultiConfigurationalState leads to an out of memory error. By looking for the reason, it is because the length of excitations is 0. This causes negative infinity when the Lg function is evaluated inside the function. The debug information:

image-20230420120803017

​ In addition, none of the functions calling truncate (ceiling, floor, round) check the special values such as infinity and NaN, so Truncate (value) is responsible for the out-of-memory error.

​ It is recommended to add come code to check whether the parameter of the Truncate is valid.

To Reproduce

namespace TEST {
   open Microsoft.Quantum.Canon;
   open Microsoft.Quantum.Arrays;
   open Microsoft.Quantum.Chemistry.JordanWigner;
   open Microsoft.Quantum.Math;
   open Microsoft.Quantum.Convert;
   open Microsoft.Quantum.Simulation;
   open Microsoft.Quantum.Preparation;
   open Microsoft.Quantum.Arithmetic;
   open Microsoft.Quantum.Intrinsic;

   @EntryPoint()
   operation main() : Unit {
		mutable initialStatePreparation = SwapReverseRegister;
		mutable excitations = EmptyArray<JordanWignerInputState>();
		use qubits = Qubit[1];
		mutable APIResult = PrepareSparseMultiConfigurationalState(initialStatePreparation, excitations, qubits);//excitations  is an empty array
    }
}

Expected behavior

  1. PrepareSparseMultiConfigurationalState function excitations should consider the situation that excitations is an empty array.
  2. Truncate adds validation to the parameter.

Actual behavior

image-20230420155042506

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

I can be honored to submit a PR fix. :)

@AidPaike AidPaike added Kind-Enhancement New feature or request Status-NeedsApiReview This PR requires an API review before merging in. labels Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Kind-Enhancement New feature or request Status-NeedsApiReview This PR requires an API review before merging in.
Projects
None yet
Development

No branches or pull requests

1 participant