Ensemble classification with Rigetti and Qiskit devices Error

Hi, I was trying to duplicate the result but, unfortunately, when I loaded the np file downloaded from website, I got a type error. If the provided npy file valid?

If you want help with diagnosing an error, please put the full error message below:

print("Training accuracy (ensemble): {}".format(accuracy(p_train, y_train)))
TypeError: expected Tensor as element 0 in argument 0, but got tuple

Name: PennyLane
Version: 0.34.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
License: Apache License 2.0
Location: /home/martinet/PycharmProjects/Hybrid_QML/.venv/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning, PennyLane-Lightning-GPU, PennyLane-Lightning-Kokkos, PennyLane-qiskit, PennyLane-Rigetti

Platform info: Linux-6.5.0-15-generic-x86_64-with-glibc2.35
Python version: 3.10.12
Numpy version: 1.26.3
Scipy version: 1.12.0
Installed devices:

  • default.gaussian (PennyLane-0.34.0)
  • default.mixed (PennyLane-0.34.0)
  • default.qubit (PennyLane-0.34.0)
  • default.qubit.autograd (PennyLane-0.34.0)
  • default.qubit.jax (PennyLane-0.34.0)
  • default.qubit.legacy (PennyLane-0.34.0)
  • default.qubit.tf (PennyLane-0.34.0)
  • default.qubit.torch (PennyLane-0.34.0)
  • default.qutrit (PennyLane-0.34.0)
  • null.qubit (PennyLane-0.34.0)
  • qiskit.aer (PennyLane-qiskit-0.34.0)
  • qiskit.basicaer (PennyLane-qiskit-0.34.0)
  • qiskit.ibmq (PennyLane-qiskit-0.34.0)
  • qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.34.0)
  • qiskit.ibmq.sampler (PennyLane-qiskit-0.34.0)
  • qiskit.remote (PennyLane-qiskit-0.34.0)
  • lightning.qubit (PennyLane-Lightning-0.34.0)
  • rigetti.numpy_wavefunction (PennyLane-Rigetti-0.34.0)
  • rigetti.qpu (PennyLane-Rigetti-0.34.0)
  • rigetti.qvm (PennyLane-Rigetti-0.34.0)
  • rigetti.wavefunction (PennyLane-Rigetti-0.34.0)
  • lightning.kokkos (PennyLane-Lightning-Kokkos-0.34.0)
  • lightning.gpu (PennyLane-Lightning-GPU-0.34.0)

Hey @Martin_Guo! I’m not sure what code you’re running that gives you this. Can you be more specific?

Hi, like the topic said - ( Ensemble classification with Rigetti and Qiskit devices | PennyLane Demos)
I ran the exact same jupyter notebook

Hi @Martin_Guo! I get the same when I run the code. If you change this line:

results = torch.tensor(torch.vstack(results))


results = torch.tensor(np.array(results))

things should work. I’m not sure why this is an issue though :thinking:

Yeah I think I figured it out:/ stack does not accept tuple =-=

1 Like