Beispiel #1
0
        /// <summary>
        /// Apply a permutation defined by a permutation table. This overload
        /// allows for perfomance optimizations like reuse of permutation
        /// tables.
        /// </summary>
        public static void ApplyOracle(QuantumSimulator simulator, Int64[] permutation,
                                       IQArray <Qubit> xbits, IQArray <Qubit> ybits, bool adjoint = false)
        {
            simulator.CheckQubits(xbits, "x");
            simulator.CheckQubits(ybits, "y");
            Debug.Assert(CheckPermutation(permutation));
            var qbits = QArray <Qubit> .Add(xbits, ybits).GetIds();

            if (adjoint)
            {
                AdjPermuteBasisTable(simulator.Id, (uint)qbits.Length, qbits, permutation.LongLength, permutation);
            }
            else
            {
                PermuteBasisTable(simulator.Id, (uint)qbits.Length, qbits, permutation.LongLength, permutation);
            }
        }
Beispiel #2
0
        /// <summary>
        /// The main entry point for emulation of a permutation oracle:
        /// Apply the permutation defined by the oracle function
        ///     f: (x, y) -> (x, f(x, y)).
        /// </summary>
        public static void ApplyOracle(QuantumSimulator simulator, Func <Int64, Int64, Int64, Int64> oracle,
                                       Int64 nLayers, IQArray <Qubit> xbits, Qubit ybit, bool adjoint = false)
        {
            var permutation = BuildPermutationTable(oracle, nLayers, (int)xbits.Length, 1);

            simulator.CheckQubits(xbits, "x");
            simulator.CheckQubit(ybit, "y");
            Debug.Assert(CheckPermutation(permutation));
            IQArray <Qubit> ybits = new QArray <Qubit>(ybit);
            var             qbits = QArray <Qubit> .Add(xbits, ybits).GetIds();

            if (adjoint)
            {
                AdjPermuteBasisTable(simulator.Id, (uint)qbits.Length, qbits, permutation.LongLength, permutation);
            }
            else
            {
                PermuteBasisTable(simulator.Id, (uint)qbits.Length, qbits, permutation.LongLength, permutation);
            }
        }