Skip to content

Commit

Permalink
Fix based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderivrii committed Aug 9, 2022
1 parent d82e2e0 commit 07733d6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions qiskit/quantum_info/operators/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,11 @@ def _init_instruction(cls, instruction):
@classmethod
def _instruction_to_matrix(cls, obj):
"""Return Operator for instruction if defined or None otherwise."""
if not isinstance(obj, Operation):
raise QiskitError("Input is not an instruction.")
# Note: to_matrix() is not a required method for Operations, thus we raise
# an error for opaque instructions without a matrix representation.
# On the other hand, we do use to_matrix() when it's available.
if not isinstance(obj, Operation) and not hasattr(obj, "to_matrix"):
raise QiskitError("Input is not an Operation and does not have 'to_matrix()' method.")
mat = None
if hasattr(obj, "to_matrix"):
# If instruction is a gate first we see if it has a
Expand Down

0 comments on commit 07733d6

Please sign in to comment.