Beispiel #1
0
def test_spinmodel(tolerance=None):
    from pyvmc.library.dmetal import DMetalWavefunction

    wf = DMetalWavefunction(**{
        'lattice': Lattice([12, 2]),
        'd1': Bands([5, 3], (periodic, periodic)),
        'd2': Bands([8, 0], (antiperiodic, periodic)),
        'f_up': Bands([4, 0], (antiperiodic, periodic)),
        'f_dn': Bands([4, 0], (antiperiodic, periodic)),
        'd1_exponent': 0.7,
        'd2_exponent': -0.4,
    })

    from pyvmc.operators import SpinModelRingExchangeOperator
    from pyvmc.measurements import BasicOperatorMeasurementPlan
    from pyvmc.core import LatticeSite
    from pyvmc.core.universe import SimulationUniverse

    spin_operator = SpinModelRingExchangeOperator(LatticeSite([0, 0]), LatticeSite([1, 0]),
                                                  LatticeSite([1, 1]), LatticeSite([0, 1]),
                                                  (periodic, periodic))
    plans = [BasicOperatorMeasurementPlan(wf, o) for o in spin_operator.get_basic_operators()]
    universe = SimulationUniverse(plans, equilibrium_sweeps=500000)
    universe.iterate(1000000)
    context = {mp.operator: m.get_estimate().result for mp, m in universe.get_overall_measurement_dict().items()}
    logger.info("Spin model: %f", spin_operator.evaluate(context)())
Beispiel #2
0
def test_ansatz(lattice, t1, delta1, mu0, expected_results, tolerance):
    parton_boundary_conditions = (periodic, antiperiodic)

    from pyvmc.library.mft_utils import did_hf_bcs_theory
    phi = did_hf_bcs_theory(lattice, parton_boundary_conditions, t1=t1, delta1=delta1, mu0=mu0, delta0=0)['pairing_matrix']

    from pyvmc.library.bcs import ProjectedBCSWavefunction
    wf = ProjectedBCSWavefunction(**{
        'lattice': lattice,
        'phi': phi,
        'N_up': len(lattice) // 2,
    })

    from pyvmc.library.heisenberg_ring import HeisenbergPlusRingExchangeHamiltonian
    from pyvmc.measurements import BasicOperatorMeasurementPlan
    from pyvmc.core import LatticeSite
    from pyvmc.core.universe import SimulationUniverse

    hamiltonian = HeisenbergPlusRingExchangeHamiltonian(parton_boundary_conditions, lattice)
    plans = [BasicOperatorMeasurementPlan(wf, o, steps_per_measurement=100) for o in hamiltonian.get_basic_operators()]
    universe = SimulationUniverse(plans, equilibrium_sweeps=100000)
    universe.iterate(1000000)
    context = {mp.operator: m.get_estimate().result for mp, m in universe.get_overall_measurement_dict().items()}
    evaluator = hamiltonian.evaluate(context)
    final_results = (
        evaluator(J1=1, J2=0, J3=0, K=0) / len(lattice) / 3,
        evaluator(J1=0, J2=1, J3=0, K=0) / len(lattice) / 3,
        evaluator(J1=0, J2=0, J3=1, K=0) / len(lattice) / 3,
        evaluator(J1=0, J2=0, J3=0, K=1) / len(lattice) / 3,
    )
    logger.info("t1=%f, delta1=%f, mu0=%f", t1, delta1, mu0)
    logger.info("  nn: %f", final_results[0])
    logger.info(" 2nn: %f", final_results[1])
    logger.info(" 3nn: %f", final_results[2])
    logger.info("ring: %f", final_results[3])

    assert all(abs(r1 - r2) < tolerance for r1, r2 in zip(final_results, expected_results))
