Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Prepare standalone docs for publication #804

Merged
merged 15 commits into from May 1, 2020
2 changes: 1 addition & 1 deletion .openpublishing.publish.config.json
Expand Up @@ -72,7 +72,7 @@
{
"path_to_root": "articles/quantum",
"url": "https://github.com/microsoft/quantum",
"branch": "master",
"branch": "feature/standalone",
"branch_mapping": {}
}
],
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Expand Up @@ -5,5 +5,8 @@
// cause problems working with the Samples Browser.
"MD003": {"style": "atx"},
"MD013": false
}
},
"cSpell.words": [
"Quickstart"
]
}
10 changes: 1 addition & 9 deletions articles/TOC.yml
Expand Up @@ -17,15 +17,7 @@
- name: Get started with the QDK
href: welcome.md
- name: Install the QDK
items:
- name: Installation overview
href: install-guide/index.md
- name: Q# + C#
href: install-guide/csinstall.md
- name: Q# + Python
href: install-guide/pyinstall.md
- name: Q# Jupyter notebooks
href: install-guide/qjupyter.md
href: install-guide/toc.yml
- name: Update the QDK
href: install-guide/update.md
- name: How to create a Q# project
Expand Down
158 changes: 56 additions & 102 deletions articles/install-guide/csinstall.md
Expand Up @@ -7,135 +7,89 @@ ms.topic: article
ms.custom: how-to
uid: microsoft.quantum.install.cs
---
# Develop with Q# + C#
# Using Q# with C\# and F\#

Install the QDK to develop C# host programs to call Q# operations.
Q# is built to play well with .NET languages such as C# and F#.
In this guide, we'll demonstrate how to use Q# with a host program written in a .NET language.

Q# is built to play well with .NET languages--specifically C#. You can work with this pairing inside different development environments:
## Prerequisites

