Skip to content

DeadmanXXXII/QDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

QDK

Microsoft quantum CLI This is a comprehensive and detailed list of commands and techniques for using the Microsoft Quantum Development Kit (QDK) CLI.

1. QDK Installation

Ensure you have the QDK installed. You can install the QDK using the .NET Core SDK.

dotnet new -i Microsoft.Quantum.ProjectTemplates

2. Creating a New Quantum Project

Create a new Q# project using the QDK templates.

dotnet new console -n QuantumProject
cd QuantumProject

3. Building and Running Quantum Programs

  • Build the project:

    dotnet build
  • Run the project:

    dotnet run

4. Quantum Operations and Algorithms

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);
    }
}

5. Running Q# Operations from C#

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);
            }
        }
    }
}

6. Advanced Techniques and Execution Options

  • 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());
    }

7. Quantum Machine Execution

  • Azure Quantum Execution:
    az quantum execute --target-id MyQuantumTarget --job-name MyJob --input-file input.json

8. Managing and Listing Quantum Targets

  • List available targets:

    az quantum target list
  • Set default quantum workspace:

    az quantum workspace set --resource-group MyResourceGroup --name MyWorkspace

9. Optimizations and Transformations

  • Optimizing quantum circuits:
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;
    
    operation OptimizeCircuit() : Unit {
        // Define your quantum circuit here
        // Use optimization techniques
    }

10. Working with Q# Files and Projects

  • 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

11. Using QDK from Jupyter Notebooks

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!");
    }

12. Miscellaneous Commands

  • Setting parameters in a Q# operation:

    operation RotateQubit(angle : Double, qubit : Qubit) : Unit {
        Rx(angle, qubit);
    }
  • Compiling a quantum program:

    dotnet build

13. Integrating with Visual Studio and Visual Studio Code

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

Conclusion

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.

About

Microsoft quantum CLI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published