def test_simple_operators():
    L = 4
    g = nk.graph.Hypercube(L, 1)
    hi = nk.hilbert.Spin(g, 0.5)

    sx = [[0, 1], [1, 0]]
    sy = [[0, -1.0j], [1.0j, 0]]
    sz = [[1, 0], [0, -1]]
    sm = [[0, 0], [1, 0]]
    sp = [[0, 1], [0, 0]]

    print("Testing Sigma_x/y/z...")
    for i in range(L):
        sx_hat = nk.operator.LocalOperator(hi, sx, [i])
        sy_hat = nk.operator.LocalOperator(hi, sy, [i])
        sz_hat = nk.operator.LocalOperator(hi, sz, [i])

        assert (sigmax(hi, i).to_dense() == sx_hat.to_dense()).all()
        assert (sigmay(hi, i).to_dense() == sy_hat.to_dense()).all()
        assert (sigmaz(hi, i).to_dense() == sz_hat.to_dense()).all()

    print("Testing Sigma_+/-...")
    for i in range(L):
        sm_hat = nk.operator.LocalOperator(hi, sm, [i])
        sp_hat = nk.operator.LocalOperator(hi, sp, [i])

        assert (sigmam(hi, i).to_dense() == sm_hat.to_dense()).all()
        assert (sigmap(hi, i).to_dense() == sp_hat.to_dense()).all()

    print("Testing Sigma_+/- composition...")

    hi = nk.hilbert.Spin(g, 0.5)
    for i in range(L):
        sx = sigmax(hi, i)
        sy = sigmay(hi, i)

        sigmam_hat = 0.5 * (sx + (-1j) * sy)
        sigmap_hat = 0.5 * (sx + (1j) * sy)

        assert (sigmam(hi, i).to_dense() == sigmam_hat.to_dense()).all()
        assert (sigmap(hi, i).to_dense() == sigmap_hat.to_dense()).all()

    print("Testing create/destroy composition...")
    hi = nk.hilbert.Boson(g, 3)
    for i in range(L):
        a = bdestroy(hi, i)
        ad = bcreate(hi, i)
        n = bnumber(hi, i)

        assert np.allclose(n.to_dense(), (ad * a).to_dense())
        assert (ad.to_dense() == a.conjugate().transpose().to_dense()).all()
Beispiel #2
0
def test_pauli_algebra(S):
    hi = nk.hilbert.Spin(S)**N

    for i in range(N):
        sx = spin.sigmax(hi, i)
        sy = spin.sigmay(hi, i)
        sz = spin.sigmaz(hi, i)

        sm = spin.sigmam(hi, i)
        sp = spin.sigmap(hi, i)

        assert_almost_equal(0.5 * (sx - 1j * sy).to_dense(), sm.to_dense())
        assert_almost_equal(0.5 * (sx + 1j * sy).to_dense(), sp.to_dense())
        assert_almost_equal(0.5 * (sx.to_dense() - 1j * sy.to_dense()),
                            sm.to_dense())
        assert_almost_equal(0.5 * (sx.to_dense() + 1j * sy.to_dense()),
                            sp.to_dense())

        if S == 1 / 2:
            Imat = np.eye(hi.n_states)

            # check that -i sx sy sz = I
            assert_almost_equal((-1j * sx @ sy @ sz).to_dense(), Imat)
            assert_almost_equal(
                (-1j * sx.to_dense() @ sy.to_dense() @ sz.to_dense()), Imat)
