mindquantum.core.operators.commutator

View Source On Gitee
mindquantum.core.operators.commutator(left_operator, right_operator)[source]

Compute the commutator of two operators.

Parameters
Raises

TypeErrorleft_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]