Esempio n. 1
0
        static async Task Main(string[] args)
        {
            using (var qsim = new QuantumSimulator())
            {   // create each quantum circuit case
                int[,] arr =
                {
                    { 9, 4, 2 },                   //number to factor, no. of bits, random number
                    { 9, 4, 4 },
                    //...list of all possible cases
                };
                int l = arr.GetLength(0);
                // iterate through each cases
                for (int i = 0; i < l; i++)
                {
                    ResourcesEstimator estimator = new ResourcesEstimator();
                    // run the machine class to estimate the resources used
                    await FindOrder.Run(estimator, arr[i, 0], arr[i, 1], arr[i, 2]);

                    // query the data of depth, width, gates count
                    Console.WriteLine(
                        "[" +
                        arr[i, 0] + "," +
                        arr[i, 2] + "," +
                        estimator.Data.Rows.Find("CNOT")["Sum"] + "," +
                        estimator.Data.Rows.Find("QubitClifford")["Sum"] + "," +
                        estimator.Data.Rows.Find("R")["Sum"] + "," +
                        estimator.Data.Rows.Find("Measure")["Sum"] + "," +
                        estimator.Data.Rows.Find("T")["Sum"] + "," +
                        estimator.Data.Rows.Find("Depth")["Sum"] + "," +
                        estimator.Data.Rows.Find("Width")["Sum"] + "," +
                        estimator.Data.Rows.Find("BorrowedWidth")["Sum"] + "],"
                        );
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The quantum estimation calls the quantum algorithm in the Q# file which computes the permutation
        /// πⁱ(input) where i is a superposition of all values from 0 to 7.  The algorithm then uses QFT to
        /// find a period in the resulting state.  The result needs to be post-processed to find the estimate.
        /// <summary>
        private int GuessOrderQuantumOne(int index)
        {
            var result = FindOrder.Run(_sim, new QArray <long>(_p.ConvertAll(x => (long)x)), (long)index).Result;

            if (result == 0)
            {
                var guess = _rnd.NextDouble();
                // the probability distribution is extracted from the second
                // column (m = 0) in Fig. 2's table on the right-hand side,
                // in the original and referenced paper.
                if (guess <= 0.5505)
                {
                    return(1);
                }
                else if (guess <= 0.5505 + 0.1009)
                {
                    return(2);
                }
                else if (guess <= 0.5505 + 0.1009 + 0.1468)
                {
                    return(3);
                }
                else
                {
                    return(4);
                }
            }
            else if (result % 2 == 1)
            {
                return(3);
            }
            else if (result == 2 || result == 6)
            {
                return(4);
            }
            else /* result == 4 */
            {
                return(2);
            }
        }