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

[unitaryhack] Add the XX operation #1149

Closed antalszava closed 3 years ago

antalszava commented 3 years ago

This issue has been tagged for contributions during unitaryHACK

Context

We would like to define a new operation called XX, as defined in the PennyLane-Braket plugin.

Steps to take

A. Adding the operation

  1. Adding the XX class and its attributes to pennylane/ops/qubit.py. Complete its docstring in a similar fashion as for other operations. Make sure the class is accessible through qml.XX.
  2. Add its decomposition: a definition for how the operation could be decomposed into elementary operations (see note below),
  3. Add its matrix, eigenvalues, adjoint and generator,
  4. Test: include tests for the operation in the tests/ops/test_qubit_ops.py file,

Note: XX is a special case for PauliRot for the "XX" Pauli word. Therefore, the decomposition of XX can directly depend on using PauliRot, which further decomposes into elementary gates. Inheriting from PauliRot could also be considered.

B. Adding default.qubit support

  1. Add support for the operation in the default.qubit device,
  2. Test: test the operation with default.qubit in the tests/devices/test_default_qubit.py file.

Bonus: Add support to the interface-specific default.qubit devices too: default.qubit.autograd and default.qubit.tf. This will require the operation to be defined in a framework-specific way. These devices inherit the supported operations from default.qubit, so if this step is not tackled, the XX can be removed from the operations dictionary for default.qubit.autograd and default.qubit.tf.

aglitoiu commented 3 years ago

Hello! I would like to solve this issue

antalszava commented 3 years ago

Hi @aglitoiu, that's great to hear, thanks for your interest! :slightly_smiling_face: Feel free to go for it and open a draft PR in the process. We could have a look even during it's being worked on or go for a review whenever ready.

aglitoiu commented 3 years ago

Created the draft PR and made some commits. I would like an advice on where should I search for the decomposition "formulae"

antalszava commented 3 years ago

Sure! For the decomposition there are two possibilities to explore: 1) Either going with the one that's provided in the Braket plugin. The decomposition can be verified by computing using the matrices of CNOT and RX, where is the parameter to RX and the subscripts refer to the qubits the operations act on. 2) Depending on PauliRot by including qml.PauliRot(param, "XX", wires=[wire0, wire1]) where param is the parameter, wire0 and wire1 are the wires provided to qml.XX. In this case PennyLane will further decompose qml.PauliRot if need be.