# Quantum transfer learning code (Mari et al., 2019) - IBMQDevice endless execution

**URL:** https://discuss.pennylane.ai/t/quantum-transfer-learning-code-mari-et-al-2019-ibmqdevice-endless-execution/325
**Category:** PennyLane Qiskit
**Created:** [January 27, 2020, 9:13am UTC](https://discuss.pennylane.ai/t/quantum-transfer-learning-code-mari-et-al-2019-ibmqdevice-endless-execution/325 "2020-01-27T09:13:31Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![Tom\_Bromley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tom_bromley/32/129_2.png) [@Tom\_Bromley](https://discuss.pennylane.ai/u/Tom_Bromley)
#### Post date: [October 26, 2020, 3:42pm UTC](https://discuss.pennylane.ai/t/quantum-transfer-learning-code-mari-et-al-2019-ibmqdevice-endless-execution/325/13 "2020-10-26T15:42:05Z")

</div>

Hi @Jerry2001Qu, and thanks @angelinaG for your answer!

We recently introduced a new attribute to the device: `dev.num_executions`, which makes it easy to track the number of device executions. You could do this on simulator before trying to run on hardware. This feature can be accessed by [installing](https://pennylane.ai/install.html?version=preview) the development version of PennyLane.

For example, the following shows a benchmark of the number of device executions on a 4-qubit, 6-layer circuit:

```python
import pennylane as qml
import torch

nqubits = 4
nlayers = 6
dev = qml.device("default.qubit", wires=nqubits)

@qml.qnode(dev, interface="torch")
def qcircuit(inputs, weights):
    for i in range(nqubits):
        qml.Hadamard(wires=i)
        qml.RY(inputs[i], wires=i)
    qml.templates.BasicEntanglerLayers(weights, wires=range(nqubits))
    return [qml.expval(qml.PauliZ(i)) for i in range(nqubits)]

weight_shapes = {"weights": (nlayers, nqubits)}
inputs = torch.ones(nqubits, requires_grad=True)

qlayer = qml.qnn.TorchLayer(qcircuit, weight_shapes)

out = torch.sum(qlayer(inputs))
out.backward()

print(f"Number of executions: {dev.num_executions}")

n_exec_basic = nqubits * nlayers * 2
n_ry = nqubits * 2
n_expected = n_ry + n_exec_basic + 1 # the 1 comes from the forward pass

print(f"Expected number of executions: {dev.num_executions}")

```

The result is 57 device executions. We can also look at the dressed quantum circuit:

```python
clayer1 = torch.nn.Linear(512, 4)
clayer2 = torch.nn.Linear(4, 2)

hybrid = torch.nn.Sequential(clayer1, qlayer, clayer2)
inputs = torch.ones(512, requires_grad=True)

dev._num_executions = 0

out = torch.sum(qlayer(inputs))
out.backward()

print(f"Number of executions: {dev.num_executions}")

```

This also gives 57 executions, so it doesn’t look like the hybrid element is increasing things (as expected).

In terms or training on IBMQ, we had a discussion on improving performance on another [thread](http://discuss.pennylane.ai/t/tips-on-how-to-improve-performance-on-ibm-hardware/515). I would say that this is quite a heavy task for optimization on hardware right now. One thing you could consider is training on simulator and testing (i.e., forward passes, which are much cheaper) on hardware.

---

_[View the full topic](https://discuss.pennylane.ai/t/quantum-transfer-learning-code-mari-et-al-2019-ibmqdevice-endless-execution/325)._
