def test_basic_pulse(self): """ Test for basic pulse generation and attributes. """ coeff = np.array([0.1, 0.2, 0.3, 0.4]) tlist = np.array([0., 1., 2., 3.]) ham = sigmaz() # Basic tests pulse1 = Pulse(ham, 1, tlist, coeff) assert_allclose( pulse1.get_ideal_qobjevo(2)(0).full(), tensor(identity(2), sigmaz()).full() * coeff[0]) pulse1.tlist = 2 * tlist assert_allclose(pulse1.tlist, 2 * tlist) pulse1.tlist = tlist pulse1.coeff = 2 * coeff assert_allclose(pulse1.coeff, 2 * coeff) pulse1.coeff = coeff pulse1.qobj = 2 * sigmay() assert_allclose(pulse1.qobj.full(), 2 * sigmay().full()) pulse1.qobj = ham pulse1.targets = 3 assert_allclose(pulse1.targets, 3) pulse1.targets = 1 qobjevo = pulse1.get_ideal_qobjevo(2) if parse_version(qutip.__version__) >= parse_version('5.dev'): expected = QobjEvo([tensor(identity(2), sigmaz()), coeff], tlist=tlist, order=0) else: expected = QobjEvo([tensor(identity(2), sigmaz()), coeff], tlist=tlist, args={"_step_func_coeff": True}) _compare_qobjevo(qobjevo, expected, 0, 3)
def TestBasicPulse(): """ Test for basic pulse generation and attributes. """ coeff = np.array([0.1, 0.2, 0.3, 0.4]) tlist = np.array([0., 1., 2., 3.]) ham = sigmaz() # Basic tests pulse1 = Pulse(ham, 1, tlist, coeff) assert_allclose( pulse1.get_ideal_qobjevo(2).ops[0].qobj, tensor(identity(2), sigmaz())) pulse1.tlist = 2 * tlist assert_allclose(pulse1.tlist, 2 * tlist) pulse1.tlist = tlist pulse1.coeff = 2 * coeff assert_allclose(pulse1.coeff, 2 * coeff) pulse1.coeff = coeff pulse1.qobj = 2 * sigmay() assert_allclose(pulse1.qobj, 2 * sigmay()) pulse1.qobj = ham pulse1.targets = 3 assert_allclose(pulse1.targets, 3) pulse1.targets = 1 assert_allclose(pulse1.get_ideal_qobj(2), tensor(identity(2), sigmaz()))