Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to run Q# program because an dotnet runtime error #81679

Closed
weucode opened this issue Feb 6, 2023 · 6 comments
Closed

Fail to run Q# program because an dotnet runtime error #81679

weucode opened this issue Feb 6, 2023 · 6 comments

Comments

@weucode
Copy link

weucode commented Feb 6, 2023

Description

When running the program in this issue, it went wrong with a runtime exceptionSystem.DivideByZeroException: Attempted to divide by zero.

We tried to import ModPowL as a user-defined API and call it, but it did not get the same exception, meaning that the content in ModPowL was right. Moreover, we found that the error message point to something error in this page.

Here are the error message:

Unhandled exception. System.DivideByZeroException: Attempted to divide by zero.
 ---> NISLNameSpace.main on /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10

Unhandled exception: System.DivideByZeroException: Attempted to divide by zero.
   at System.Numerics.BigIntegerCalculator.PowCore(UInt32 power, UInt32 modulus, UInt64 value, UInt64 result)
   at System.Numerics.BigInteger.ModPow(BigInteger value, BigInteger exponent, BigInteger modulus)
   at Microsoft.Quantum.Math.ModPowL.Native.<>c.<get___Body__>b__2_0(ValueTuple`3 args)
   at Microsoft.Quantum.Simulation.Core.Function`2.Apply(I a)
   at Microsoft.Quantum.Simulation.Core.Function`2.Microsoft.Quantum.Simulation.Core.ICallable<I,O>.Apply(I args)
   at NISLNameSpace.main.<get___Body__>b__16_0(QVoid __in__) in /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10
   at Microsoft.Quantum.Simulation.Core.Operation`2.Apply(I a)
   at Microsoft.Quantum.Simulation.Core.Operation`2.Apply[GenO](Object args)
   at Microsoft.Quantum.Simulation.Common.SimulatorBase.Execute[T,I,O](I args)
   at Microsoft.Quantum.Simulation.Common.SimulatorBase.<>c__DisplayClass68_0`3.<Run>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Quantum.EntryPointDriver.Simulation`3.RunSimulator(TIn input, Func`1 createSimulator)
   at Microsoft.Quantum.EntryPointDriver.Simulation`3.Simulate(IEntryPoint entryPoint, TIn input, DriverSettings settings, String simulator)
   at System.CommandLine.Invocation.CommandHandler.GetResultCodeAsync(Object value, InvocationContext context)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__20_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__21_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseExceptionHandler>b__0>d.MoveNext()

Can you give me some suggestion about why this program run failure?

Reproduction Steps

Run the program.

	open Microsoft.Quantum.Math;
	open Microsoft.Quantum.Intrinsic;

	@EntryPoint()
	operation main() : Unit {
		let value = 1L;
		let exponent = 0L;
		let modulus = 0L;
		let result = ModPowL(value,exponent,modulus);
		Message($"{value}");
		Message($"{exponent}");
		Message($"{modulus}");
		Message($"{result}");
	}
}

Expected behavior

1
0
0
1

Actual behavior

Unhandled exception. System.DivideByZeroException: Attempted to divide by zero.
---> NISLNameSpace.main on /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10

Regression?

No response

Known Workarounds

No response

Configuration

dotnet version:6.0.400

os version:Windows10 & Ubuntu18.04

QDK version:0.27.253010

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When running the program in this issue, it went wrong with a runtime exceptionSystem.DivideByZeroException: Attempted to divide by zero.

We tried to import ModPowL as a user-defined API and call it, but it did not get the same exception, meaning that the content in ModPowL was right. Moreover, we found that the error message point to something error in this page.

Here are the error message:

Unhandled exception. System.DivideByZeroException: Attempted to divide by zero.
 ---> NISLNameSpace.main on /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10

Unhandled exception: System.DivideByZeroException: Attempted to divide by zero.
   at System.Numerics.BigIntegerCalculator.PowCore(UInt32 power, UInt32 modulus, UInt64 value, UInt64 result)
   at System.Numerics.BigInteger.ModPow(BigInteger value, BigInteger exponent, BigInteger modulus)
   at Microsoft.Quantum.Math.ModPowL.Native.<>c.<get___Body__>b__2_0(ValueTuple`3 args)
   at Microsoft.Quantum.Simulation.Core.Function`2.Apply(I a)
   at Microsoft.Quantum.Simulation.Core.Function`2.Microsoft.Quantum.Simulation.Core.ICallable<I,O>.Apply(I args)
   at NISLNameSpace.main.<get___Body__>b__16_0(QVoid __in__) in /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10
   at Microsoft.Quantum.Simulation.Core.Operation`2.Apply(I a)
   at Microsoft.Quantum.Simulation.Core.Operation`2.Apply[GenO](Object args)
   at Microsoft.Quantum.Simulation.Common.SimulatorBase.Execute[T,I,O](I args)
   at Microsoft.Quantum.Simulation.Common.SimulatorBase.<>c__DisplayClass68_0`3.<Run>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Quantum.EntryPointDriver.Simulation`3.RunSimulator(TIn input, Func`1 createSimulator)
   at Microsoft.Quantum.EntryPointDriver.Simulation`3.Simulate(IEntryPoint entryPoint, TIn input, DriverSettings settings, String simulator)
   at System.CommandLine.Invocation.CommandHandler.GetResultCodeAsync(Object value, InvocationContext context)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__20_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__21_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseExceptionHandler>b__0>d.MoveNext()

Can you give me some suggestion about why this program run failure?

Reproduction Steps

Run the program.

	open Microsoft.Quantum.Math;
	open Microsoft.Quantum.Intrinsic;

	@EntryPoint()
	operation main() : Unit {
		let value = 1L;
		let exponent = 0L;
		let modulus = 0L;
		let result = ModPowL(value,exponent,modulus);
		Message($"{value}");
		Message($"{exponent}");
		Message($"{modulus}");
		Message($"{result}");
	}
}

Expected behavior

1
0
0
1

Actual behavior

Unhandled exception. System.DivideByZeroException: Attempted to divide by zero.
---> NISLNameSpace.main on /home/htm/qsharpProject/quantumDemo3/Program.qs:line 10

Regression?

No response

Known Workarounds

No response

Configuration

dotnet version:6.0.400

os version:Windows10 & Ubuntu18.04

QDK version:0.27.253010

Other information

No response

Author: weucode
Assignees: -
Labels:

area-System.Numerics, untriaged

Milestone: -

@Clockwork-Muse
Copy link
Contributor

Clockwork-Muse commented Feb 6, 2023

let modulus = 0L;

This is a definition problem of the modulus operator:

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another (called the modulus of the operation).
Given two positive numbers a and n, a modulo n (often abbreviated as a mod n) is the remainder of the Euclidean division of a by n, where a is the dividend and n is the divisor.

In other words, you're asking the code to perform someValue % 0, so a DivideByZeroException is expected (in some cases this can even be spotted at compile time).

We tried to import ModPowL as a user-defined API and call it, but it did not get the same exception, meaning that the content in ModPowL was right.

Not sure what you were doing here, but this sounds like a more serious problem, because the exception should have been thrown.


As designed, not a bug in the core libraries.

@dakersnar dakersnar added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels Feb 6, 2023
@ghost
Copy link

ghost commented Feb 6, 2023

This issue has been marked needs-author-action and may be missing some important information.

@ghost ghost added the no-recent-activity label Feb 21, 2023
@ghost
Copy link

ghost commented Feb 21, 2023

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Mar 7, 2023

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Mar 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 6, 2023
@tannergooding tannergooding removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 24, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants