Consider to improve logging, if needed. #518
Description
The first implementation of Message function is minimalistic, added in #511.
Consider improving, if needed. More details are here, here, and below:
(See the latest Chris Granade's email about https://github.com/microsoft/iqsharp/blob/c93a872976692964f247b9faa8f53ee7eac4736b/src/Jupyter/Extensions.cs#L96)
From: Cesar Zaragoza Cortes
Sent: Saturday, February 13, 2021 12:05 AM
To: Chris Granade (THEY/THEM); Robin Kuzmin
Cc: Irina Yatsenko; Bettina Heim
Subject: RE: Q#: function Message()
Thanks for example Chris! I think something similar might work for the internal implementation of the QIR runtime.
Regarding APIs available through the QIR runtime, I was thinking on something similar to the SetupQirToRunOnFullStateSimulator() API.
Having said that, I think something that has the following signature would work:
void OverrideMessageOutput(std::ostream& s);
That way, by default the output goes to std::out but it can be redirected for testing purposes or by the C++ driver in the Azure Quantum service.
Cesar
From: Chris Granade
Sent: Friday, February 12, 2021 7:07 PM
To: Robin Kuzmin; Cesar Zaragoza Cortes
Cc: Irina Yatsenko; Bettina Heim
Subject: Re: Q#: function Message()
Dear all:
Thinking of IQ# as an example consumer of logging APIs, you may be interested in how the %simulate magic command configures logging for rich diagnostic output: https://github.com/microsoft/iqsharp/blob/c93a872976692964f247b9faa8f53ee7eac4736b/src/Jupyter/Extensions.cs#L96. Happy to walk through that code if it would be helpful!
Sincerely,
Dr. Chris Granade
Senior Research Software Development Engineer, Quantum Systems
AHSI D&I Representative, Quantum Systems
From: Robin Kuzmin
Sent: Friday, February 12, 2021 4:45 PM
To: Chris Granade; Cesar Zaragoza Cortes
Cc: Irina Yatsenko; Bettina Heim
Subject: RE: Q#: function Message()
Cesar,
What APIs do you need to be provided by the runtime to the Q# code in order to control the behavior of the function Message (msg : String) : Unit?
E.g. in the file mentioned by Chris the controls are
void EnableLogToConsole()
void DisableLogToConsole()
Robin Kuzmin ['robɪn kuz'mɪn], Sr. SW Dev Eng, Azure Quantum
From: Chris Granade
Sent: Friday, February 12, 2021 2:46 PM
To: Cesar Zaragoza Cortes; Robin Kuzmin
Cc: Irina Yatsenko; Bettina Heim
Subject: Re: Q#: function Message()
Dear Cesar and Robin,
That would also match more closely with how the previous runtime (i.e. C#) exposed output from Message. In particular, the SimulatorBase.OnLog and SimulatorBase.OnDisplayableDiagnostic events (https://github.com/microsoft/qsharp-runtime/blob/main/src/Simulation/Simulators/QuantumSimulator/SimulatorBase.cs) are used to expose logging and diagnostic data to host programs.
Sincerely,
Dr. Chris Granade
Senior Research Software Development Engineer, Quantum Systems
AHSI D&I Representative, Quantum Systems
From: Cesar Zaragoza Cortes
Sent: Friday, February 12, 2021 2:19 PM
To: Robin Kuzmin
Cc: Irina Yatsenko; Bettina Heim; Chris Granade
Subject: RE: Q#: function Message()
Hi Robin,
Would it be possible to output the information to an ostream which is std::cout by default but that can be changed through a QIR API?
From the perspective of Azure Quantum execution this would be ideal since it would allow us to separate the output produced during the simulation from the output of the QIR entry-point function.
Thanks,
Cesar
From: Robin Kuzmin
Sent: Friday, February 12, 2021 1:48 PM
To: Cesar Zaragoza Cortes
Cc: Irina Yatsenko, Bettina Heim; Chris Granade
Subject: Q#: function Message()
Cesar,
Can you please provide more info about the right way for the Q# programs to print/log the info to the console?
In particular, where should the function Message (msg : String) : Unit output the information? To the C++’s std::cout, or to the C’s stdout, or anywhere else? What’s the team’s strategy?
See some more details here.
I also need to test that output (to test that the Q#’s Message() function prints the expected string to the console).
From the development speed point of view,
• I have already implemented the test for the case where the Message() function outputs to the C++’s std::cout (I redirect the std::cout to the stringstream and after calling the Message() function I analyze the contents of the stringstream, more details are here and in my test).
• Redirecting the C’s stdout will take me some more time, but it is achievable according to one of the developers of the Catch2 test framework that we use.
Robin Kuzmin ['robɪn kuz'mɪn], Sr. SW Dev Eng, Azure Quantum