PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.36k stars 604 forks source link

Include type casting to list for wires passed to Hermitian #456

Closed antalszava closed 4 years ago

antalszava commented 4 years ago

Issue description

When using Hermitian, if the wires parameter is not specified as a list, an error seems to arise.

Name: PennyLane
Version: 0.8.0.dev0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: /home/antal/Documents/code_base/pennylane
Requires: numpy, scipy, networkx, autograd, toml, appdirs, semantic-version
Required-by: 
Platform info:           Linux-5.0.0-37-generic-x86_64-with-debian-buster-sid
Python version:          3.7.4
Numpy version:           1.17.3
Scipy version:           1.3.1
Installed devices:
- strawberryfields.fock (PennyLane-SF-0.6.0.dev0)
- strawberryfields.gaussian (PennyLane-SF-0.6.0.dev0)
- projectq.classical (PennyLane-PQ-0.5.0.dev0)
- projectq.ibm (PennyLane-PQ-0.5.0.dev0)
- projectq.simulator (PennyLane-PQ-0.5.0.dev0)
- forest.numpy_wavefunction (PennyLane-Forest-0.4.0.dev0)
- forest.qpu (PennyLane-Forest-0.4.0.dev0)
- forest.qvm (PennyLane-Forest-0.4.0.dev0)
- forest.wavefunction (PennyLane-Forest-0.4.0.dev0)
- cirq.simulator (PennyLane-Cirq-0.1.0)
- microsoft.QuantumSimulator (PennyLane-qsharp-0.2.0)
- qiskit.aer (PennyLane-qiskit-0.7.0.dev0)
- qiskit.basicaer (PennyLane-qiskit-0.7.0.dev0)
- qiskit.ibmq (PennyLane-qiskit-0.7.0.dev0)
- qulacs.simulator (pennylane-qulacs-0.0.4)
- default.gaussian (PennyLane-0.8.0.dev0)
- default.qubit (PennyLane-0.8.0.dev0)
- expt.tensornet (PennyLane-0.8.0.dev0)
- expt.tensornet.tf (PennyLane-0.8.0.dev0)

Source code and tracebacks

Specifying wires as a tuple as follows:


@qml.qnode(dev)
def circuit2(a, b, c):
    return qml.expval(qml.Hermitian(np.kron(qml.PauliZ._matrix(), qml.PauliZ._matrix()), wires=(0, 2)))

Results in an error with the following traceback:

pennylane/qnodes/base.py:574: in evaluate
    self.circuit.operations, self.circuit.observables, self.variable_deps
pennylane/_qubit_device.py:96: in execute
    results.append(self.expval(obs))
pennylane/plugins/default_qubit.py:434: in expval
    self.rotate_basis(observable)
pennylane/_qubit_device.py:160: in rotate_basis
    self.apply(observable.diagonalizing_gates()[0])
pennylane/plugins/default_qubit.py:382: in apply
    self._state = self.mat_vec_product(A, self._state, wires)
(...)
        unused_idxs = [idx for idx in range(self.num_wires) if idx not in wires]
>       perm = wires + unused_idxs
E       TypeError: can only concatenate tuple (not "list") to tuple

pennylane/plugins/default_qubit.py:408: TypeError

Additional information

Any additional information, configuration or data that might be necessary to reproduce the issue.

josh146 commented 4 years ago

This issue is likely redundant now due to #666