Microsoft quantum CLI This is a comprehensive and detailed list of commands and techniques for using the Microsoft Quantum Development Kit (QDK) CLI.
Ensure you have the QDK installed. You can install the QDK using the .NET Core SDK.
dotnet new -i Microsoft.Quantum.ProjectTemplatesCreate a new Q# project using the QDK templates.
dotnet new console -n QuantumProject
cd QuantumProject-
Build the project:
dotnet build
-
Run the project:
dotnet run
Create a Q# file (Operation.qs) and define quantum operations:
namespace Quantum.QuantumProject {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
operation HelloQ() : Unit {
Message("Hello, Quantum World!");
}
operation ApplyHadamard(qubit : Qubit) : Unit {
H(qubit);
}
}Create a C# host program (Host.cs) to run Q# operations:
using System;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace Quantum.QuantumProject {
class Program {
static void Main(string[] args) {
using (var sim = new QuantumSimulator()) {
HelloQ.Run(sim).Wait();
var qubit = sim.AllocateQubit();
ApplyHadamard.Run(sim, qubit).Wait();
sim.Release(qubit);
}
}
}
}-
Simulating quantum operations:
using (var sim = new QuantumSimulator()) { var result = ApplyHadamard.Run(sim, qubit).Result; Console.WriteLine($"Result: {result}"); }
-
Using the ResourcesEstimator:
using (var estimator = new ResourcesEstimator()) { HelloQ.Run(estimator).Wait(); Console.WriteLine(estimator.ToTSV()); }
- Azure Quantum Execution:
az quantum execute --target-id MyQuantumTarget --job-name MyJob --input-file input.json
-
List available targets:
az quantum target list
-
Set default quantum workspace:
az quantum workspace set --resource-group MyResourceGroup --name MyWorkspace
- Optimizing quantum circuits:
open Microsoft.Quantum.Canon; open Microsoft.Quantum.Intrinsic; operation OptimizeCircuit() : Unit { // Define your quantum circuit here // Use optimization techniques }
-
Export circuit to Q# file:
// Save your Q# code in a file (e.g., Circuit.qs) -
Import circuit from Q# file:
// Include the Q# file in your project
You can run Q# code in Jupyter Notebooks using the IQ# kernel.
-
Install Jupyter Notebook and IQ#:
dotnet tool install -g Microsoft.Quantum.IQSharp dotnet iqsharp install
-
Start Jupyter Notebook:
jupyter notebook
-
Run Q# in a notebook cell:
open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon; operation HelloQuantum() : Unit { Message("Hello, Quantum World!"); }
-
Setting parameters in a Q# operation:
operation RotateQubit(angle : Double, qubit : Qubit) : Unit { Rx(angle, qubit); }
-
Compiling a quantum program:
dotnet build
-
Install QDK extension for Visual Studio:
# Open Visual Studio, go to Extensions > Manage Extensions # Search for "Microsoft Quantum Development Kit"
-
Install QDK extension for Visual Studio Code:
# Open Visual Studio Code, go to Extensions view # Search for "Microsoft Quantum Development Kit"
This extensive and detailed list of commands and techniques covers a wide range of tasks for working with the Microsoft Quantum Development Kit (QDK). From installation and project creation to advanced execution options, optimizations, and integration with development environments, this guide provides a comprehensive resource for quantum programming with QDK.