iqsharp
iqsharp copied to clipboard
Should we support passing integers as Pauli parameters to magics?
Describe the bug Currently we can use both constants PauliI ... PauliZ and integers 0 ... 3 to pass parameters of type Pauli to magic commands. However, passing an integer outside of this range does not cause an error, and yields unexpected behaviors. It might make sense to restrict the inputs to only Pauli constants.
To Reproduce Steps to reproduce the behavior: Create a Q# Jupyter notebook with the following cells:
open Microsoft.Quantum.Diagnostics;
operation Tmp(a : Pauli) : Unit {
Message($"{a}");
use q = Qubit();
R(a, 2.0, q);
DumpMachine();
}
%simulate Tmp a=4
The output of the %simulate
cell will look as follows, indicating that the invalid parameter is actually passed to the rotation gate without producing an error:
Expected behavior An error message indicating an invalid parameter passed.
System information
- OS: Windows 10 and Linux
- IQ# Version 0.18.2107153439
This looks like an issue that arises when parameters are deserialized in OperationInfo.GetRunArguments
. Adding a custom converter to JsonConverters.TupleConverters would allow for the correct error handling. The default deserialization could still be used in cases where a valid integer was passed, as in ResultConverter.