1
$\begingroup$

When setting up projects with Q# I used to start with the given Quick-Starting Guide. Following the tutorial I am able to setup the example problem and the program works well.

However, there seems to be some issues when trying to use the Q# Libraries, e.g., the Arithmetic libraries or Arrays. Consider the following minimal working example created from the tutorial:

Driver.cs using Microsoft.Quantum.Simulation.Core; using Microsoft.Quantum.Simulation.Simulators; using System.Diagnostics;

namespace Microsoft.Quantum.Numerics.Samples { class Program { static void Main(string[] args) { using (var qsim = new QuantumSimulator()) { RunAll.Run(qsim).Wait(); } } } }

Operation.qs namespace Bell { open Microsoft.Quantum.Canon; open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Arithmetic; // Added this line operation HelloQ () : Unit { Message("Hello quantum world!"); using ( (xQb, yQb) = (Qubit[5], Qubit[5]) ) // And this block { AddI(LittleEndian(xQb), LittleEndian(yQb)); } } }

Where only the line indicating the usage of the Microsoft.Quantum.Arithmetic library and the code block using the AddI($\cdot$) operation (or function?) have been added to the tutorial code. This results in an error :

error QS5022: No identifier with that name exists.

Whereas I am sure that this is not a Q# issue, I do wonder if anybody stumbled upon a similar problem, or know how to fix that?

Solution: Using any of the example code from GitHub, all functionalities that I was able to add work without any problems. Using such a sample project I can just delete all the code and rewrite it, which works well.

Question: While copy-paste-delete using sample projects is a viable approach to set up new projects, I do wonder what I am missing in the "normal" project setup?

$\endgroup$
0
$\begingroup$

(I tried the fix in Visual Studio, but I'm pretty sure that will work with command line as well)

You need to add Microsoft.Quantum.Numerics NuGet package reference to your project, as described here. That is the package in which AddI is defined, and by default a newly created Q# project doesn't include this reference.

If you copy an existing project from Numerics section of the samples, it will already include the reference to this package (see, for example, this .csproj file).

$\endgroup$
  • $\begingroup$ Thanks, it works. I do feel a little bad though, especially since I have more questions that I was not able to figure out :/ (but that might not be worthy of opening posts, since they are apparently easy to solve :D) $\endgroup$ – Fleeep Aug 12 at 9:10
  • 1
    $\begingroup$ It seems fair to ask questions that can be easy for somebody but you can't solve - that's what StackExchange network is for? $\endgroup$ – Mariia Mykhailova Aug 12 at 15:53
  • 1
    $\begingroup$ @Fleeep Mariia is exactly right - One aim is to be a repository of questions and answers and another is to help people find answers. Just because someone (who happens to work at the company that wrote the thing you're asking the question about!) knows the answer easily doesn't make it a worthless question! $\endgroup$ – Mithrandir24601 Aug 13 at 9:19
1
$\begingroup$

According to the [Microsoft website][1], basically you create a new C# project with language Q#. That should do the trick.

$ dotnet new console -lang Q# -o myApp
$ cd MyApp
$ dotnet run
Update:
To add dependencies, such as nuGet, go to your project folder, open the terminal, and run this:
```
$ dotnet add package Microsoft.Quantum.Numerics

  [1]: https://docs.microsoft.com/en-us/quantum/install-guide/csharp?view=qsharp-preview
$\endgroup$
  • $\begingroup$ This will not add the necessary NuGet package reference... $\endgroup$ – Mariia Mykhailova Aug 13 at 15:58
  • $\begingroup$ To add a package from the terminal, simply go to the project folder, and run commands like this way, $ cd myApp $ dotnet add ypurDesiredPackage . So to add nuGet, you add $ dotnet add package Microsoft.Quantum.Numerics $\endgroup$ – Qazi Fahim Farhan Aug 14 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.