Exemplo n.º 1
0
def _setup_ss(**kwargs):
    nk.random.seed(SEED)
    np.random.seed(SEED)

    hi, lind = _setup_system()

    ma = nk.machine.density_matrix.RbmSpin(hilbert=hi, alpha=1)
    ma.init_random_parameters(sigma=0.01, seed=SEED)

    sa = nk.sampler.MetropolisLocal(machine=ma)
    sa_obs = nk.sampler.MetropolisLocal(machine=ma.diagonal())

    op = nk.optimizer.Sgd(ma, learning_rate=0.1)

    if "sr" in kwargs:
        sr = nk.optimizer.SR(ma, **kwargs["sr"])
        kwargs["sr"] = sr

    ss = nk.SteadyState(lindblad=lind,
                        sampler=sa,
                        optimizer=op,
                        sampler_obs=sa_obs,
                        **kwargs)

    return ma, ss
Exemplo n.º 2
0
def _setup_ss(dtype=np.float32, sr=True):
    hi, lind = _setup_system()

    ma = nk.models.NDM()
    # sa = nk.sampler.ExactSampler(hilbert=nk.hilbert.DoubledHilber(hi))

    sa = nk.sampler.MetropolisLocal(hilbert=nk.hilbert.DoubledHilbert(hi))
    sa_obs = nk.sampler.MetropolisLocal(hilbert=hi)

    vs = nk.vqs.MCMixedState(sa,
                             ma,
                             sampler_diag=sa_obs,
                             n_samples=1000,
                             seed=SEED)

    op = nk.optimizer.Sgd(learning_rate=0.05)
    if sr:
        sr_config = nk.optimizer.SR()
    else:
        sr_config = None

    driver = nk.SteadyState(lind,
                            op,
                            variational_state=vs,
                            preconditioner=sr_config)

    return lind, vs, driver
Exemplo n.º 3
0
def test_steadystate_construction_vstate():
    lind, vs, driver = _setup_ss()

    sa = vs.sampler
    op = nk.optimizer.Sgd(learning_rate=0.05)

    driver = nk.SteadyState(lind,
                            op,
                            sa,
                            nk.models.NDM(),
                            n_samples=1000,
                            seed=SEED)

    driver.run(1)

    assert driver.step_count == 1

    with raises(TypeError):
        ha2 = nk.operator.LocalOperator(lind.hilbert_physical)
        driver = nk.SteadyState(ha2, op, variational_state=driver.state)
Exemplo n.º 4
0
def test_steadystate_steadystate_legacy_api():
    lind, vs, driver = _setup_ss()
    op = driver.optimizer
    vs = driver.state
    sr_config = driver.preconditioner

    with pytest.raises(ValueError):
        driver = nk.SteadyState(lind,
                                op,
                                variational_state=vs,
                                sr=sr_config,
                                preconditioner=sr_config)

    with pytest.warns(FutureWarning):
        driver = nk.SteadyState(lind,
                                op,
                                variational_state=vs,
                                sr=sr_config,
                                sr_restart=True)
        assert driver.preconditioner == sr_config
Exemplo n.º 5
0
def _setup_ss(**kwargs):
    nk.random.seed(SEED)
    np.random.seed(SEED)
    g = nk.graph.Hypercube(length=L, n_dim=1)
    hi = nk.hilbert.Spin(s=0.5, graph=g)

    # ma = nk.machine.density_matrix.RbmSpin(hilbert=hi, alpha=1)
    ma = nk.machine.density_matrix.RbmSpin(hilbert=hi, alpha=1)
    ma.init_random_parameters(sigma=0.01, seed=SEED)

    ha = nk.operator.LocalOperator(hi)
    j_ops = []
    for i in range(L):
        ha += (0.3 / 2.0) * nk.operator.LocalOperator(hi, sx, [i])
        ha += (2.0 / 4.0) * nk.operator.LocalOperator(hi, np.kron(sz, sz),
                                                      [i, (i + 1) % L])
        j_ops.append(nk.operator.LocalOperator(hi, sigmam, [i]))

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

    sa = nk.sampler.MetropolisLocal(machine=ma)
    sa_obs = nk.sampler.MetropolisLocal(machine=ma.diagonal())

    op = nk.optimizer.Sgd(ma, learning_rate=0.1)

    if "sr" in kwargs:
        sr = nk.optimizer.SR(ma, **kwargs["sr"])
        kwargs["sr"] = sr

    ss = nk.SteadyState(lindblad=lind,
                        sampler=sa,
                        optimizer=op,
                        sampler_obs=sa_obs,
                        **kwargs)

    return ma, ss
