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.27k stars 585 forks source link

Make Clifford plus T decomposition output shorter circuits #6131

Open cvjjm opened 3 weeks ago

cvjjm commented 3 weeks ago

Feature details

It is very cool that PL ships a Clifford plus T decomposition transform!

However it does seem to struggle in certain cases. An extreme example is:

print(qml.draw(qml.transforms.clifford_t_decomposition(qml.adjoint(qml.S)))(0))

which produces the gate sequence:

0: ──H──T──H──T†──T†──T†──H──T──H──T──T──H──T†──H──T──H──T──H──T†──T†──T†──T†──H──T──H──T──T──T──H

───T†──H──T†──H──T──H──T†──T†──H──T†──H──T──T──GlobalPhase(0.79)─┤  <Z>

Clearly this is not optimal :-)

Implementation

No response

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

josh146 commented 3 weeks ago

Thanks @cvjjm! from chatting to the team, this seems to come from the adjoint modifier; exchanging the decomposition and the qml.adjoint resolves the problem (compiling to S^\dagger). I wonder if the ability to smartly swap transforms that are associative might help here 🤔

Some other thoughts:

josh146 commented 3 weeks ago

We're curious if you've encountered any other cases where the clifford decomposition struggles?

cvjjm commented 3 weeks ago

I noticed that I got very deep circuits for a circuit that should have been Clifford in the first place. I wanted to use clifford_t_decomposition to verify that and got very long circuits with T gates. I then tried simpler and simpler circuits until I arrived at the minimal example above.

Another good example that should not need T gates but produces loads is:

>>>print(qml.draw(qml.transforms.clifford_t_decomposition(qml.adjoint(qml.IsingXX)))(np.pi/2, [0, 1]))
0: ─╭●──T──H──T†──T†──T†──H──T──H──T──T──H──T†──H──T──H──T──H──T†──T†──T†──T†──H──T──H──T──T──T──H
1: ─╰X────────────────────────────────────────────────────────────────────────────────────────────

───T†──H──T†──H──T──H──T†──T†──H──T†──H──T──T──H─╭●─┤
─────────────────────────────────────────────────╰X─┤
isaacdevlugt commented 2 weeks ago

@cvjjm thanks for reporting this! We'll leave the issue open for now and investigate a fix for this. We will update here if there is any movement.