def test_use_modes(self): qubit = Transmon("qubit", levels=3, kerr=-200e-3) cavity = Cavity("cavity", levels=10, kerr=-10e-6) system = System("system", modes=[qubit, cavity]) with system.use_modes([qubit]): self.assertEqual(system.ground_state(), qubit.fock(0, full_space=False)) with system.use_modes([cavity]): self.assertEqual(system.ground_state(), cavity.fock(0, full_space=False)) with system.use_modes([qubit, cavity]): self.assertEqual( system.ground_state(), qutip.tensor( qubit.fock(0, full_space=False), cavity.fock(0, full_space=False) ), ) system.order_modes = False with system.use_modes([cavity, qubit]): self.assertEqual( system.ground_state(), qutip.tensor( cavity.fock(0, full_space=False), qubit.fock(0, full_space=False) ), )
def test_displacement(self): cavity = Cavity("cavity", levels=12) system = System("system", modes=[cavity]) for _ in range(3): _, old_amp, new_amp = tune_displacement(system, cavity.fock(0)) self.assertLess(abs(old_amp - new_amp), 1e-7) init = cavity.fock(0) seq = get_sequence(system) cavity.displace(1 + 2j) result = seq.run(init) target = cavity.D(1 + 2j) * init fidelity = qutip.fidelity(result.states[-1], target)**2 self.assertLess(abs(1 - fidelity), 1e-7)