Exemplo n.º 6
0
def _setup_ss(**kwargs):
    nk.utils.seed(SEED)
    g = nk.graph.Hypercube(length=L, n_dim=1)
    hi = nk.hilbert.Spin(s=0.5, graph=g)

    ma = nk.machine.NdmSpinPhase(hilbert=hi, alpha=1, beta=1)
    ma.init_random_parameters(sigma=0.01)

    ha = nk.operator.LocalOperator(hi)
    obs_sx = nk.operator.LocalOperator(hi)
    j_ops = []
    for i in range(L):
        ha += (0.3 / 2.0) * nk.operator.LocalOperator(hi, sx, [i])
        ha += (2.0 / 4.0) * nk.operator.LocalOperator(hi, np.kron(sz, sz),
                                                      [i, (i + 1) % L])
        j_ops.append(nk.operator.LocalOperator(hi, sigmam, [i]))

        obs_sx += nk.operator.LocalOperator(hi, sx, [i])

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

    sa = nk.sampler.MetropolisLocal(machine=ma)
    sa_obs = nk.sampler.MetropolisLocal(machine=ma.diagonal())

    op = nk.optimizer.Sgd(learning_rate=0.1)

    ss = nk.SteadyState(lindblad=lind,
                        sampler=sa,
                        optimizer=op,
                        sampler_obs=sa_obs,
                        **kwargs)

    # Add custom observable
    ss.add_observable(obs_sx, "SigmaX")

    return ma, ss
Exemplo n.º 7
0
for i in range(L):
    ha += (gp / 2.0) * nk.operator.spin.sigmax(hi, i)
    ha += ((Vp / 4.0) * nk.operator.spin.sigmaz(hi, i) *
           nk.operator.spin.sigmaz(hi, (i + 1) % L))
    # sigma_{-} dissipation on every site
    j_ops.append(nk.operator.spin.sigmam(hi, i))
    obs_sx += nk.operator.spin.sigmax(hi, i)
    obs_sy += nk.operator.spin.sigmay(hi, i)
    obs_sz += nk.operator.spin.sigmaz(hi, i)

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

ma = nk.models.NDM(beta=1, )

# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(lind.hilbert)

# Optimizer
op = nk.optimizer.Sgd(0.01)
sr = nk.optimizer.SR(diag_shift=0.01)

vs = nk.vqs.MCMixedState(sa, ma, n_samples=2000, n_samples_diag=500)
vs.init_parameters(nk.nn.initializers.normal(stddev=0.01))

ss = nk.SteadyState(lind, op, variational_state=vs, preconditioner=sr)

obs = {"Sx": obs_sx, "Sy": obs_sy, "Sz": obs_sz}

out = ss.run(n_iter=300, out="test", obs=obs)
Exemplo n.º 8
0
    ha += (Vp / 4.0) * nk.operator.LocalOperator(hi, np.kron(sz, sz),
                                                 [i, (i + 1) % L])

    # sigma_{-} dissipation on every site
    j_ops.append(nk.operator.LocalOperator(hi, sigmam, [i]))

    obs_sx += nk.operator.LocalOperator(hi, sx, [i])
    obs_sy += nk.operator.LocalOperator(hi, sy, [i])
    obs_sz += nk.operator.LocalOperator(hi, sz, [i])

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

# RBM Spin Machine
ma = nk.machine.NdmSpinPhase(hilbert=hi, alpha=1, beta=1)
ma.init_random_parameters(seed=1234, sigma=0.001)

# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Sampler for the diagonal of the density matrix, to compute observables
sa_obs = nk.sampler.MetropolisLocal(machine=ma.diagonal())

# Optimizer
op = nk.optimizer.Sgd(ma, 0.01)
sr = nk.optimizer.SR(ma, diag_shift=0.01, use_iterative=True)

ss = nk.SteadyState(lind, sa, op, 2000, sampler_obs=sa_obs, n_samples_obs=500)
obs = {"Sx": obs_sx, "Sy": obs_sy, "Sz": obs_sz}

ss.run(n_iter=200, out="test", obs=obs)
Exemplo n.º 9
0
for i in range(L):
    ha += (gp / 2.0) * nk.operator.spin.sigmax(hi, i)
    ha += ((Vp / 4.0) * nk.operator.spin.sigmaz(hi, i) *
           nk.operator.spin.sigmaz(hi, (i + 1) % L))
    # sigma_{-} dissipation on every site
    j_ops.append(nk.operator.spin.sigmam(hi, i))
    obs_sx += nk.operator.spin.sigmax(hi, i)
    obs_sy += nk.operator.spin.sigmay(hi, i)
    obs_sz += nk.operator.spin.sigmaz(hi, i)

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

ma = nk.models.NDM(beta=1, )

# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(lind.hilbert)

# Optimizer
op = nk.optimizer.Sgd(0.01)
sr = nk.optimizer.SR(diag_shift=0.01)

vs = nk.variational.MCMixedState(sa, ma, n_samples=2000, n_samples_diag=500)
vs.init_parameters(nk.nn.initializers.normal(stddev=0.01))

ss = nk.SteadyState(lind, op, variational_state=vs, sr=sr)

obs = {"Sx": obs_sx, "Sy": obs_sy, "Sz": obs_sz}

out = ss.run(n_iter=300, out="test", obs=obs)