Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was 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

Description

@AidPaike

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. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions