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.35k stars 603 forks source link

[unitaryhack] Add the ZZ operation #1148

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 diagonal operation called ZZ, as defined in the PennyLane-Braket plugin.

Steps to take

A. Adding the operation

  1. Adding the ZZ class and its attributes to pennylane/ops/qubit.py. This class would inherit from DiagonalOperation. Complete its docstring in a similar fashion as for other operations. Make sure the class is accessible through qml.ZZ.
  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: ZZ is a special case for PauliRot for the "ZZ" Pauli word. Therefore, the decomposition of ZZ 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 ZZ can be removed from the operations dictionary for default.qubit.autograd and default.qubit.tf.

Miru19 commented 3 years ago

Hello! I would like to solve this issue :) Thank you

antalszava commented 3 years ago

Hi @Miru19, that's great to hear! :) Feel free to start with it and open up a draft PR that's work in progress if you'd like. Don't hesitate to post any questions here.