Exemplo n.º 1
0
def test_to_dm():
    """Tests the `to_dm` method that converts kets and bras to density matrices"""
    dm0 = jnp.array(
        [[1.0 + 0.0j, 0.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]], dtype=jnp.complex64
    )
    dm1 = jnp.array(
        [[0.0 + 0.0j, 0.0 + 0.0j], [0.0 + 0.0j, 1.0 + 0.0j]], dtype=jnp.complex64
    )
    # testing kets
    assert_array_equal(to_dm(basis(2, 0)), dm0)
    assert_array_equal(to_dm(basis(2, 1)), dm1)
    # testing bras
    assert_array_equal(to_dm(dag(basis(2, 0))), dm0)
    assert_array_equal(to_dm(dag(basis(2, 1))), dm1)
Exemplo n.º 2
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
Exemplo n.º 3
0
def snap(hilbert_size, thetas):
    """
    Constructs the matrix for a SNAP gate operation
    that can be applied to a state.
    
    Args:
        hilbert_size (int): Hilbert space cuttoff
        thetas (:obj:`jnp.ndarray`): A vector of theta values to 
                apply SNAP operation
    
    Returns:
        :obj:`jnp.ndarray`: matrix representing the SNAP gate
    """
    op = 0 * jnp.eye(hilbert_size)
    for i, theta in enumerate(thetas):
        op += jnp.exp(1j * theta) * to_dm(basis(hilbert_size, i))
    return op