Trying to apply a four-qubit unitary gate, getting an error message I don't understand (see title).

Here is my code

import numpy as np
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.extensions import UnitaryGate
gate16x16=np.load('m0.npy', allow_pickle=True) #shape [4,4]
q = QuantumRegister(4)
c = ClassicalRegister(4)
qc = QuantumCircuit(q)

qc.measure(q[0], c[0])
  • 2
    $\begingroup$ If the gate that you have loaded into the variable gate16x16 is indeed of dimensions $4 \times 4$ as implied in the comment #shape [4,4], then this is the problem. $4 \times 4$ unitary matrices are representation of quantum gates for $2$ qubits, not for $4$ qubits. For $4$ qubits a unitary operator of dimensions $16 \times 16$ is needed. $\endgroup$
    – Ohad
    Aug 22, 2022 at 22:46
  • $\begingroup$ Could you please provide the matrix you load? $\endgroup$ Aug 24, 2022 at 4:35


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.