Commutation operation is essential in quantum mechanics, but when I was trying to use the commutator of IBM qiskit I find something confusing.
Here comes the problematic code.
from qiskit import QuantumCircuit from qiskit.quantum_info import DensityMatrix from qiskit.aqua.operators.legacy import commutator qr0=QuantumCircuit(1) qr1=QuantumCircuit(1) circ0.x(0) dm0=DensityMatrix.from_instruction(circ0) circ1.z(0) dm1=DensityMatrix.from_instruction(circ1)
The upper codes generates two Density Matrices, and since they are matrices, mathematically we can compute their commutator, but then after you run
commutator(dm0,dm1) you'll find that it's not working. Even if you try some other types like input two Operators or input the detailed matrices(
dm.data) but it is just raised an error. E.g. in the lower code when the detailed matrices case returns an error.
dm0=Operator(dm0) dm1=Operator(dm1) commutator(dm0.data,dm1.data)
The errors that qiskit reports are nearly identical so I just put one of them as an example.
I know numpy or scipy can help me in circumventing the trouble, but I still want to ask: have anyone meet this before? Do you know how to fix this? Thanks!