# Quantum Convolutional Layer+ Random quantum circuit

**URL:** <https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491>\
**Category:** PennyLane Help\
**Created:** [July 23, 2020, 4:46pm UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491 "2020-07-23T16:46:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZainabAli](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/zainabali/32/307_2.png) [@ZainabAli](https://discuss.pennylane.ai/u/ZainabAli)\
**Post date:** [July 23, 2020, 4:46pm UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/1 "2020-07-23T16:46:47Z")

</div>

Hi @andreamari  
I wanna understand the role of Ry rotation in the quantum circuit as a convolutional operation. Ry rotation applied on data before encoding to quantum data?  
thanks in advance.

![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/5c373be86044001046d945fa74f6af5c07cb5ae5.png)

---

<div class="post-metadata">

**Author:** ![Maria\_Schuld](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maria_schuld/32/166_2.png) [@Maria\_Schuld](https://discuss.pennylane.ai/u/Maria_Schuld)\
**Post date:** [July 24, 2020, 6:58am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/2 "2020-07-24T06:58:49Z")

</div>

Hey ZainabAli,

Could you add where the code is from? I’m just trying to understand in what context you are thinking of convolutions here.

Guessing from the comment in the code, `phi` is a data vector and the `RY` are just encoding the data into a quantum state (see also the [AngleEmbedding](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.templates.embeddings.AngleEmbedding.html) template). Mathematically speaking I don’t see an obvious convolution happening in the embedding. Typically, in convolutional neural net layers one slides a window through the data vector and summarises all entries in this window with some arithmetic operation. Here we just encode each entry into one qubit, which is a rather common approach.

But @andreamari, maybe you have more context?

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [July 24, 2020, 7:02am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/3 "2020-07-24T07:02:25Z")

</div>

(I believe this is from the [Quanvolutional Neural Network](https://pennylane.ai/qml/demos/tutorial_quanvolution.html) demonstration)

---

<div class="post-metadata">

**Author:** ![Maria\_Schuld](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maria_schuld/32/166_2.png) [@Maria\_Schuld](https://discuss.pennylane.ai/u/Maria_Schuld)\
**Post date:** [July 24, 2020, 7:06am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/4 "2020-07-24T07:06:57Z")

</div>

Oh, I just saw!

@ZainabAli, in that case, you’ll find that the convolution is happening through the `quanv()` function defined just after the code you show.

Basically, the function performs the “sliding”, and collects the features (here squares of pixels in an image) into the vector `phi`, which then gets fed to the quantum circuit via the `RY` gates. So the quanvolution is a executed by a combination of classical and quantum computing.

Would that answer your question? @andreamari, feel free to chip in 🙂

---

<div class="post-metadata">

**Author:** ![ZainabAli](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/zainabali/32/307_2.png) [@ZainabAli](https://discuss.pennylane.ai/u/ZainabAli)\
**Post date:** [July 24, 2020, 7:57am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/5 "2020-07-24T07:57:24Z")

</div>

Hi @Maria_Schuld  
Thanks for your reply  
Are rotations gates (Rx, Ry, Rz) used in encoding classical to quantum?  
what is the difference between rotations gates and Quantum embedded methods (e.g Amplitude embedding, Basis embedding [([https://pennylane.ai/qml/glossary/quantum\_embedding.html#quantum-embedding](https://pennylane.ai/qml/glossary/quantum_embedding.html#quantum-embedding)) in the encoding phase?  
the choice encoding method based on the type of data?

---

<div class="post-metadata">

**Author:** ![andreamari](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/andreamari/32/145_2.png) [@andreamari](https://discuss.pennylane.ai/u/andreamari)\
**Post date:** [July 24, 2020, 9:14am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/6 "2020-07-24T09:14:20Z")

</div>

👍 thanks @Maria_Schuld ! All you said is correct, I have nothing to add.

@ZainabAli, _angle embedding_ (e.g. `RY(phi)` on each qubit) is just one of the possible ways of embedding classical data in a quantum system. It is probably the simplest one from an experimental point of view since one only needs a single gate for each parameter.

Other methods such as _amplitude embedding_ can in principle compress more data but are usually more difficult to implement.

In general it is not clear what is the best choice.  
A nice aspect of PennyLane is that you can easily try and switch between different methods by importing the corresponding template from this list ([https://pennylane.readthedocs.io/en/stable/code/qml\_templates.html](https://pennylane.readthedocs.io/en/stable/code/qml_templates.html)).

---

<div class="post-metadata">

**Author:** ![ZainabAli](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/zainabali/32/307_2.png) [@ZainabAli](https://discuss.pennylane.ai/u/ZainabAli)\
**Post date:** [July 24, 2020, 9:23am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/7 "2020-07-24T09:23:01Z")

</div>

@andreamari  
I can use Rx or Rz instead of Ry. I just want to know, How to choose the encoding method according to data(such as images or numerical data).  
thanks

---

<div class="post-metadata">

**Author:** ![andreamari](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/andreamari/32/145_2.png) [@andreamari](https://discuss.pennylane.ai/u/andreamari)\
**Post date:** [July 24, 2020, 11:36am UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/8 "2020-07-24T11:36:13Z")

</div>

Yes, for angle encoding, you can use any rotation.  
I don’t have a simple answer about how to choose the encoding method according to data.

The only suggestion that comes to my mind is that, if you are dealing with images, [this tutorial](https://pennylane.ai/qml/demos/tutorial_quantum_transfer_learning.html) on _quantum transfer learning_ could be a good trick for efficiently pre-processing and encoding features of images on quantum circuits. Similarly, in this [this tutorial](https://pennylane.ai/qml/demos/tutorial_embeddings_metric_learning.html) on _quantum embeddings_ you can find a similar approach.

---

<div class="post-metadata">

**Author:** ![ZainabAli](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/zainabali/32/307_2.png) [@ZainabAli](https://discuss.pennylane.ai/u/ZainabAli)\
**Post date:** [July 24, 2020, 1:09pm UTC](https://discuss.pennylane.ai/t/quantum-convolutional-layer-random-quantum-circuit/491/9 "2020-07-24T13:09:00Z")

</div>

@Maria_Schuld and @andreamari  
I am very grateful for your help.  
many thanks.  
@nathan, thanks a lot for you.