Beispiel #3
0
def test_sigmay_is_complex():
    hi = nk.hilbert.Spin(1 // 2) ** 3

    with pytest.warns(np.ComplexWarning):
        sy = spin.sigmay(hi, 0, dtype=np.float64)
        assert sy.dtype == np.complex128

    with pytest.warns(np.ComplexWarning):
        sy = spin.sigmay(hi, 0, dtype=np.float32)
        assert sy.dtype == np.complex64

    sy = spin.sigmay(hi, 0, dtype=np.complex64)
    assert sy.dtype == np.complex64

    sy = spin.sigmay(hi, 0, dtype=np.complex128)
    assert sy.dtype == np.complex128
Beispiel #4
0
def test_simple_operators():
    L = 4
    hi = nk.hilbert.Spin(0.5) ** L

    sx = [[0, 1], [1, 0]]
    sy = [[0, -1.0j], [1.0j, 0]]
    sz = [[1, 0], [0, -1]]
    sm = [[0, 0], [1, 0]]
    sp = [[0, 1], [0, 0]]

    print("Testing Sigma_x/y/z...")
    for i in range(L):
        sx_hat = nk.operator.LocalOperator(hi, sx, [i])
        sy_hat = nk.operator.LocalOperator(hi, sy, [i])
        sz_hat = nk.operator.LocalOperator(hi, sz, [i])
        assert (sigmax(hi, i).to_dense() == sx_hat.to_dense()).all()
        assert (sigmay(hi, i).to_dense() == sy_hat.to_dense()).all()
        assert (sigmaz(hi, i).to_dense() == sz_hat.to_dense()).all()

    print("Testing Sigma_+/-...")
    for i in range(L):
        sm_hat = nk.operator.LocalOperator(hi, sm, [i])
        sp_hat = nk.operator.LocalOperator(hi, sp, [i])
        assert (sigmam(hi, i).to_dense() == sm_hat.to_dense()).all()
        assert (sigmap(hi, i).to_dense() == sp_hat.to_dense()).all()

    print("Testing Sigma_+/- composition...")

    hi = nk.hilbert.Spin(0.5, N=L)
    for i in range(L):
        sx = sigmax(hi, i)
        sy = sigmay(hi, i)
        sigmam_hat = 0.5 * (sx + (-1j) * sy)
        sigmap_hat = 0.5 * (sx + (1j) * sy)
        assert (sigmam(hi, i).to_dense() == sigmam_hat.to_dense()).all()
        assert (sigmap(hi, i).to_dense() == sigmap_hat.to_dense()).all()

    print("Testing create/destroy composition...")
    hi = nk.hilbert.Fock(3, N=L)
    for i in range(L):
        print("i=", i)
        a = bdestroy(hi, i)
        ad = bcreate(hi, i)
        n = bnumber(hi, i)

        assert np.allclose(n.to_dense(), (ad @ a).to_dense())
        assert (ad.to_dense() == a.conjugate().transpose().to_dense()).all()

    print("Testing mixed spaces...")
    L = 3
    his = nk.hilbert.Spin(0.5, N=L)
    hib = nk.hilbert.Fock(3, N=L - 1)
    hi = his * hib
    for i in range(hi.size):
        print("i=", i)
        sx = sigmax(hi, i)

        assert sx.operators[0].shape == (hi.shape[i], hi.shape[i])
        assert np.allclose(n.to_dense(), (ad @ a).to_dense())
        assert (ad.to_dense() == a.conjugate().transpose().to_dense()).all()

    for i in range(3):
        print("i=", i)
        a = bdestroy(hi, i)
        ad = bcreate(hi, i)
        n = bnumber(hi, i)
        for j in range(3, 5):
            print("j=", i)
            a = bdestroy(hi, j)
            ad = bcreate(hi, j)
            n = bnumber(hi, j)

        assert np.allclose(n.to_dense(), (ad @ a).to_dense())
        assert (ad.to_dense() == a.conjugate().transpose().to_dense()).all()
Beispiel #5
0
from netket.operator import spin

np.set_printoptions(linewidth=180)

# 1D Lattice
L = 4

# Hilbert space of spins on the graph
hi = nk.hilbert.Spin(s=0.5) ** L

ha = nk.operator.LocalOperator(hi, dtype=complex)
j_ops = []

for i in range(L):
    ha += spin.sigmax(hi, i)
    ha += spin.sigmay(hi, i)
    ha += spin.sigmaz(hi, i) @ spin.sigmaz(hi, (i + 1) % L)
    j_ops.append(spin.sigmam(hi, i))
    j_ops.append(1j * spin.sigmam(hi, i))


#  Create the lindbladian with
lind = nk.operator.LocalLiouvillian(ha, j_ops)


def test_lindblad_form():
    ## Construct the lindbladian by hand:
    idmat = sparse.eye(2**L)

    # Build the non hermitian matrix
    hnh_mat = ha.to_sparse()