- [Q# + C# using Visual Studio (Windows)](#VS)
- [Q# + C# using Visual Studio Code (Windows, Linux and Mac)](#VSC)
- [Q# + C# using the `dotnet` command-line tool](#command)
- Install the Quantum Development Kit [for use with Q# command-line projects](xref:microsoft.quantum.install.standalone).

## Develop with Q# + C# using Visual Studio <a name="VS"></a>
## Creating a Q# library and a .NET host

Visual Studio offers a rich environment for developing Q# programs. The Q# Visual Studio extension contains templates for Q# files and projects as well as syntax highlighting, code completion and IntelliSense support.
The first step is to create projects for your Q# library, and for the .NET host that will call into the operations and functions defined in your Q# library.

### [Visual Studio 2019](#tab/tabid-vs2019)

1. Pre-requisites
- Create a new Q# library
- Go to **File** -> **New** -> **Project**
- Type "Q#" in the search box
- Select **Q# Library**
- Select **Next**
- Choose a name and location for your library
- Make sure that "place project and solution in same directory" is **unchecked**
- Select **Create**
- Create a new C# or F# host program
- Go to **File** → **New** → **Project**
- Select "Console App (.NET Core")" for either C# or F#
- Select **Next**
- Under *solution*, select "add to solution"
- Choose a name for your host program
- Select **Create**

- [Visual Studio](https://visualstudio.microsoft.com/downloads/) 16.3, with the .NET Core cross-platform development workload enabled
### [Visual Studio Code or Command Line](#tab/tabid-cmdline)

1. Install the Q# Visual Studio extension
- Create a new Q# library

- Download and install the [Visual Studio extension](https://marketplace.visualstudio.com/items?itemName=quantum.DevKit)
```dotnetcli
dotnet new classlib -lang Q# -o quantum
```

1. Verify the installation by creating a `Hello World` application
- Create a new C# or F# console project

- Create a new Q# application
```dotnetcli
dotnet new console -lang C# -o host
```

- Go to **File** -> **New** -> **Project**
- Type `Q#` in the search box
- Select **Q# Application**
- Select **Next**
- Choose a name and location for your application
- Select **Create**
- Add your Q# library as a reference from your host program

- Inspect the project
```dotnetcli
cd host
dotnet add reference ../quantum/quantum.csproj
```

You should see that two files have been created: `Driver.cs`, which is the C# host application; and `Operation.qs`, which is a Q# program that defines a simple operation to print a message to the console.
- [Optional] Create a solution for both projects

- Run the application
```dotnetcli
dotnet new sln -n quantum-dotnet
dotnet sln quantum-dotnet.sln add ./quantum/quantum.csproj
dotnet sln quantum-dotnet.sln add ./host/host.csproj
```

- Select **Debug** -> **Start Without Debugging**
- You should see the text `Hello quantum world!` printed to a console window.
***

> [!NOTE]
> * If you have multiple projects within one Visual Studio solution, all projects contained in the solution need to be in the same folder as the solution, or in one of its subfolders.
## Calling into Q# from .NET

## Develop with Q# + C# using Visual Studio Code <a name="VSC"></a>
Once you have your projects set up following the above instructions, you can call into Q# from your .NET console application.
The Q# compiler will create .NET classes for each Q# operation and function that allow you to run your quantum programs on a simulator.

Visual Studio Code (VS Code) offers a rich environment for developing Q# programs on Windows, Linux and Mac. The Q# VS Code extension includes support for Q# syntax highlighting, code completion, and Q# code snippets.
For example, the [.NET interoperability sample](https://github.com/microsoft/Quantum/tree/master/samples/interoperability/dotnet) includes the following an example Q# operation:

1. Pre-requisites
:::code language="qsharp" source="~/quantum/samples/interoperability/dotnet/qsharp/Operations.qs" range="67-75":::

- [VS Code](https://code.visualstudio.com/download)
- [.NET Core SDK 3.1 or later](https://www.microsoft.com/net/download)
To call this operation from .NET on a quantum simulator, you can use the `Run` method of the `ReconstructOracleParameters` .NET class generated by the Q# compiler:

1. Install the Quantum VS Code extension
### [C#](#tab/tabid-csharp)

- Install the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=quantum.quantum-devkit-vscode)
:::code language="csharp" source="~/quantum/samples/interoperability/dotnet/csharp/Host.cs" range="4-":::

1. Install the Quantum project templates:
### [F#](#tab/tabid-fsharp)

- Go to **View** -> **Command Palette**
- Select **Q#: Install project templates**

You now have the Quantum Development Kit installed and ready to use in your own applications and libraries.

1. Verify the installation by creating a `Hello World` application

- Create a new project:

- Go to **View** -> **Command Palette**
- Select **Q#: Create New Project**
- Select **Standalone console application**
- Navigate to the location on the file system where you would like to create the application
- Click on the **Open new project...** button, once the project has been created

- If you don't already have the C# extension for VS Code installed, a pop-up will appear. Install the extension.

- Run the application:

- Go to **Terminal** -> **New Terminal**
- Enter `dotnet run`
- You should see the following text in the output window `Hello quantum world!`


> [!NOTE]
> * Workspaces with multiple root folders are not currently supported by the Visual Studio Code extension. If you have multiple projects within one VS Code workspace, all projects need to be contained within the same root folder.

## Develop with Q# + C# using the `dotnet` command-line tool <a name="command"></a>

Of course, you can also build and run Q# programs from the command line by simply installing the .NET Core SDK and the QDK project templates.

1. Pre-requisites

- [.NET Core SDK 3.1 or later](https://www.microsoft.com/net/download)

1. Install the Quantum project templates for .NET

```dotnetcli
dotnet new -i Microsoft.Quantum.ProjectTemplates
```

You now have the Quantum Development Kit installed and ready to use in your own applications and libraries.

1. Verify the installation by creating a `Hello World` application

- Create a new application

```dotnetcli
dotnet new console -lang "Q#" -o runSayHello
```

- Navigate to the new application directory

```bash
cd runSayHello
```

You should see that two files have been created, along with the project files of the application: a Q# file (`Operation.qs`) and a C# host file (`Driver.cs`).

- Run the application

```dotnetcli
dotnet run
```

You should see the following output: `Hello quantum world!`
:::code language="fsharp" source="~/quantum/samples/interoperability/dotnet/fsharp/Host.fs" range="4-":::

***

## What's next?

Now that you have installed the Quantum Development Kit in your preferred environment, you can write and run [your first quantum program](xref:microsoft.quantum.write-program).
Now that you have Quantum Development Kit set up for both Q# command-line programs, and for interoperability with .NET, you can write and run [your first quantum program](xref:microsoft.quantum.write-program).
5 changes: 4 additions & 1 deletion articles/install-guide/index.md
Expand Up @@ -23,6 +23,9 @@ In addition, the QDK provides Q# support for Jupyter Notebooks with the IQ# Jupy

The QDK is available for multiple development environments. Select your preferred setup from the sections below:

- [Q# command line application:](xref:microsoft.quantum.install.standalone) choose this approach if you want to work with Q# from the command line. This does not require a driver or a host program like the below options.
- [Install Q# for Jupyter Notebooks:](xref:microsoft.quantum.install.jupyter) choose this environment to execute Q# code in cells with embedded text or create quantum computing interactive tutorials.
<!---
- [Install Q# for C#:](xref:microsoft.quantum.install.cs) choose this environment if you want to combine C# and Q# to create a C# host program that calls Q# operations.
-->
Copy link
Contributor

@geduardo geduardo May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!---
- [Install Q# for C#:](xref:microsoft.quantum.install.cs) choose this environment if you want to combine C# and Q# to create a C# host program that calls Q# operations.
-->
- [Install Q# for .NET:](xref:microsoft.quantum.install.cs) Q# can also be combined with the .NET ecosystem. Choose this environment if you want to combine F# or C# with Q# to create classical host programs that call Q# operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #806.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

        <!---
      
      
        
        - [Install Q# for C#:](xref:microsoft.quantum.install.cs) choose this environment if you want to combine C# and Q# to create a C# host program that calls Q# operations.
      
      
        
        -->
      
      
        
        - [Install Q# for .NET:](xref:microsoft.quantum.install.cs) Q# can also be combined with the .NET ecosystem. Choose this environment if you want to combine F# or C# with Q# to create classical host programs that call Q# operations.

Thank you, I was looking for this.

- [Install Q# for Python:](xref:microsoft.quantum.install.python) choose this environment if you want to combine Python and Q# to create a Python host program that calls Q# operations.
- [Install Q# for Jupyter Notebooks:](xref:microsoft.quantum.install.jupyter) choose this environment to execute Q# code in cells with embedded text or create quantum computing interactive tutorials. Do not choose this environment if you want to combine Q# with an external classical host program.
2 changes: 1 addition & 1 deletion articles/install-guide/pyinstall.md
Expand Up @@ -25,7 +25,7 @@ Install the QDK to develop Python host programs to call Q# operations.
pip install qsharp
```

1. Install `iqsharp`, a kernel used by Jupyter and Python that provides the core functionality for compiling and executing Q# operations.
1. Install IQ#, a kernel used by Jupyter and Python that provides the core functionality for compiling and executing Q# operations.

```bash
dotnet tool install -g Microsoft.Quantum.IQSharp
Expand Down
82 changes: 82 additions & 0 deletions articles/install-guide/standalone.md
@@ -0,0 +1,82 @@
---
title: Execute Q# programs without a driver and a host language
author: KittyYeungQ
ms.author: kitty
ms.date: 4/24/2020
ms.topic: article
ms.custom: how-to
uid: microsoft.quantum.install.standalone
---

# Q# Command Line Applications

Q# programs can be executed on their own, without a driver in a host language like C#, F#, or Python.

## Pre-requisites

- [.NET Core SDK 3.1 or later](https://www.microsoft.com/net/download)

## Installation

While you can build Q# command line applications in any IDE, we highly recommend using Visual Studio Code (VS Code) or Visual Studio IDE for your Q# applications. By using VS Code or Visual Studio and the QDK Visual Studio Code extension you gain access to richer functionality.

- Install [VS Code](https://code.visualstudio.com/download) (Windows, Linux and Mac)
- Install the [QDK extension for VS Code](https://marketplace.visualstudio.com/items?itemName=quantum.quantum-devkit-vscode)
OR
- [Visual Studio](https://visualstudio.microsoft.com/downloads/) 16.3, with the .NET Core cross-platform development workload enabled
- Download and install the [Visual Studio extension](https://marketplace.visualstudio.com/items?itemName=quantum.DevKit)


## Develop with Q# using VS Code

Install the Quantum project templates:

- Go to **View** -> **Command Palette**
- Select **Q#: Install project templates**

You now have the Quantum Development Kit installed and ready to use in your own applications and libraries.
- Create a new project:
- Go to **View** -> **Command Palette**
- Select **Q#: Create New Project**
- Select **Standalone console application**
- Navigate to the location on the file system where you would like to create the application
- Click on the **Open new project...** button, once the project has been created

- Inspect the project
- You should see that a file called `Program.qs` created, which is a Q# program that defines a simple operation to print a message to the console.

- Run the application:
- Go to **Terminal** -> **New Terminal**
- Enter `dotnet run`
- You should see the following text in the output window `Hello quantum world!`


> [!NOTE]
> * Workspaces with multiple root folders are not currently supported by the Visual Studio Code extension. If you have multiple projects within one VS Code workspace, all projects need to be contained within the same root folder.

## Develop with Q# using Visual Studio

Verify the installation by creating a `Hello World` application

- Create a new Q# application
- Go to **File** -> **New** -> **Project**
- Type `Q#` in the search box
- Select **Q# Application**
- Select **Next**
- Choose a name and location for your application
- Select **Create**

- Inspect the project
- You should see that a file called `Program.qs` has been created, which is a Q# program that defines a simple operation to print a message to the console.

- Run the application
- Select **Debug** -> **Start Without Debugging**
- You should see the text `Hello quantum world!` printed to a console window.

> [!NOTE]
> * If you have multiple projects within one Visual Studio solution, all projects contained in the solution need to be in the same folder as the solution, or in one of its subfolders.


## What's next?

Now that you have installed the Quantum Development Kit in your preferred environment, you can write and run [your first quantum program](xref:microsoft.quantum.write-program).
13 changes: 13 additions & 0 deletions articles/install-guide/toc.yml
@@ -0,0 +1,13 @@
items:
- name: Installation overview
href: index.md
- name: Q# command line applications
href: standalone.md
- name: Q# Jupyter notebooks
href: qjupyter.md
- name: Using Q# with other languages
items:
- name: Using Q# with Python
href: pyinstall.md
- name: Using Q# with .NET
href: csinstall.md