QuantumLibraries
QuantumLibraries copied to clipboard
Some facts and assertions take message inputs, others don't.
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, @msoeken and I think we should develop this into a proposal and discuss it during API review.
+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)
@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!
@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, sorry for the late response. I'd be happy to take a stab at this.
Sounds good, thank you!
+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
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.