PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.17k stars 568 forks source link

Optimize PhaseShift, T, S gates #5876

Open vincentmr opened 1 week ago

vincentmr commented 1 week ago

Before submitting

Please complete the following checklist when submitting a PR:

When all the above are checked, delete everything above the dashed line and fill in the pull request template.


Context: PauliZ has a fast implementation which relies on the sparsity of the operator in DefaultQubit. Several operations have the same non-zero matrix elements and could be similarly accelerated. One candidate is PhaseShift which is abundantly used in iterative_qpe.

Description of the Change: Port the fast-PauliZ to PhaseShift and use the implementation for PauliZ, S and T.

Benefits: Faster execution. For example the simple system

nwires = 24
dev = qml.device("default.qubit", shots=1)
@qml.qnode(dev)
def circuit(iters):
    for i in range(iters):
        qml.PhaseShift(0.1234, i % nwires)
    return qml.sample(wires=[0])
circuit(100)

takes 0m13.178s on master and 0m9.146s on optim_apply_operations. We observe the same speed-up for S and T.

Possible Drawbacks:

Related GitHub Issues:

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.66%. Comparing base (442cbab) to head (60ac35b).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5876 +/- ## ========================================== - Coverage 99.67% 99.66% -0.01% ========================================== Files 425 425 Lines 40753 40489 -264 ========================================== - Hits 40620 40355 -265 - Misses 133 134 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.