演習 - Copilot を使用して量子プログラムを実行する

完了

Azure Quantum で Copilot を調べてコーディングを始めるには、[Quantum Samples] (Quantum のサンプル) ドロップダウンのいずれかのサンプルを使います。

量子プログラムを実行する

  1. Azure Quantum でのコードに関するページに移動します。

  2. [Quantum Samples] (Quantum のサンプル) を選んで、Random Number Generator を選びます。 次のコードがコード ウィンドウにコピーされます。

    /// # Sample
    /// Quantum Random Number Generator
    ///
    /// # Description
    /// This program implements a quantum ranndom number generator by setting qubits
    /// in superposition and then using the measurement results as random bits.
    namespace Sample {
        open Microsoft.Quantum.Measurement;
        open Microsoft.Quantum.Intrinsic;
    
        @EntryPoint()
        operation Main() : Result[] {
            // Generate 5-bit random number.
            let nBits = 5;
            return GenerateNRandomBits(nBits);
        }
    
        /// # Summary
        /// Generates N random bits.
        operation GenerateNRandomBits(nBits : Int) : Result[] {
            // Allocate N qubits.
            use register = Qubit[nBits];
    
            // Set the qubits into superposition of 0 and 1 using the Hadamard
            // operation `H`.
            for qubit in register {
                H(qubit);
            }
    
            // At this point each has 50% chance of being measured in the |0〉 state
            // and 50% chance of being measured in the |1〉 state.
            // Measure each qubit and reset them all so they can be safely
            // deallocated.
            let results = MeasureEachZ(register);
            ResetAll(register);
            return results;
        }
    }
    
  3. [In-Memory Simulator] (メモリ内シミュレーター) を選びます。

  4. [実行] を選択します。

    • 結果が [Results] (結果) フィールドに表示され、結果のヒストグラムがコード ウィンドウの下に表示されます。
    • [Select number of shots] (ショットの数を選択する) スライダーを動かして、プログラムの実行回数を指定できます。
    • [Shots] (ショット) フィールドに、各ショットの結果が表示されます。

別のシミュレーターを使ってプログラムをもう一度実行するには:

  1. [In-Memory Simulator] (メモリ内シミュレーター) ドロップダウンを選んで、Quantinuum H-Series Emulator を選びます。

  2. ショットの数を選んで (現在は 20 回に制限されています)、[Run] (実行) を選びます。

    • ジョブの状態が、コード ウィンドウの上部に表示されます。
    • 結果のヒストグラムが、コード ウィンドウの下に表示されます。 現在、Quantinuum H-Series Emulator では、ショットごとの結果は使用できません。

Copilot に質問する

量子に関連するほぼすべてのことについてのプロンプトを、Azure Quantum の Copilot に指定できます。 たとえば、Copilot に次の質問をして、どのようになるか確認してください。

  • "Explain the MResetZ operation" (MResetZ 演算について説明してください)
  • "Write Q# code that entangles two qubits" (2 量子ビットをもつれさせる Q# コードを記述してください)
  • "Explain quantum interference" (量子干渉について説明してください)
  • "What is the difference between a qubit and a classical bit?" (量子ビットと古典ビットの違いは何ですか?)