def test_commutator():
    'Test commutator'
    qub_op1 = QubitOperator('X1 Y2')
    qub_op2 = QubitOperator('X1 Z2')
    qub_op3 = (2j * QubitOperator('X2'))
    assert (commutator(qub_op1, qub_op2) == qub_op3)
    assert (commutator(qub_op1, qub_op1) == QubitOperator())
    qubit_exc_op1 = QubitExcitationOperator(((4, 1), (1, 0)), 2j)
    qubit_exc_op2 = QubitExcitationOperator(((3, 1), (2, 0)), 2j)
    qubit_exc_op3 = (QubitExcitationOperator('3^ 2 4^ 1', 4.0) + QubitExcitationOperator('4^ 1 3^ 2', (- 4.0)))
    assert (commutator(qubit_exc_op1, qubit_exc_op2).compress() == qubit_exc_op3)
    assert (commutator(qubit_exc_op1, qubit_exc_op1) == QubitExcitationOperator())
Test commutator
def test_commutator():
    
    qub_op1 = QubitOperator('X1 Y2')
    qub_op2 = QubitOperator('X1 Z2')
    qub_op3 = (2j * QubitOperator('X2'))
    assert (commutator(qub_op1, qub_op2) == qub_op3)
    assert (commutator(qub_op1, qub_op1) == QubitOperator())
    qubit_exc_op1 = QubitExcitationOperator(((4, 1), (1, 0)), 2j)
    qubit_exc_op2 = QubitExcitationOperator(((3, 1), (2, 0)), 2j)
    qubit_exc_op3 = (QubitExcitationOperator('3^ 2 4^ 1', 4.0) + QubitExcitationOperator('4^ 1 3^ 2', (- 4.0)))
    assert (commutator(qubit_exc_op1, qubit_exc_op2).compress() == qubit_exc_op3)
    assert (commutator(qubit_exc_op1, qubit_exc_op1) == QubitExcitationOperator())