Hello, I am experimenting with Pennylane-Qiskit plugin and tried to run a simple quantum circuit on ibmq_qasm_simulator. Following is the code I used.
import pennylane as qml
from pennylane import numpy as np
import time as time
import torch
import torch.nn as nn
dev = qml.device("default.qubit", wires=1)
@qml.qnode(dev, interface = 'torch')
def simple_qubit_circuit(theta, inputs):
qml.RX(inputs, wires=0)
qml.RY(theta, wires=0)
return qml.expval(qml.PauliZ(0))
class QNet(nn.Module):
def __init__(self):
super().__init__()
shapes = {
"theta": (1,)
}
self.q = qml.qnn.TorchLayer(simple_qubit_circuit, shapes)
def forward(self, input_value):
return self.q(input_value)
x_train = np.array([0.2, 0.1, 0.2, 0.14, 0.11, 0.41, 0.55, 0.3, 0.31, 0.6])
x_train = torch.tensor(x_train).reshape(10,1)
model = QNet()
t1 = time.time()
out = model(x_train)
print("time taken for batch operations: {} seconds".format(time.time()-t1))
I created a random tensor of size 10 and passed it as an input to the quantum model. I understand that the all the samples in the batch were executed sequentially as total 10 jobs were created. However, what surprised me is the time taken to complete the execution of each job. Following is the output I got.
time taken for batch operations: 59.5023033618927 seconds
As there are total 10 samples in the batch, time taken/job is around about 6 seconds. However, when I checked the details of the job submitted to ’ ibmq_qasm_simulator’, the ‘Total completion time’ is 230 ms/job on an average which is way less compared to actual time taken. I am not sure if I am doing something wrong or this behavior is normal.
Output of qml.about()
.
qml.about()
Name: PennyLane
Version: 0.28.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: c:\users\aksi01\miniconda3\envs\qns\lib\site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-qiskit
Platform info: Windows-10-10.0.19045-SP0
Python version: 3.8.15
Numpy version: 1.22.3
Scipy version: 1.7.3
Installed devices:
- default.gaussian (PennyLane-0.28.0)
- default.mixed (PennyLane-0.28.0)
- default.qubit (PennyLane-0.28.0)
- default.qubit.autograd (PennyLane-0.28.0)
- default.qubit.jax (PennyLane-0.28.0)
- default.qubit.tf (PennyLane-0.28.0)
- default.qubit.torch (PennyLane-0.28.0)
- default.qutrit (PennyLane-0.28.0)
- null.qubit (PennyLane-0.28.0)
- lightning.qubit (PennyLane-Lightning-0.28.1)
- qiskit.aer (PennyLane-qiskit-0.29.0)
- qiskit.basicaer (PennyLane-qiskit-0.29.0)
- qiskit.ibmq (PennyLane-qiskit-0.29.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.29.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.29.0)