# Circuit executing with qiskit.aer noise\_model very slow

**URL:** <https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946>\
**Category:** PennyLane Qiskit\
**Created:** [May 18, 2023, 8:37am UTC](https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946 "2023-05-18T08:37:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PoJung-Lu](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/pojung-lu/32/1600_2.png) [@PoJung-Lu](https://discuss.pennylane.ai/u/PoJung-Lu)\
**Post date:** [May 18, 2023, 8:37am UTC](https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946/1 "2023-05-18T08:37:42Z")

</div>

Hello!

I am trying to use quantum circuit to do some classification works (VQC).  
My circuit work pretty well with local simulater cureently. And I think the next step is to test if it is robust to noisy environment.  
I searched some pennylane’s tutorial, and changed my circuit into noisy version.  
Since I would use IBM quantum device to do final teting in the future, I think it is reasonable to plugin their noise during training.  
However I found that if I change my device from “default.qubit” into ‘qiskit.aer’, the traning time increases significantly.  
Here is a reproducable example code:

```auto
import numpy as np
import pennylane as qml
from qiskit_ibm_provider import IBMProvider
from qiskit_aer.noise import NoiseModel
from jax.config import config
import jax
import jax.numpy as jnp
config.update("jax_enable_x64", True)
jax.config.update('jax_platform_name', 'cpu')
n=100
provider = IBMProvider()
backend = 'ibmq_belem'
noise_model = NoiseModel.from_backend(provider.get_backend(backend)) #backend = provider.get_backend(backend)
dev = qml.device('qiskit.aer', wires=2, noise_model=noise_model) 
#dev = qml.device("default.qubit", wires=2)
@qml.qnode(dev, interface="jax")
def circuit(p,x,y):
    qml.RY(p[0]*x, wires=[0])
    qml.RX(p[1]*y, wires=[0])
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(wires=1)),qml.expval(qml.PauliY(wires=1))

params = jnp.array([0.1,0.2])
datax = jnp.array(np.random.randn(2, n))

def loss(p,x):
    rst = circuit(p, x[0], x[1])
    cost=jnp.sum(sum(rst)-1)**2
    return cost

```

And use `%timeit` to see the performance difference:

```auto
%timeit cost, grad = jax.value_and_grad(loss)(params,datax)

```

One may see that the ‘default.qubit’ device is over hundred times faster than 'qiskit.aer’ device. I wonder what cause this difference, they should be having the similar scale of matrix multiplying.  
I have tried to use jax.jit function to speedup training. But this will cause one problem:  
A noisy circuit means there are some noise fluctuating when running, hence every time you run will get different outcome.  
However if I use jit function, either jit the circuit or the grad function, the noise seems to be ‘fixed’. No matter how many times i run, I always get the same results.

Is there any way to speed up the training?  
Any suggestion would be appreciated, thanks!

Here is the package imformation of `qml.about()`:

```auto
Name: PennyLane
Version: 0.30.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: /home/ubuntu2022/anaconda3/envs/research/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-qiskit

Platform info: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python version: 3.10.9
Numpy version: 1.23.5
Scipy version: 1.10.1
Installed devices:
- qiskit.aer (PennyLane-qiskit-0.30.1)
- qiskit.basicaer (PennyLane-qiskit-0.30.1)
- qiskit.ibmq (PennyLane-qiskit-0.30.1)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.30.1)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.30.1)
- lightning.qubit (PennyLane-Lightning-0.30.0)
- default.gaussian (PennyLane-0.30.0)
- default.mixed (PennyLane-0.30.0)
- default.qubit (PennyLane-0.30.0)
- default.qubit.autograd (PennyLane-0.30.0)
- default.qubit.jax (PennyLane-0.30.0)
- default.qubit.tf (PennyLane-0.30.0)
- default.qubit.torch (PennyLane-0.30.0)
- default.qutrit (PennyLane-0.30.0)
- null.qubit (PennyLane-0.30.0)
```

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [May 19, 2023, 1:40pm UTC](https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946/2 "2023-05-19T13:40:18Z")

</div>

Hey @PoJung-Lu! `default.qubit` will definitely be faster here because it’s using `diff_method="backprop"`, whereas `qiskit.aer` is using `diff_method="parameter-shift"`. On top of that, there will be a general slowdown with `qiskit.aer` because of the noise simulation.

---

<div class="post-metadata">

**Author:** ![PoJung-Lu](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/pojung-lu/32/1600_2.png) [@PoJung-Lu](https://discuss.pennylane.ai/u/PoJung-Lu)\
**Post date:** [May 22, 2023, 2:21pm UTC](https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946/3 "2023-05-22T14:21:55Z")

</div>

Hi @isaacdevlugt!  
I see, maybe I can change the ‘diff\_method’ and see what would happen.  
Thank you very much!

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [May 23, 2023, 2:42pm UTC](https://discuss.pennylane.ai/t/circuit-executing-with-qiskit-aer-noise-model-very-slow/2946/4 "2023-05-23T14:42:21Z")

</div>

Just be careful that not all differentiation methods are compatible with all devices! Check out our YouTube video on this: [Differentiation on quantum hardware | PennyLane Tutorial - YouTube](https://www.youtube.com/watch?v=yMXJ0irhPZY&list=PL_hJxz_HrXxsY23iiLZTxiPctXKYI6tNV&index=5&pp=gAQBiAQB)
