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())
def test_control_and_coeffs(self): processor = Processor(2) processor.add_control(sigmax()) processor.add_control(sigmaz()) # Set coeffs and tlist without a label coeffs = np.array([[1., 2., 3.], [3., 2., 1.]]) processor.set_coeffs(coeffs) assert_allclose(coeffs, processor.coeffs) tlist = np.array([0., 1., 2., 3.]) processor.set_tlist(tlist) assert_allclose(tlist, processor.get_full_tlist()) processor.set_tlist({0: tlist, 1: tlist}) assert_allclose(tlist, processor.get_full_tlist()) # Pulses assert (len(processor.pulses) == 2) assert (processor.find_pulse(0) == processor.pulses[0]) assert (processor.find_pulse(1) == processor.pulses[1]) with pytest.raises(KeyError): processor.find_pulse("non_exist_pulse")