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] Define decomposition for `qml.CSWAP` #1306

Closed antalszava closed 3 years ago

antalszava commented 3 years ago

This issue has been tagged for contributions during unitaryHACK

Each PennyLane operation defines a decomposition. The decomposition of an operation is an ordered list of other operations. Applying this list of operations evolves quantum states the same way as applying the operation itself does. In most cases, this list includes elementary gates that are often supported by most quantum devices.

We would like to add the decomposition of the qml.CSWAP operation by:

  1. Defining the decomposition method for the qml.CSWAP operation that has the following signature:
    @staticmethod
    def decomposition(wires):

    Other operations in the pennylane/ops/qubit.py file can serve as an example for defining this method (e.g., see qml.Hadamard).

  2. Including a test case for the decomposition of qml.CSWAP in the tests/ops/test_qubit_ops.py file to verify its correctness.
charmerDark commented 3 years ago

Hey! I would like to have a crack at this. Would you have any tips on writing the tests? Thanks for the opportunity!

josh146 commented 3 years ago

Hi @charmerDark - you can have a look at some of the decomposition tests we have in test_qubit_ops.py. Essentially, the idea is to:

  1. Decompose the operation
  2. Multiply together the matrix representations of each operation in the decomposition
  3. Make sure it agrees with the matrix representation of the CSWAP gate
co9olguy commented 3 years ago

Another possible landing spot (and reference) for gate tests:

https://github.com/PennyLaneAI/pennylane/blob/7680a48a8a93c5a2f24acd7204b8de83e41bc02e/tests/test_operation.py#L1034

MaldoAlberto commented 3 years ago

Hi @antalszava I send a Pull requests about this issue, but I forgot to add the Unitaryhack label, is there any problem or should I resend it?

josh146 commented 3 years ago

Hi @MaldoAlberto, I can add the label for you :)