# Building larger quantum circuits

**URL:** <https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310>\
**Category:** PennyLane Help\
**Created:** [January 12, 2020, 4:34pm UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310 "2020-01-12T16:34:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vijpandaturtle](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vijpandaturtle/32/156_2.png) [@vijpandaturtle](https://discuss.pennylane.ai/u/vijpandaturtle)\
**Post date:** [January 12, 2020, 4:34pm UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/1 "2020-01-12T16:34:30Z")

</div>

Hi,  
I am currently researching on the topic of image processing in quantum computers. I recently did a project using pennylane (variational classifier) to classify biomedical images. However, I worked only with 2 and 4 qubit circuits and am wanting to try with a larger number of qubits. I am having some trouble understanding how I can go about designing a circuit of this size. Can I please get some help ?  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![kareem\_essafty](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kareem_essafty/32/401_2.png) [@kareem\_essafty](https://discuss.pennylane.ai/u/kareem_essafty)\
**Post date:** [January 12, 2020, 9:22pm UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/2 "2020-01-12T21:22:35Z")

</div>

hey,  
machine learning either classical or quantum depends significantly on your data preparation and how you configure your cost function. because of the gpus and their incredible speed less attention is given to these two points and this is actually what happens here in the quantum realm. by far, the amplitude encoding scheme can encode a single 28\*28 image with only 10 qubits and there would be more room for other features and you can you the circuit centric classifier by prof schuld for your problem.  
another way is to use the universal qubit classifier but it would be the deepest network ever. Or, you can try out this [paper](https://arxiv.org/pdf/1810.03787.pdf).  
if you are more precise i think i can help you more 😅  
good luck

---

<div class="post-metadata">

**Author:** ![vijpandaturtle](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vijpandaturtle/32/156_2.png) [@vijpandaturtle](https://discuss.pennylane.ai/u/vijpandaturtle)\
**Post date:** [January 13, 2020, 12:59pm UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/4 "2020-01-13T12:59:42Z")

</div>

I figured it out. Thank you for your reply 😄

---

<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:** [January 13, 2020, 2:28pm UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/5 "2020-01-13T14:28:01Z")

</div>

Hi @vijpandaturtle! To help create your variational circuit ansatz for a larger number of qubits, you could take a look at the templates provided by PennyLane: [Templates — PennyLane 0.27.0 documentation](https://pennylane.readthedocs.io/en/stable/introduction/templates.html)

One that is quite useful is the [`StronglyEntanglingLayers`](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.templates.layers.StronglyEntanglingLayers.html). This template creates layers like the following:

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

For example, for a 10 qubit circuit, with 3 strongly entangling layers:

```python
import pennylane as qml
from pennylane.templates.layers import StronglyEntanglingLayers

dev = qml.device('default.qubit', wires=10)

@qml.qnode(dev)
def circuit(weights):
    StronglyEntanglingLayers(weights, wires=list(range(10)))
    return qml.expval(qml.PauliZ(0))

init_weights = strong_ent_layers_normal(n_layers=3, n_wires=10)
circuit(init_weights)

```

---

<div class="post-metadata">

**Author:** ![vijpandaturtle](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vijpandaturtle/32/156_2.png) [@vijpandaturtle](https://discuss.pennylane.ai/u/vijpandaturtle)\
**Post date:** [January 14, 2020, 7:28am UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/6 "2020-01-14T07:28:57Z")

</div>

Thank you so much @josh !

---

<div class="post-metadata">

**Author:** ![vijpandaturtle](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vijpandaturtle/32/156_2.png) [@vijpandaturtle](https://discuss.pennylane.ai/u/vijpandaturtle)\
**Post date:** [January 26, 2020, 3:52am UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/7 "2020-01-26T03:52:55Z")

</div>

@josh trying to build this circuit

```python
@qml.qnode(dev)
def circuit(inputs, weights):
    AngleEmbedding(inputs, list(range(9)))
    RandomLayers(weights=weights, wires=list(range(9)))
    return qml.expval(qml.PauliZ(0))

init_pars = random_layers_uniform(n_layers=3, n_wires=num_qubits, seed=2)

```

however when i run this command to test  
print(circuit([1,2,3,4,5,6,7,8,9], init\_pars))

i get the following error  
“TypeError: RX: Real scalar parameter expected, got \<class ‘numpy.ndarray’\>.”

what am i doing wrong ?

---

<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:** [January 27, 2020, 3:00am UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/8 "2020-01-27T03:00:10Z")

</div>

Hi @vijpandaturtle, the example you posted works for me. I use the following QNode:

```python
import pennylane as qml

num_qubits = 9
dev = qml.device("default.qubit", wires=num_qubits )

@qml.qnode(dev)
def circuit(inputs, weights):
    qml.templates.AngleEmbedding(inputs, list(range(9)))
    qml.templatesRandomLayers(weights=weights, wires=list(range(9)))
    return qml.expval(qml.PauliZ(0))

init_pars = random_layers_uniform(n_layers=3, n_wires=num_qubits, seed=2)

```

Running this circuit,

```python
>>> print(circuit([1,2,3,4,5,6,7,8,9], init_pars))
0.54030230586814

```

Can you post the output of `qml.about()`?

---

<div class="post-metadata">

**Author:** ![vijpandaturtle](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/vijpandaturtle/32/156_2.png) [@vijpandaturtle](https://discuss.pennylane.ai/u/vijpandaturtle)\
**Post date:** [January 27, 2020, 3:45am UTC](https://discuss.pennylane.ai/t/building-larger-quantum-circuits/310/9 "2020-01-27T03:45:21Z")

</div>

@josh I ran qml.about() and realized that i have pennylane 0.5.0 installed. simply running an upgrade fixed my issue. thanks for pointing me in the right direction !
