QuantumLibraries icon indicating copy to clipboard operation
QuantumLibraries copied to clipboard

Some facts and assertions take message inputs, others don't.

Open cgranade opened this issue 5 years ago • 8 comments
trafficstars

Describe the bug The signatures of different facts and assertions are not consistent with respect to supporting message : String inputs. For example:

// No message input.
function NearEqualityFactD(actual : Double, expected : Double) : Unit;
operation AssertPhase (expected : Double, qubit : Qubit, tolerance : Double) : Unit;

// Takes message input.
function EqualityFactI(actual : Int, expected : Int, message : String) : Unit;
function AllEqualityFactB(actual : Bool[], expected : Bool[], message : String) : Unit;

cgranade avatar Jan 30 '20 23:01 cgranade

@cgranade, @msoeken and I think we should develop this into a proposal and discuss it during API review.

guenp avatar Nov 23 '20 17:11 guenp

+1 from the discussion https://github.com/microsoft/qsharp-runtime/issues/156. (The asserts I'm looking at there, primarily AssertAllZero, come from the runtime repository, so I'm not sure whether to open a new issue or just to add it here)

tcNickolas avatar Feb 02 '21 18:02 tcNickolas

@guenp and @msoeken: Would you like to draft this into a proposal? I'm also happy to do so as well, whichever you'd prefer. Thanks!

cgranade avatar Feb 02 '21 19:02 cgranade

@guenp, @msoeken: Just to follow up on this, since the March review is coming up shortly, would you prefer for me to write up a proposal on this one? Thank you!

cgranade avatar Mar 01 '21 17:03 cgranade

@cgranade, sorry for the late response. I'd be happy to take a stab at this.

guenp avatar Mar 04 '21 00:03 guenp

Sounds good, thank you!

cgranade avatar Mar 04 '21 00:03 cgranade

+1 from the discussion microsoft/qsharp-runtime#156. (The asserts I'm looking at there, primarily AssertAllZero, come from the runtime repository, so I'm not sure whether to open a new issue or just to add it here)

When unit tests fail the AssertAllZero assertion a cryptic exception message is displayed:

Unhandled exception. Microsoft.Quantum.Simulation.Core.ExecutionFailException: Qubit in invalid state. Expecting: Zero
  Expected: 0
  Actual: 0.5000000000000002

a more informative error message would be very helpful

hros avatar Jun 17 '21 23:06 hros

Some other inconsistencies that would be good to note and possibly address in a proposal:

  • The Q# style guide says that classical arguments should precede quantum arguments, but many assertions use the opposite convention. Others (e.g.: AssertQubit) follow the style guide, leading to an inconsistency.
  • Similarly, inputs that vary less frequently (e.g.: tolerance) should precede inputs that vary more frequently (e.g.: message), but some assertions use the opposite convention.

cgranade avatar Jul 15 '21 18:07 cgranade