Beispiel #1
0
def test_simple_subsystem_json():
    lattice = Lattice([16, 8], 2)
    subsystem = SimpleSubsystem([4, 4], lattice)
    assert json.dumps(subsystem.to_json()) == '{"type": "SimpleSubsystem", "dimensions": [4, 4]}'

    assert Subsystem.from_json(subsystem.to_json(), lattice) == subsystem
    assert SimpleSubsystem.from_json(subsystem.to_json(), lattice) == subsystem
Beispiel #2
0
def _save_universe_to_hdf5(universe, h5group):
    assert isinstance(universe, SimulationUniverse)

    from pyvmc.utils import custom_json as json

    # make sure we've provided an empty h5group
    if h5group.attrs or h5group.keys():
        raise Exception("h5group is not empty")

    # fixme: for now, assume there is only one wavefunction represented in all
    # the plans
    wf_set = {sim.walk_plan.wavefunction for sim in universe.simulations}
    assert len(wf_set) == 1
    wf = wf_set.pop()

    # remember info about the wavefunction
    h5group.attrs["wavefunction_json"] = json.dumps(wf.to_json())
    for k, v in six.iteritems(wf.to_json_extra()):
        h5group.create_dataset("wf_{}".format(k), data=v)

    # save each walk to an hdf5 subgroup
    for i, sim in enumerate(universe.simulations):
        sim.to_hdf5(h5group, wf, i)

    h5group.file.flush()
Beispiel #3
0
    def test_json(self):
        lattice = Lattice([16, 8], 2)
        subsystem = CustomSubsystem(lambda site: site.bs[0] == 0 and site.bs[1] < 4, lattice)
        assert (
            json.dumps(subsystem.to_json())
            == '{"type": "CustomSubsystem", "_site_indices": [0, 16, 32, 48, 128, 144, 160, 176]}'
        )

        assert Subsystem.from_json(subsystem.to_json(), lattice) == subsystem
        assert CustomSubsystem.from_json(subsystem.to_json(), lattice) == subsystem
Beispiel #4
0
def test_lattice_json():
    lattice = Lattice([24, 2])
    assert json.dumps(lattice.to_json()) == '{"type": "Lattice", "dimensions": [24, 2], "basis_indices": 1}'
    assert Lattice.from_json(lattice.to_json()) == lattice