Ejemplo n.º 1
0
def test_isdm():
    # Check when matrix is non-semi-positive-definite
    non_spd = jnp.array([[1, 1], [-1, 1]])
    assert isdm(non_spd) == False
    # Check standard density matrices
    assert isdm(to_dm(basis(2, 0))) == True
    # Check when matrix is non-hermitian
    assert isdm(sigmax() * sigmay()) == False
    # Check when trace is non-unity
    assert isdm(jnp.eye(2) * 2) == False
Ejemplo n.º 2
0
def test_sigmax():
    assert_array_equal(sigmax(), jnp.array([[0.0, 1.0], [1.0, 0.0]]))
Ejemplo n.º 3
0
def test_sigmax():
    assert_array_equal(sigmax(), jnp.array([[0.0, 1.0], [1.0, 0.0]]))


def test_sigmay():
    assert_array_equal(
        sigmay(), jnp.array([[0.0 + 0.0j, 0.0 - 1.0j], [0.0 + 1.0j, 0.0 + 0.0j]])
    )


def test_sigmaz():
    assert_array_equal(sigmaz(), jnp.array([[1.0, 0.0], [0.0, -1.0]]))


@pytest.mark.parametrize("op", [sigmax(), sigmay(), sigmaz()])
@pytest.mark.parametrize("state", [basis(2, 0), basis(2, 1)])
def test_expect_sigmaxyz(op, state):
    """Tests the `expect` function on Pauli-X, Pauli-Y and Pauli-Z."""
    # The stacked pytest decorators check all the argument combinations like a Cartesian product
    if jnp.all(op != sigmaz()):
        assert expect(op, state) == 0.0
    elif jnp.all(state == basis(2, 0)):
        assert expect(op, state) == 1.0
    else:
        assert expect(op, state) == -1.0


@pytest.mark.parametrize(
    "oper, state",
    [