Beispiel #3
0
def test_1d_free_fermion_renyi(tolerance=0.02):
    N = 10
    F = 5

    lattice = Lattice([N])
    orbitals = Bands([F], [periodic])

    if False:
        # a constant Jastrow factor shouldn't change anything
        from pyvmc.core.wavefunction import TwoBodyJastrowFactor

        jastrow_mat = numpy.empty((N, N))
        jastrow_mat.fill(1)
        jastrow = TwoBodyJastrowFactor(jastrow_mat)
    else:
        jastrow = None
    wf = FreeFermionWavefunction(lattice=lattice, orbitals=[orbitals], jastrow=jastrow)

    exact_values = [
        free_fermions.exact_renyi(SimpleSubsystem([i], lattice), orbitals, [periodic], 2) for i in range(1, N // 2 + 1)
    ]

    plans = [RenyiEntropyMeasurementPlan(wf, SimpleSubsystem([i], lattice)) for i in range(1, N // 2 + 1)]
    calc = SimulationUniverse(plans, 500000)
    while True:
        calc.iterate(200000)
        results = calc.get_overall_measurement_dict()
        measured_values = [plan.calculate(lambda p, k=None: results[p].get_estimate(k).result) for plan in plans]

        differences = [
            measured_value - exact_value for measured_value, exact_value in zip(measured_values, exact_values)
        ]
        logger.info("differences from expected: %s", differences)
        if all(numpy.abs(d) < tolerance for d in differences):
            break

    # test hdf5
    import h5py

    filename = "/tmp/hdf5test_renyi.hdf5"
    with h5py.File(filename, "w") as f:
        calc.to_hdf5(f)
    with h5py.File(filename, "r") as f:
        universe2 = SimulationUniverse.from_hdf5(f, wf)
    results2 = universe2.get_overall_measurement_dict()
    measured_values2 = [plan.calculate(lambda p, k=None: results2[p].get_estimate(k).result) for plan in plans]
    assert all(
        numpy.abs(measured_value - exact_value) < tolerance
        for measured_value, exact_value in zip(measured_values, exact_values)
    )
Beispiel #4
0
def test_dmetal_energy(tolerance=None):
    wf = DMetalWavefunction(**{
        'lattice': Lattice([12, 2]),
        'd1': Bands([5, 3], (periodic, periodic)),
        'd2': Bands([8, 0], (antiperiodic, periodic)),
        'f_up': Bands([4, 0], (antiperiodic, periodic)),
        'f_dn': Bands([4, 0], (antiperiodic, periodic)),
        'd1_exponent': 0.7,
        'd2_exponent': -0.4,
    })

    from pyvmc.operators import TJKHamiltonian
    from pyvmc.measurements import BasicOperatorMeasurementPlan
    from pyvmc.core.universe import SimulationUniverse

    hamiltonian = TJKHamiltonian((periodic, periodic), wf.lattice)
    plans = [BasicOperatorMeasurementPlan(wf, o) for o in hamiltonian.get_basic_operators()]
    universe = SimulationUniverse(plans, equilibrium_sweeps=500000)
    universe.iterate(1000000)
    context = {mp.operator: m.get_estimate().result for mp, m in universe.get_overall_measurement_dict().items()}
    energy = hamiltonian.evaluate(context)(t=1, J=2, K=2) / len(wf.lattice)

    logger.info("Energy: %f", energy)
    assert -0.8 < energy < -0.74

    # test hdf5
    import h5py
    filename = '/tmp/hdf5test_dmetal.hdf5'
    with h5py.File(filename, 'w') as f:
        grp = f.create_group('testgroup')
        universe.to_hdf5(grp)
    with h5py.File(filename, 'r') as f:
        universe2 = SimulationUniverse.from_hdf5(f['testgroup'], wf)
    context2 = {mp.operator: m.get_estimate().result for mp, m in universe2.get_overall_measurement_dict().items()}
    energy = hamiltonian.evaluate(context)(t=1, J=2, K=2) / len(wf.lattice)
    logger.info("Energy: %f", energy)
    assert -0.8 < energy < -0.74