Skip to content

[BUG] MPSPrep fails when work_wires are np.arrays #8551

@tomlqc

Description

@tomlqc

Expected behavior

MPSPrep() accepts np.array as work_wires

Actual behavior

When passing work_wires to MPSPrep() as an np.array instead of a python list, it fails with

pennylane/templates/state_preparations/state_prep_mps.py:359: ValueError
>       if work_wires:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

See

The if-clause if work_wires: works well with lists, but not with np.array.
We could have instead,

if work_wires is not None:

Additional information

No response

Source code

Tracebacks

System information

Name: pennylane
Version: 0.44.0.dev15
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: 
Author: 
Author-email: 
License: 
Location: /home/ubuntu/Benchmarks/venv/latest/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing_extensions
Required-by: pennylane_catalyst, pennylane_lightning, pennylane_lightning_kokkos

Platform info:           Linux-5.15.0-142-generic-x86_64-with-glibc2.35
Python version:          3.11.11
Numpy version:           2.3.4
Scipy version:           1.16.2
JAX version:             0.6.2
Installed devices:
- lightning.qubit (pennylane_lightning-0.44.0.dev9)
- nvidia.custatevec (pennylane_catalyst-0.14.0.dev15)
- nvidia.cutensornet (pennylane_catalyst-0.14.0.dev15)
- oqc.cloud (pennylane_catalyst-0.14.0.dev15)
- softwareq.qpp (pennylane_catalyst-0.14.0.dev15)
- default.clifford (pennylane-0.44.0.dev15)
- default.gaussian (pennylane-0.44.0.dev15)
- default.mixed (pennylane-0.44.0.dev15)
- default.qubit (pennylane-0.44.0.dev15)
- default.qutrit (pennylane-0.44.0.dev15)
- default.qutrit.mixed (pennylane-0.44.0.dev15)
- default.tensor (pennylane-0.44.0.dev15)
- null.qubit (pennylane-0.44.0.dev15)
- reference.qubit (pennylane-0.44.0.dev15)
- lightning.kokkos (pennylane_lightning_kokkos-0.43.0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions