Quantum: State Testing

 

Operation StateTest  takes parameters count and initial. The operation returns two values as a tuple of integer types. The operation loops the count number of times and measures one and zero states. The measurement occurs after invoking the set operation and Not Gate on Qubit. The code below shows the number of times zero and one values come in the run of 1000 times is printed.

using System;

using Microsoft.Quantum.Simulation.Core;

using Microsoft.Quantum.Simulation.Simulators;

namespace QuantumState

{

    class Driver

    {

        static void Main(string[] args)

        {

            using (var qsim = new QuantumSimulator())

            {

                

                Result[] initials = new Result[] { Result.Zero, Result.One };

                foreach (Result initial in initials)

                {

                    var res = StateTest.Run(qsim, 1000, initial).Result;

                    var (numZeros, numOnes) = res;

                    System.Console.WriteLine(

                        $”Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4}”);

                }

            }

        }

    }

}

 

namespace QuantumState

{

    open Microsoft.Quantum.Canon;

    open Microsoft.Quantum.Primitive;

operation Set (desired: Result, q1: Qubit) : Unit

    {

        let current = M(q1);

        if (desired != current)

        {

            X(q1);

        }

    }

state testing