Example #1
0
    def test_json(self):
        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
Example #2
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