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

An issue about the AssertQubitWithinTolerance operation #990

Open
@QuXing9

Description

@QuXing9

Description

Hello! As shown in the below testcase, a qubit is defined, which is named NISLVariable0. When H is applied to NISLVariable0, it has a 50% chance of being 0 and a chance of 50% being 1. But when excepted is set to Zero and tolerance is set to 0.5, the operation AssertQubitWithinTolerance throws an exception. Is this a normal behavior of the operation? And what does the tolerance parameter mean?

Testcase

namespace NISLNameSpace {
	open Microsoft.Quantum.Intrinsic;
	open Microsoft.Quantum.Convert;
	open Microsoft.Quantum.Math;
	open Microsoft.Quantum.Diagnostics;


	operation NISLOperation () : Unit {
		mutable expected = Zero;
		use NISLVariable0 = Qubit();
		H(NISLVariable0);
		mutable tolerance = 0.5;
		AssertQubitWithinTolerance(expected, NISLVariable0, tolerance);
        	Reset(NISLVariable0);
	}

	@EntryPoint()
	operation main() : Unit {
		mutable tmp = NISLOperation();
	}
}

Actual Behavior

Unhandled exception. Microsoft.Quantum.Simulation.Core.ExecutionFailException: Qubit in invalid state. Expecting: Zero with tolerance 0.5
        Expected:       1
        Actual: 0.4999999999999999

Expected Behavior

No exception

Environment

Operating system: Windows 10

dotnet version: 3.1.414

QDK: 0.21.2111177148

Command

dotnet run

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions