mindquantum.core.operators.commutator
- mindquantum.core.operators.commutator(left_operator, right_operator)[source]
Compute the commutator of two operators.
- Parameters
left_operator (Union[FermionOperator, QubitOperator, QubitExcitationOperator]) – FermionOperator or QubitOperator.
right_operator (Union[FermionOperator, QubitOperator, QubitExcitationOperator]) – FermionOperator or QubitOperator.
- Raises
TypeError – left_operator and right_operator are not of the same type.
Examples
>>> from mindquantum.core.operators import QubitOperator, FermionOperator, commutator >>> qub_op1 = QubitOperator("X1 Y2") >>> qub_op2 = QubitOperator("X1 Z2") >>> commutator(qub_op1, qub_op1) 0 >>> commutator(qub_op1, qub_op2) (2j) [X2]