Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

%kata magic doesn't recognize C# tests #166

Closed
tcNickolas opened this issue Aug 16, 2019 · 16 comments
Closed

%kata magic doesn't recognize C# tests #166

tcNickolas opened this issue Aug 16, 2019 · 16 comments
Labels
enhancement New feature or request

Comments

@tcNickolas
Copy link
Member

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.

@bromeg bromeg added the enhancement New feature or request label Sep 5, 2019
@Manvi-Agrawal
Copy link
Contributor

Is the magic command %kata specified in this repository(ie Quantum Katas) or some other repository?

@tcNickolas
Copy link
Member Author

It's defined in Microsoft.Quantum.Katas package in this repo.

@Manvi-Agrawal
Copy link
Contributor

Thanks @tcNickolas.

@Manvi-Agrawal
Copy link
Contributor

@tcNickolas I would like to take up this issue.

@tcNickolas
Copy link
Member Author

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!

@Manvi-Agrawal
Copy link
Contributor

@rmshaffer
Copy link
Contributor

@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.

@Manvi-Agrawal
Copy link
Contributor

Hi @rmshaffer @tcNickolas, I am not able to see the modified error messages in the console window. For eg I tried to modify

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.

@tcNickolas
Copy link
Member Author

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:

  1. 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).
  2. Copy the generated .nupkg file to the folder in which your project resides (possibly PhaseEstimation kata).
  3. 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>
  1. 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!

@Manvi-Agrawal
Copy link
Contributor

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?

@tcNickolas
Copy link
Member Author

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# :-)

@Manvi-Agrawal
Copy link
Contributor

Thats a nice suggestion. I would be doing #557 first.

@Manvi-Agrawal
Copy link
Contributor

Manvi-Agrawal commented Mar 19, 2021

Hi @tcNickolas ,
Now I am able to see updated log messages while running IQ# kernel in debug mode. I did the following additional steps:

  1. Set the environment variables IQSHARP_LOG_LEVEL='Debug' and IQSHARP_SKIP_AUTO_LOAD_PROJECT='True'
  2. Added <RootNameSpace>Microsoft.Quantum.Katas</RootNameSpace> to the <PropertyGroup> tag in Microsoft.Quantum.Katas.csproj
  3. Used %package magic to load the newly built nuget package Microsoft.Quantum.Katas and also load Microsoft.Quantum.Xunit
  4. 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...

@Manvi-Agrawal
Copy link
Contributor

Hi @tcNickolas @rmshaffer, I think a good approach to solve this issue would be after the following issue is resolved microsoft/iqsharp#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 microsoft/iqsharp#277 (comment)

I would like to know your opinion on the above statement.

@tcNickolas
Copy link
Member Author

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 :-)

@tcNickolas
Copy link
Member Author

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".

@tcNickolas tcNickolas closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants