QuantumKatas
QuantumKatas copied to clipboard
%kata magic doesn't recognize C# tests
PhaseEstimation kata has a test that covers Q# code but is written in C# due to the need to catch and process exceptions thrown by the task. When the kata is approached as Q# project, the test is recognized and executed together with Q# tests just fine. However, when the kata is converted to Jupyter Notebook format, the %kata magic command does not recognize the C# test. This is not unexpected, but ideally we need to come up with a way to execute C# tests from Q# notebooks.
This is related to one of the work items in #138.
Is the magic command %kata specified in this repository(ie Quantum Katas) or some other repository?
It's defined in Microsoft.Quantum.Katas package in this repo.
Thanks @tcNickolas.
@tcNickolas I would like to take up this issue.
Sure, give it a try and let us know what design you come up with. It's a rather non-trivial issue, so we'll probably want to discuss it with @rmshaffer as well, who is familiar with IQ# internals.
Thank you!
Hi @tcNickolas @rmshaffer, do you have any idea about where to see the Logger messages defined in KataMagic.cs?
Some examples are
@Manvi-Agrawal Yes, you should set the environment variable IQSHARP_LOG_LEVEL=Debug (case-sensitive) and then restart the IQ# kernel. You should then see the log messages output to the console window where you launched Jupyter Notebook.
This logging is very noisy, but hopefully it is manageable.
Hi @rmshaffer @tcNickolas, I am not able to see the modified error messages in the console window. For eg I tried to modify
Logger.LogDebug($"Resolved {userAnswer.FullName} to {skeletonAnswer}");toLogger.LogDebug($"Hi Resolved {userAnswer.FullName} to {skeletonAnswer}");and built the Microsoft.Quantum.Katas package but the console window still shows previous version
I think I would need to create a new version of Microsoft.Quantum.Katas and update the project to see modified error messages. I looked up a few links:
Any help would be greatly appreciated.
Yes, you need to update the Microsoft.Quantum.Katas project, build a NuGet package with a custom version out of it and use that package instead of the published NuGets.
Here's the sequence of steps that I use to build and use a private NuGet package:
- Build the Microsoft.Quantum.Katas project to produce a NuGet package (you can set version field in this file to get a version other than 1.0.0).
- Copy the generated .nupkg file to the folder in which your project resides (possibly PhaseEstimation kata).
- Set up NuGet.config file so that it allows the project to discover a NuGet package in the current folder in addition to the standard sources. Here's an example file (should be placed in project folder as well):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Local Folder" value="." />
</packageSources>
</configuration>
- Modify the .csproj file to change the version of the Microsoft.Quantum.Katas package to your version.
That should allow the project to pick up the custom version of the package, rather than the published one. I only tried this path with Q# projects, not with IQ#, so there might be some additional hiccups on the way.
Let me know if that path works!
Hi @tcNickolas , seems that these steps aren't sufficient to see updated messages in IQ#.
Also, a more general doubt: is there any smart way to debug kata and check_kata magic; or do we need to rely on log messages in IQ# console window?
Hmm, then this might take a different path... I don't recall debugging these magics, but I'll try to set it up locally and ask around in the team to see how it's done.
Meanwhile, it sounded like you were going to work on #557 - I'd suggest doing that one first, since it only involves plain Q# :-)
Thats a nice suggestion. I would be doing #557 first.
Hi @tcNickolas , Now I am able to see updated log messages while running IQ# kernel in debug mode. I did the following additional steps:
- Set the environment variables
IQSHARP_LOG_LEVEL='Debug'andIQSHARP_SKIP_AUTO_LOAD_PROJECT='True' - Added
<RootNameSpace>Microsoft.Quantum.Katas</RootNameSpace>to the<PropertyGroup>tag inMicrosoft.Quantum.Katas.csproj - Used
%packagemagic to load the newly built nuget packageMicrosoft.Quantum.Katasand also loadMicrosoft.Quantum.Xunit - Reloaded the workspace by using
%workspace reload
I was thinking to update the contributing guide so that it would be easy for the new contributors to validate the changes in KataMagic and CheckKataMagic on their local machine. Would love to know your opinion on the same.
Meanwhile I am thinking to prepare a design document since its not a trivial change...
Hi @tcNickolas @rmshaffer, I think a good approach to solve this issue would be after the following issue is resolved https://github.com/microsoft/iqsharp/issues/277. Because currently IQ# recognises all Q# files in the root folder of jupyter notebook and compiles them into a DLL file like this
__ws__{assemblyVersion}{projectFilenamePart}__.dll
where assemblyVersion is the currently-executing IQ# assembly version and projectFilenamePart is the unique representation of the full path to the project file on disk.
This dll unfortunately does not contain the compiled C# code, so we can't call C# code currently. As a workaround, we could try to invoke dotnet build but then it has its own hassles as explained in https://github.com/microsoft/iqsharp/issues/277#issue-680415148
I would like to know your opinion on the above statement.
A quick answer to the comment-before-last one: yes, documenting these steps in the contributor's guide would definitely be helpful!
Let me try and think of a workaround for this - I feel like I had an idea a couple of weeks ago which involved calling a Python test instead of C# one, but I can't promise that I'll recall it or that it will actually make sense :-)
We will be migrating the Katas to the new QDK that will use a different infrastructure (see https://devblogs.microsoft.com/qsharp/introducing-the-azure-quantum-development-kit-preview/ for the announcement), so we won't continue to improve the existing infrastructure of Q# notebooks magics. Closing this issue as "won't fix".