コード例 #1
0
        static public void TestMethod3()
        {
            var list = new List <Matrix>();

            Complex[,] array1 = { { 0.5, 0.5 },
                                  { 0.5, 0.5 } };
            var value = (Matrix)Matrix.Build.DenseOfArray(array1);

            list.Add(value);
            Complex[,] array2 = { {  0.5, -0.5 },
                                  { -0.5,  0.5 } };
            value = (Matrix)Matrix.Build.DenseOfArray(array2);
            list.Add(value);
            var measureMatrix2 = new MeasureMatrix2(list.ToArray());

            Complex[,] array3 = { { 1 / Sqrt(2),  1 / Sqrt(2) },
                                  { 1 / Sqrt(2), -1 / Sqrt(2) } };
            var unitaryTransMatrix = (Matrix)Matrix.Build.DenseOfArray(array3);

            for (;;)
            {
                var ret = new int[2];
                for (var i = 0; i < 100; i++)
                {
                    var qBit = new QBit(false);
                    qBit.UnitaryTrans2(unitaryTransMatrix);
                    ret[qBit.Measu2ResultIndex(measureMatrix2)]++;
                }
                for (var i = 0; i < ret.Length; i++)
                {
                    Console.WriteLine($"{i} is {ret[i]}");
                }
            }
        }
コード例 #2
0
ファイル: TestCWhile.cs プロジェクト: phaldon/QSI
        static public void TestMethod()
        {
            Console.WriteLine("QBit value");
            Console.WriteLine(new QBit(false).Value.ToComplexString());
            var matrixArray = new Matrix[2];

            Complex[,] array0 = { { 0.5, 0.5 },
                                  { 0.5, 0.5 } };
            matrixArray[0]    = (Matrix)Matrix.Build.DenseOfArray(array0);
            Complex[,] array1 = { {  0.5, -0.5 },
                                  { -0.5,  0.5 } };
            matrixArray[1] = (Matrix)Matrix.Build.DenseOfArray(array1);
            var measureMatrix2 = new MeasureMatrix2(matrixArray);

            Console.WriteLine("Measurement matrix 0");
            Console.WriteLine(measureMatrix2.Value[0].ToComplexString());
            Console.WriteLine("Measurement matrix 1");
            Console.WriteLine(measureMatrix2.Value[1].ToComplexString());
            int count;
            var countNumber = new SortedDictionary <int, int>();

            // var qbit = new QBit(false);
            for (var i = 0; i < 1000; i++)
            {
                var qbit = new QBit(false);
                count = 0;


                qwhile(qbit, measureMatrix2, 1,
                       () =>
                {
                    qbit.UnitaryTrans2(HGate.Value);
                    count++;
                    if (count > 1000)
                    {
                        return(CWHILEFLOW.BREAK);
                    }
                    return(CWHILEFLOW.CONTINUE);
                }
                       );
                if (countNumber.ContainsKey(count))
                {
                    countNumber[count]++;
                }
                else
                {
                    countNumber[count] = 1;
                }
            }

            foreach (var pair in countNumber)
            {
                Console.WriteLine($"{pair.Key} is {pair.Value}");
            }
        }
コード例 #3
0
ファイル: TestCIf.cs プロジェクト: phaldon/QSI
        static public void TestMethod()
        {
            var qbit = new QBit(false);

            Console.WriteLine("QBit value");
            Console.WriteLine(qbit.Value.ToComplexString());
            var matrixArray = new Matrix[2];

            Complex[,] array0 = { { 0.5, 0.5 },
                                  { 0.5, 0.5 } };
            matrixArray[0]    = (Matrix)Matrix.Build.DenseOfArray(array0);
            Complex[,] array1 = { {  0.5, -0.5 },
                                  { -0.5,  0.5 } };
            matrixArray[1] = (Matrix)Matrix.Build.DenseOfArray(array1);
            var measureMatrix2 = new MeasureMatrix2(matrixArray);

            Console.WriteLine("Measurement matrix 0");
            Console.WriteLine(measureMatrix2.Value[0].ToComplexString());
            Console.WriteLine("Measurement matrix 1");
            Console.WriteLine(measureMatrix2.Value[1].ToComplexString());
            int count_0 = 0, count_1 = 0;

            for (var i = 0; i < 1000; i++)
            {
                qif(qbit, measureMatrix2,
                    () =>
                {
                    count_0++;
                },
                    () =>
                {
                    count_1++;
                }
                    );
                qbit.UnitaryTrans2(HGate.Value);
            }
            Console.WriteLine($"count_0 = {count_0}");
            Console.WriteLine($"count_1 = {count_1}");
        }
コード例 #4
0
ファイル: TestMeasureMatrix2.cs プロジェクト: phaldon/QSI
        static public void TestMethod2()
        {
            var list = new List <Matrix>();

            Complex[,] array1 = { { 0.5, 0.5 },
                                  { 0.5,   1 } };
            var value = (Matrix)Matrix.Build.DenseOfArray(array1);

            Console.WriteLine(value.ToComplexString());
            list.Add(value);
            Complex[,] array2 = { {  0.5, -0.5 },
                                  { -0.5,  0.5 } };
            value = (Matrix)Matrix.Build.DenseOfArray(array2);
            Console.WriteLine(value.ToComplexString());
            list.Add(value);
            Console.WriteLine("MeasureMatrix2");
            var measureMatrix2 = new MeasureMatrix2(list.ToArray());

            foreach (var matrix in measureMatrix2.Value)
            {
                Console.WriteLine(matrix.ToComplexString());
            }
        }