Skip to content

QuantumCircuit.compose errors when qubits argument is numpy.int64 instead of int. #8691

@tomohiro-soejima

Description

@tomohiro-soejima

Environment

  • `qiskit-terra: '0.21.0':
  • python: '3.9.12':
  • Ubuntu-20.04 windows subsystem for Linux running on Windows 10:
  • numpy: 1.21.5

What is happening?

QuantumCircuit.compose() errors when qubits argument is a list of numpy.int64 instead of int.

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.converters.circuit_to_dag import circuit_to_dag
import numpy as np

qc0 = QuantumCircuit(1)
qc1 = QuantumCircuit(1)
qc0.x(0)
qc1.x(0)

# First, let's try qubits = [0] (vanilla python `int`)
qc_vanilla_int = qc0.compose(qc1, qubits=[0])
# `QuantumCircuit.compose` does not error even when the `qubits` argument is invalid, so we need to check the DAG
circuit_to_dag(qc_vanilla_int) # does not error

# Now let's try qubits = [np.int64(0)]
qc_numpy_int = qc0.compose(qc1, qubits=[np.int64(0)]) #np.arange(0) does the same thing.
circuit_to_dag(qc_numpy_int) #this one errors

Here is the error:

DAGCircuitError: "(qu)bit 0 not found in OrderedDict([(Qubit(QuantumRegister(1, 'q'), 0), 
DAGOutNode(wire=Qubit(QuantumRegister(1, 'q'), 0)))])"

What should happen?

qc0.compose should return a QuantumCircuit object that can be converted to a DAG.

Any suggestions?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions