Qiskit aer simulation with torch interface

It appears that when running the following code from “How to simulate noise with PennyLane”:

import qiskit
import qiskit.providers.aer.noise as noise
import pennylane as qml

p = 0.01
my_bitflip = noise.pauli_error([('X', p), ('I', 1 - p)])

my_noise_model = noise.NoiseModel()

my_noise_model.add_quantum_error(my_bitflip, ['h'], [0])

dev4 = qml.device('qiskit.aer', wires=1, noise_model = my_noise_model)

@qml.qnode(dev4)
def bitflip_circuit_aer():
    qml.Hadamard(0)
    return qml.expval(qml.PauliZ(0))

print(bitflip_circuit_aer())

And then changing the 14th line from @qml.qnode(dev4) to @qml.qnode(dev4, interface='torch') I get a SIGSEGV segmentation violation.

Is there a way of running a qiskit noisy device using the torch interface in pennylane?

Hi @tjvarma, welcome to the forum!

I’m running this on Xanadu Cloud and it runs properly. Can you please post the output of qml.about()?

Hi @CatalinaAlbornoz, thank you for getting back to me.

This is the output of qml.about():

Name: PennyLane
Version: 0.25.1
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: anaconda3/envs/qmsc/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning, PennyLane-qiskit

Platform info:           macOS-10.16-x86_64-i386-64bit
Python version:          3.10.4
Numpy version:           1.23.2
Scipy version:           1.9.1
Installed devices:
- default.gaussian (PennyLane-0.25.1)
- default.mixed (PennyLane-0.25.1)
- default.qubit (PennyLane-0.25.1)
- default.qubit.autograd (PennyLane-0.25.1)
- default.qubit.jax (PennyLane-0.25.1)
- default.qubit.tf (PennyLane-0.25.1)
- default.qubit.torch (PennyLane-0.25.1)
- default.qutrit (PennyLane-0.25.1)
- lightning.qubit (PennyLane-Lightning-0.25.1)
- qiskit.aer (PennyLane-qiskit-0.24.0)
- qiskit.basicaer (PennyLane-qiskit-0.24.0)
- qiskit.ibmq (PennyLane-qiskit-0.24.0)
- qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.24.0)
- qiskit.ibmq.sampler (PennyLane-qiskit-0.24.0)
None

Maybe for additional context, I’m running this on a conda virtual environment with only: “torch”, “pennylane”, “qiskit”, and “pennylane-qiskit” installed and I’m getting the following error:

OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized.
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Thank you in advance for your help

Hi @tjvarma, I’m still unable to reproduce your problem. I have found this GitHub issue from another repo, where other people have posted some possible solutions. Please let me know if one of the solutions there works for you.