# Hybrid quantum-classical model

**URL:** <https://discuss.pennylane.ai/t/hybrid-quantum-classical-model/3482>\
**Category:** PennyLane Help\
**Created:** [September 26, 2023, 1:59am UTC](https://discuss.pennylane.ai/t/hybrid-quantum-classical-model/3482 "2023-09-26T01:59:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![junggu.choi](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/junggu.choi/32/1479_2.png) [@junggu.choi](https://discuss.pennylane.ai/u/junggu.choi)\
**Post date:** [September 26, 2023, 1:59am UTC](https://discuss.pennylane.ai/t/hybrid-quantum-classical-model/3482/1 "2023-09-26T01:59:56Z")

</div>

Hi, I have been tring to make hybrid quantum-classical model.

I have two questions about that.

1. classical layer between quantum layers  
: First, I attempted hybrid layer codes as follows.

dev = qml.device(‘default.qubit’, wires = 8)  
@qml.qnode(dev)  
def QCNN (…):  
embedding.data\_embedding(X, embedding\_type=embedding\_type) ## embedding 256 classical data to amplitude of 8 qubits  
QCNN\_structure1(unitary.U\_SU4, params, U\_params)  
torch.nn.Linear(16, 16) ## classical layer 1  
QCNN\_structure2(unitary.U\_SU4, params, U\_params)  
torch.nn.Linear(4, 4) ## classical layer 2  
QCNN\_structure3(unitary.U\_SU4, params, U\_params)  
result = qml.expval(qml.PauliZ(4))  
return result

I checked my hybrid model including above codes runs well without any errors.  
However, I don’t have confidence whether this code can run with my goal.  
(i.e., the output of QCNN structure\_1 pass to classical layer 1 and the output from classical layer 1 to QCNN\_structure 2)  
How can I check this? And is it possible to write code for my goal?

1. quamtum layer between classical layers  
: Like the first question I mentioned above, I considered hybrid model with quantum layer between classical layers. In this case, how can I use quantum layer without measurement between classical layers?  
For example, (this is pseudo code)

classical\_layer1 (torch.nn.Linear(256, 256))  
quantum\_layer1 (amplitude embedding with 8 qubits and without measurement)  
classical\_layer2 (torch.nn.Linear(64, 64)

Is it possible to use intermediate data from quantum circuit without measurement step as a input data for classical layer?

Thank you in advance! 🙂

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 26, 2023, 11:10pm UTC](https://discuss.pennylane.ai/t/hybrid-quantum-classical-model/3482/2 "2023-09-26T23:10:39Z")

</div>

Hi @junggu.choi, thank you for your question. Unfortunately you always need to perform a measurement at the end of your quantum circuit. Moreover, your second classical layer will need classical inputs, which are the measurements from your quantum layer. This demo on [turning quantum nodes into Torch Layers](https://pennylane.ai/qml/demos/tutorial_qnn_module_torch) can be very helpful for you.

I also encourage you to go through the introduction module in the [Xanadu Quantum Codebook](https://codebook.xanadu.ai/), it can help you learn why measurement is important.

I hope this helps!
