microsoft / qsharp-runtime

Runtime components for Q#
https://docs.microsoft.com/quantum
MIT License
285 stars 93 forks source link

Use accelerated SWAP kernel to implement Intrinsic.SWAP. #44

Open cgranade opened 5 years ago

cgranade commented 5 years ago

Please describe what you would like the feature to accomplish. Currently, the Microsoft.Quantum.Intrinsic.SWAP operation is provided along with a pure-Q# implementation in terms of three CNOT calls:

    operation SWAP (qubit1 : Qubit, qubit2 : Qubit) : Unit
    is Adj + Ctl {
        body (...)
        {
            CNOT(qubit1, qubit2);
            CNOT(qubit2, qubit1);
            CNOT(qubit1, qubit2);
        }

        adjoint self;
    }

The C++ runtime for the QuantumSimulator target machine supports, however, an accelerated kernel for applying SWAP gates. It would help with simulator performance to expose this as an implementation of the SWAP intrinsic operation, similarly to how X is exposed by QuantumSimulator.

cgranade commented 5 years ago

After discussing with @anpaz-msft, I think there's two distinct steps that would be needed here:

swernli commented 3 years ago

With the addition of support for target packages, we now have an internal ApplyUncontrolledSWAP intrinsic (see https://github.com/microsoft/qsharp-runtime/blob/main/src/Simulation/TargetDefinitions/Intrinsic/ApplyUncontrolledSWAP.qs). That might be a good place to plug into the simulator SWAP and then use the decomposition over the uncontrolled SWAP.