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
def test_custom_subsystem(self): lattice = Lattice([8, 8], 2) subsystem = CustomSubsystem(lambda site: site.bs[0] % 2 == 0, lattice) inside = set() for site in lattice: if site in subsystem: inside.add(site) else: with pytest.raises(ValueError): subsystem.index(site) assert len(inside) == len(subsystem) for i, site in enumerate(subsystem): assert subsystem[i] == site assert subsystem.index(site) == i inside.remove(site) assert len(inside) == 0