def get_noisy_dynamics(self, dims): """ Return a list of Pulse object with only trivial ideal pulse (H=0) but non-trivial lindblad noise. Parameters ---------- dims: list, optional The dimension of the components system, the default value is [2,2...,2] for qubits system. Returns ------- lindblad_noise: list of :class:`qutip.qip.Pulse` A list of Pulse object with only trivial ideal pulse (H=0) but non-trivial lindblad noise. """ if isinstance(dims, list): N = len(dims) else: N = dims # time-independent if (self.coeff is None) and (self.tlist is None): self.coeff = True lindblad_noise = Pulse(None, None) for c_op in self.c_ops: if self.all_qubits: for targets in range(N): lindblad_noise.add_lindblad_noise(c_op, targets, self.tlist, self.coeff) else: lindblad_noise.add_lindblad_noise(c_op, self.targets, self.tlist, self.coeff) return lindblad_noise
def TestPulseConstructor(): """ Test for creating empty Pulse, Pulse with constant coefficients etc. """ coeff = np.array([0.1, 0.2, 0.3, 0.4]) tlist = np.array([0., 1., 2., 3.]) ham = sigmaz() # Special ways of initializing pulse pulse2 = Pulse(sigmax(), 0, tlist, True) assert_allclose(pulse2.get_ideal_qobjevo(2).ops[0].qobj, tensor(sigmax(), identity(2))) pulse3 = Pulse(sigmay(), 0) assert_allclose(pulse3.get_ideal_qobjevo(2).cte.norm(), 0.) pulse4 = Pulse(None, None) # Dummy empty ham assert_allclose(pulse4.get_ideal_qobjevo(2).cte.norm(), 0.) tlist_noise = np.array([1., 2.5, 3.]) coeff_noise = np.array([0.5, 0.1, 0.5]) tlist_noise2 = np.array([0.5, 2, 3.]) coeff_noise2 = np.array([0.1, 0.2, 0.3]) # Pulse with different dims random_qobj = Qobj(np.random.random((3, 3))) pulse5 = Pulse(sigmaz(), 1, tlist, True) pulse5.add_coherent_noise(sigmay(), 1, tlist_noise, coeff_noise) pulse5.add_lindblad_noise( random_qobj, 0, tlist=tlist_noise2, coeff=coeff_noise2) qu, c_ops = pulse5.get_noisy_qobjevo(dims=[3, 2]) assert_allclose(qu.ops[0].qobj, tensor([identity(3), sigmaz()])) assert_allclose(qu.ops[1].qobj, tensor([identity(3), sigmay()])) assert_allclose(c_ops[0].ops[0].qobj, tensor([random_qobj, identity(2)]))
def get_noisy_dynamics(self, dims): """ Return a list of Pulse object with only trivial ideal pulse (H=0) but non-trivial relaxation noise. Parameters ---------- dims: list, optional The dimension of the components system, the default value is [2,2...,2] for qubits system. Returns ------- lindblad_noise: list of :class:`qutip.qip.Pulse` A list of Pulse object with only trivial ideal pulse (H=0) but non-trivial relaxation noise. """ if isinstance(dims, list): for d in dims: if d != 2: raise ValueError( "Relaxation noise is defined only for qubits system") N = len(dims) else: N = dims self.t1 = self._T_to_list(self.t1, N) self.t2 = self._T_to_list(self.t2, N) if len(self.t1) != N or len(self.t2) != N: raise ValueError( "Length of t1 or t2 does not match N, " "len(t1)={}, len(t2)={}".format( len(self.t1), len(self.t2))) lindblad_noise = Pulse(None, None) if self.targets is None: targets = range(N) else: targets = self.targets for qu_ind in targets: t1 = self.t1[qu_ind] t2 = self.t2[qu_ind] if t1 is not None: op = 1/np.sqrt(t1) * destroy(2) lindblad_noise.add_lindblad_noise(op, qu_ind, coeff=True) if t2 is not None: # Keep the total dephasing ~ exp(-t/t2) if t1 is not None: if 2*t1 < t2: raise ValueError( "t1={}, t2={} does not fulfill " "2*t1>t2".format(t1, t2)) T2_eff = 1./(1./t2-1./2./t1) else: T2_eff = t2 op = 1/np.sqrt(2*T2_eff) * sigmaz() lindblad_noise.add_lindblad_noise(op, qu_ind, coeff=True) return lindblad_noise
def get_noisy_dynamics(self, dims=None, pulses=None, systematic_noise=None): if systematic_noise is None: systematic_noise = Pulse(None, None, label="system") N = len(dims) # time-independent if (self.coeff is None) and (self.tlist is None): self.coeff = True for c_op in self.c_ops: if self.all_qubits: for targets in range(N): systematic_noise.add_lindblad_noise( c_op, targets, self.tlist, self.coeff) else: systematic_noise.add_lindblad_noise(c_op, self.targets, self.tlist, self.coeff) return pulses, systematic_noise
def TestNoisyPulse(): """ Test for lindblad noise and different tlist """ coeff = np.array([0.1, 0.2, 0.3, 0.4]) tlist = np.array([0., 1., 2., 3.]) ham = sigmaz() pulse1 = Pulse(ham, 1, tlist, coeff) # Add coherent noise and lindblad noise with different tlist pulse1.spline_kind = "step_func" tlist_noise = np.array([1., 2.5, 3.]) coeff_noise = np.array([0.5, 0.1, 0.5]) pulse1.add_coherent_noise(sigmay(), 0, tlist_noise, coeff_noise) tlist_noise2 = np.array([0.5, 2, 3.]) coeff_noise2 = np.array([0.1, 0.2, 0.3]) pulse1.add_lindblad_noise(sigmax(), 1, coeff=True) pulse1.add_lindblad_noise( sigmax(), 0, tlist=tlist_noise2, coeff=coeff_noise2) assert_allclose( pulse1.get_ideal_qobjevo(2).ops[0].qobj, tensor(identity(2), sigmaz())) noise_qu, c_ops = pulse1.get_noisy_qobjevo(2) assert_allclose(noise_qu.tlist, np.array([0., 0.5, 1., 2., 2.5, 3.])) for ele in noise_qu.ops: if ele.qobj == tensor(identity(2), sigmaz()): assert_allclose( ele.coeff, np.array([0.1, 0.1, 0.2, 0.3, 0.3, 0.4])) elif ele.qobj == tensor(sigmay(), identity(2)): assert_allclose( ele.coeff, np.array([0., 0., 0.5, 0.5, 0.1, 0.5])) for c_op in c_ops: if len(c_op.ops) == 0: assert_allclose(c_ops[0].cte, tensor(identity(2), sigmax())) else: assert_allclose( c_ops[1].ops[0].qobj, tensor(sigmax(), identity(2))) assert_allclose( c_ops[1].tlist, np.array([0., 0.5, 1., 2., 2.5, 3.])) assert_allclose( c_ops[1].ops[0].coeff, np.array([0., 0.1, 0.1, 0.2, 0.2, 0.3]))
def get_noisy_dynamics(self, dims=None, pulses=None, systematic_noise=None): if systematic_noise is None: systematic_noise = Pulse(None, None, label="system") N = len(dims) self.t1 = self._T_to_list(self.t1, N) self.t2 = self._T_to_list(self.t2, N) if len(self.t1) != N or len(self.t2) != N: raise ValueError("Length of t1 or t2 does not match N, " "len(t1)={}, len(t2)={}".format( len(self.t1), len(self.t2))) if self.targets is None: targets = range(N) else: targets = self.targets for qu_ind in targets: t1 = self.t1[qu_ind] t2 = self.t2[qu_ind] if t1 is not None: op = 1 / np.sqrt(t1) * destroy(dims[qu_ind]) systematic_noise.add_lindblad_noise(op, qu_ind, coeff=True) if t2 is not None: # Keep the total dephasing ~ exp(-t/t2) if t1 is not None: if 2 * t1 < t2: raise ValueError("t1={}, t2={} does not fulfill " "2*t1>t2".format(t1, t2)) T2_eff = 1. / (1. / t2 - 1. / 2. / t1) else: T2_eff = t2 op = 1 / np.sqrt(2 * T2_eff) * 2 * num(dims[qu_ind]) systematic_noise.add_lindblad_noise(op, qu_ind, coeff=True) return pulses, systematic_noise