Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instruction comparison fails when parameters are arrays #2751

Closed
gadial opened this issue Jul 8, 2019 · 1 comment · Fixed by #2765
Closed

Instruction comparison fails when parameters are arrays #2751

gadial opened this issue Jul 8, 2019 · 1 comment · Fixed by #2765
Assignees
Labels
bug Something isn't working

Comments

@gadial
Copy link
Contributor

gadial commented Jul 8, 2019

Information

  • Qiskit Terra version: 0.8.2
  • Python version: 3.6
  • Operating system: Linux

What is the current behavior?

Comparing two instructions that have matrix parameters fails ungracefully with
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Matrix parameters for instructions are currently generated when converting Aer's errors to instructions.

Steps to reproduce the problem

The following code raises this error:

from qiskit import QuantumRegister, QuantumCircuit
from qiskit.providers.aer.noise.errors.standard_errors import pauli_error
qr = QuantumRegister(1, 'qr')
circuit = QuantumCircuit(qr)
error = pauli_error([('X', 0.25), ('I', 0.75)])
circuit.append(error.to_instruction(), [qr[0]])
circuit == circuit

What is the expected behavior?

Correct element-by-element comparison of the matrices, using numpy.isclose for almost-identical matrices.

Suggested solutions

Line 99 in instruction.py needs to be modified; it seems type-checking the parameter is needed (maybe isinstance(self_param, numpy.ndarray?). For Numpy arrays numpy.equalandnumpy.iscloseworks and returns a boolean array of results, on whichall()` can be used.

@gadial
Copy link
Contributor Author

gadial commented Jul 10, 2019

This is currently blocking a PR in Aer: Qiskit/qiskit-aer#239

@kdk kdk self-assigned this Jul 10, 2019
@kdk kdk added the bug Something isn't working label Jul 10, 2019
@kdk kdk closed this as completed in #2765 Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants