def test_to_from_json_str(self): qubit = Transmon("qubit", levels=3, kerr=-200e-3) cavity = Cavity("cavity", levels=10, kerr=-10e-6) system = System("system", modes=[qubit, cavity]) system.set_cross_kerr(qubit, cavity, chi=-2e-3) json_str = system.to_json(dumps=True) other_system = System.from_json(json_str=json_str) self.assertEqual(system, other_system)
def test_to_from_json_file(self): qubit = Transmon("qubit", levels=3, kerr=-200e-3) cavity = Cavity("cavity", levels=10, kerr=-10e-6) system = System("system", modes=[qubit, cavity]) system.set_cross_kerr(qubit, cavity, chi=-2e-3) with tempfile.TemporaryDirectory() as dirname: json_path = os.path.join(dirname, "__test_to_from_json_file.json") system.to_json(json_path=json_path) other_system = System.from_json(json_path=json_path) self.assertEqual(system, other_system)