def test_rotations_pulse(self): q0 = Transmon("q0", levels=2) q1 = Transmon("q1", levels=3, kerr=-200e-3) q0.gaussian_pulse.sigma = 40 q1.gaussian_pulse.sigma = 40 system = System("system", modes=[q0, q1]) init_state = system.fock() for qubit in [q0, q1]: for _ in range(1): _ = tune_rabi(system, init_state=init_state, mode_name=qubit.name, verify=False) angles = np.linspace(-np.pi, np.pi, 5) for angle in angles: for qubit in [q0, q1]: seq = get_sequence(system) qubit.rotate_x(angle) unitary = qubit.rotate_x(angle, unitary=True) result = seq.run(init_state) fidelity = qutip.fidelity(result.states[-1], unitary * init_state)**2 self.assertGreater(fidelity, 1 - 1e-2) seq = get_sequence(system) qubit.rotate_y(angle) unitary = qubit.rotate_y(angle, unitary=True) result = seq.run(init_state) fidelity = qutip.fidelity(result.states[-1], unitary * init_state)**2 self.assertGreater(fidelity, 1 - 1e-2)
def test_x(self): qubits = self.system.modes result = gates.x(*qubits, unitary=True) self.assertEqual(len(result), len(qubits)) self.assertTrue(all(isinstance(r, qutip.Qobj) for r in result)) for r, q in zip(result, qubits): self.assertEqual(r, q.Rx(np.pi)) result = gates.x(*qubits, capture=False) self.assertEqual(len(result), len(qubits)) self.assertTrue(all(isinstance(r, Operation) for r in result)) for r, q in zip(result, qubits): expected = q.rotate_x(np.pi, capture=False) for channel, info in r.terms.items(): self.assertTrue( np.array_equal(info.coeffs, expected.terms[channel].coeffs) ) _ = get_sequence(self.system) result = gates.x(*qubits) self.assertIsNone(result) result = gates.x(qubits[0], unitary=True) self.assertIsInstance(result, qutip.Qobj)
def test_invalid_sequence(self): system = self.system init_state = system.fock() target_unitary = system.qubit.rotate_x(np.pi, unitary=True) _ = get_sequence(system) system.qubit.rotate_x(np.pi) with self.assertRaises(TypeError): _ = Benchmark(system, init_state, target_unitary)
def test_benchmark_compiled_pulse_sequence(self): system = self.system init_state = system.fock() target_unitary = system.qubit.rotate_x(np.pi, unitary=True) seq = get_sequence(system) system.qubit.rotate_x(np.pi) bm = Benchmark(seq.compile(), init_state, target_unitary) self.assertAlmostEqual(bm.fidelity(), 1) self.assertLess(bm.tracedist(), 1e-5) self.assertAlmostEqual(bm.purity(), 1)
def test_plot_fock_distribution(self): system = self.system init_state = system.fock() target_unitary = system.qubit.rotate_x(np.pi, unitary=True) seq = get_sequence(system) system.qubit.rotate_x(np.pi) bm = Benchmark(seq, init_state, target_unitary) _fig, _ax = plt.subplots() fig, ax = bm.plot_fock_distribution() self.assertIsInstance(fig, type(_fig)) self.assertIsInstance(ax, type(_ax))
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)
def test_rabi_two_levels(self): qubit = Transmon("qubit", levels=2) system = System("system", modes=[qubit]) for _ in range(2): _, old_amp, new_amp = tune_rabi(system, qubit.fock(0)) self.assertLess(abs(old_amp - new_amp), 1e-7) init = qubit.fock(0) seq = get_sequence(system) qubit.rotate_x(np.pi) result = seq.run(init) target = qubit.Rx(np.pi) * init fidelity = qutip.fidelity(result.states[-1], target)**2 self.assertLess(abs(1 - fidelity), 1e-10)
def test_run_sequence_later(self): system = self.system init_state = system.fock() target_unitary = system.qubit.rotate_x(np.pi, unitary=True) seq = get_sequence(system) system.qubit.rotate_x(np.pi) bm = Benchmark(seq, init_state, target_unitary, run_sequence=False) self.assertIsNone(bm.mesolve_state) self.assertIsNone(bm.fidelity()) self.assertIsNone(bm.tracedist()) self.assertIsNone(bm.purity()) bm.run_sequence() self.assertAlmostEqual(bm.fidelity(), 1) self.assertLess(bm.tracedist(), 1e-5) self.assertAlmostEqual(bm.purity(), 1)
def test_drag(self): qubit = Transmon("qubit", levels=3, kerr=-200e-3) qubit.gaussian_pulse.sigma = 10 system = System("system", modes=[qubit]) for _ in range(3): _, old_amp, new_amp = tune_rabi(system, qubit.fock(0), plot=False, verify=False) self.assertLess(abs(old_amp - new_amp), 1e-7) _, old_drag, new_drag = tune_drag(system, qubit.fock(0), update=True) self.assertNotAlmostEqual(new_drag, 0) init = qubit.fock(0) seq = get_sequence(system) qubit.rotate_x(np.pi) result = seq.run(init) target = qubit.Rx(np.pi) * init fidelity = qutip.fidelity(result.states[-1], target)**2 self.assertLess(abs(1 - fidelity), 1e-5)
def test_displacement(self): c0 = Cavity("c0", levels=10, kerr=-10e-6) c1 = Cavity("c1", levels=12, kerr=-10e-6) system = System("system", modes=[c0, c1]) init_state = system.fock() for cavity in [c0, c1]: for _ in range(1): _ = tune_displacement(system, init_state, mode_name=cavity.name, verify=False) for alpha in [0, 1, -1, 1j, -1j, 2, -2, 2j, -2j]: ideal_state = cavity.tensor_with_zero( qutip.coherent(cavity.levels, alpha)) seq = get_sequence(system) unitary = cavity.displace(alpha, unitary=True) cavity.displace(alpha) result = seq.run(init_state) unitary_fidelity = (qutip.fidelity(unitary * init_state, ideal_state)**2) pulse_fidelity = qutip.fidelity(result.states[-1], ideal_state)**2 self.assertGreater(unitary_fidelity, 1 - 1e-4) self.assertGreater(pulse_fidelity, 1 - 1e-4)