def test_save_read(self): """ Test for saving and reading a pulse matrix """ proc = Processor(N=2) proc.add_control(sigmaz(), label="sz") proc.add_control(sigmax(), label="sx") proc1 = Processor(N=2) proc1.add_control(sigmaz(), label="sz") proc1.add_control(sigmax(), label="sx") proc2 = Processor(N=2) proc2.add_control(sigmaz(), label="sz") proc2.add_control(sigmax(), label="sx") # TODO generalize to different tlist tlist = np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5]) amp1 = np.arange(0, 5, 1) amp2 = np.arange(5, 0, -1) proc.set_all_coeffs({ label: amp for label, amp in zip(proc.get_control_labels(), [amp1, amp2]) }) proc.set_all_tlist(tlist) proc.save_coeff("qutip_test_CircuitProcessor.txt") proc1.read_coeff("qutip_test_CircuitProcessor.txt") os.remove("qutip_test_CircuitProcessor.txt") assert_allclose(proc1.get_full_coeffs(), proc.get_full_coeffs()) assert_allclose(proc1.get_full_tlist(), proc.get_full_tlist()) proc.save_coeff("qutip_test_CircuitProcessor.txt", inctime=False) proc2.read_coeff("qutip_test_CircuitProcessor.txt", inctime=False) proc2.set_all_tlist(tlist) os.remove("qutip_test_CircuitProcessor.txt") assert_allclose(proc2.get_full_coeffs(), proc.get_full_coeffs())
def test_save_read(self): """ Test for saving and reading a pulse matrix """ proc = Processor(N=2) proc.add_control(sigmaz(), cyclic_permutation=True) proc1 = Processor(N=2) proc1.add_control(sigmaz(), cyclic_permutation=True) proc2 = Processor(N=2) proc2.add_control(sigmaz(), cyclic_permutation=True) # TODO generalize to different tlist tlist = np.array([0., 0.1, 0.2, 0.3, 0.4, 0.5]) amp1 = np.arange(0, 5, 1) amp2 = np.arange(5, 0, -1) proc.pulses[0].tlist = tlist proc.pulses[0].coeff = amp1 proc.pulses[1].tlist = tlist proc.pulses[1].coeff = amp2 proc.save_coeff("qutip_test_CircuitProcessor.txt") proc1.read_coeff("qutip_test_CircuitProcessor.txt") os.remove("qutip_test_CircuitProcessor.txt") assert_allclose(proc1.get_full_coeffs(), proc.get_full_coeffs()) assert_allclose(proc1.get_full_tlist(), proc.get_full_tlist()) proc.save_coeff("qutip_test_CircuitProcessor.txt", inctime=False) proc2.read_coeff("qutip_test_CircuitProcessor.txt", inctime=False) proc2.set_all_tlist(tlist) os.remove("qutip_test_CircuitProcessor.txt") assert_allclose(proc2.get_full_coeffs(), proc.get_full_coeffs())