№ 1824Квантовые вычисленияУровень 3

Поэкспериментировать с двухкубитными фазовыми оракулами

В полном исходном примере подготовлены два кубита: первый в состоянии $0.5|0\rangle+\sqrt{0.75}|1\rangle$, второй — $0.6|0\rangle+0.8|1\rangle$. Затем применяется PhaseOracle_Xmod2.

Автор предлагает использовать другие оракулы из примера и посмотреть, как они действуют. Поэкспериментируйте с PhaseOracle_Zero, PhaseOracle_One и PhaseOracle_Xmod2. Полный исходный код дан ниже. Общая фаза −1 может не отображаться в симуляторе.

Заготовка Q#:

namespace Kata {
    import Std.Diagnostics.*;
    import Std.Math.*;

    operation PhaseOracle_Zero(x : Qubit[]) : Unit {
        // Do nothing...
    }

    operation PhaseOracle_One(x : Qubit[]) : Unit {
        // Apply a global phase of -1
        R(PauliI, 2.0 * PI(), x[0]);
    }

    operation PhaseOracle_Xmod2(x : Qubit[]) : Unit {
        let N = Length(x);
        // Array elements are indexed 0 through Length(x) - 1, inclusive.
        Z(x[N - 1]);
    }

    @EntryPoint()
    operation OracleImplementationDemo() : Unit {
        use qs = Qubit[2];
        Ry(2.0 * ArcCos(0.5), qs[0]);
        Ry(2.0 * ArcCos(0.6), qs[1]);
        Message("The state before oracle application:");
        DumpMachine();

        // Apply the oracle.
        // Experiment with using other oracles to see their behavior!
        // (Note that the -1 global phase might not show up in simulation)
        PhaseOracle_Xmod2(qs);

        Message("The state after oracle application:");
        DumpMachine();

        ResetAll(qs);
    }
}