microsoft / QuantumLibraries

Q# libraries for the Quantum Development Kit
https://docs.microsoft.com/quantum
MIT License
543 stars 179 forks source link

An issue about the IncrementByModularInteger function #681

Open xwqmary opened 1 year ago

xwqmary commented 1 year ago

Describe the bug The function executes as if it were (increment+target) -modulus, not the (increment+target) %modulus in the description document

Testcase

namespace NISLNameSpace {
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Measurement;
    open Microsoft.Quantum.Arithmetic;
    open Microsoft.Quantum.Diagnostics;
    @EntryPoint()
    operation main() : Unit {
        mutable increment = 22;
        mutable modulus = 5;
        use NISLQubitArray38 = Qubit[7];
        mutable target = LittleEndian(NISLQubitArray38);
        let measuredResult1 = MeasureInteger(LittleEndian(target!));
        IncrementByModularInteger(increment, modulus, target);
        let measuredResult = MeasureInteger(LittleEndian(target!));
        Message($"Measured result: {measuredResult}");
        ResetAll(NISLQubitArray38);}
}

Expected behavior Execute the command dotnet run -s QuantumSimulator to expect output 2 but the actual output is 17

**

System information

** Operating system: Win 11 dotnet version 7.0.306