def _compute_propagator(processor, circuit): qevo, _ = processor.get_qobjevo(noisy=True) if parse_version(qutip.__version__) < parse_version("5.dev"): qevo = qevo.to_list() result = qutip.propagator(qevo, t=processor.get_full_tlist())[-1] else: result = qutip.propagator(qevo, t=processor.get_full_tlist(), parallel=False)[-1] return result
def evolution_operator_microwave_diss( H_nodrive, H_drive, t_points=None, c_ops = [], parallel=False, **kwargs): """ Calculates the unitary evolution operator for a gate activated by a microwave drive. Parameters ---------- H_nodrive : :class:`qutip.Qobj` The Hamiltonian without the drive term. H_drive : :class:`qutip.Qobj` The time-independent part of the driving term. Example: f * (a + a.dag()) or f * qubit.n() Normalization: see `H_drive_coeff_gate` function. t_points : *array* of float (optional) Times at which the evolution operator is returned. If None, it is generated from `kwargs['T_gate']`. parallel : True or False Run the qutip propagator function in parallel mode **kwargs: Contains gate parameters such as pulse shape and gate time. Returns ------- U_t : *array* of :class:`qutip.Qobj` The evolution operator at time(s) defined in `t_points`. """ if t_points is None: T_gate = kwargs['T_gate'] t_points = np.linspace(0, T_gate, 2 * int(T_gate) + 1) H = [2 * np.pi * H_nodrive, [H_drive, H_drive_coeff_gate]] U_t = qt.propagator(H, t_points, c_ops_list=c_ops, args=kwargs, parallel=parallel) return U_t
def _integrate(L, E0, ti, tf, integrator='propagator', parallel=False, opt=qt.Options()): """ Basic ode integrator """ if tf > ti: if integrator == 'mesolve': if parallel: warnings.warn('parallelization not implemented for "mesolve"') opt.store_final_state = True sol = qt.mesolve(L, E0, [ti, tf], [], [], options=opt) return sol.final_state elif integrator == 'propagator': return qt.propagator( L, (tf - ti), [], [], parallel=parallel, options=opt) * E0 else: raise ValueError('integrator keyword must be either "propagator"' + 'or "mesolve"') else: return E0
def test_offresonant_adiabatic_CZ(self): alpha_q0 = 250e6 * 2 * np.pi J = 2.5e6 * 2 * np.pi w_q0 = 6e9 * 2 * np.pi w_q1 = w_q0 + alpha_q0 * 1.05 H_0 = czu.coupled_transmons_hamiltonian(w_q0, w_q1, alpha_q0=alpha_q0, J=J) tlist = np.arange(0, 150e-9, .1e-9) U_t = qtp.propagator(H_0, tlist) time_idx = [0, 500, 1000] # 0, 50 and 100ns phases = np.asanyarray([ czu.phases_from_unitary( czu.rotating_frame_transformation(U_t[t_idx], tlist[t_idx], w_q0, w_q1)) for t_idx in time_idx ]) np.testing.assert_almost_equal(phases[0, 3], 0, decimal=-1) np.testing.assert_almost_equal(phases[1, 3], -20, decimal=-1) np.testing.assert_almost_equal(phases[2, 3], -32, decimal=-1)
def __init__(self): super(TestBloch, self).__init__() self.propagator = propagator(sigmaz(), .1, []) self.set_state(qeye(2) + sigmax()) self.timer = QtCore.QTimer() self.timer.setInterval(100) self.timer.timeout.connect(self.propagate) self.timer.start()
def evolution_operator_microwave_long(system, H_drive, t_points=None, parallel=False, **kwargs): if t_points is None: T_gate = kwargs['T_gate'] t_points = np.linspace(0, T_gate, 2 * int(T_gate) + 1) H_nodrive = system.H() H = [2 * np.pi * H_nodrive, [H_drive, H_drive_coeff_gate_long]] U_t = qt.propagator(H, t_points, [], args=kwargs, parallel=parallel) return U_t
def time_evolution(self, T=None, ode_options={}): ''' Computes times evolution of the system ''' # -- get parameters delta = self.global_detuning if T is None: T_end = [p.time_offset + p.pulse_duration for p in self.pulse_list] T_end = np.max(T_end) T = np.linspace(0, T_end, 200) # -- compute # free Hamiltonian H0 = 0.5 * delta * qt.sigmaz() # pulses H = [H0] Hr_imag = 0.5 * qt.sigmay() Hr_real = 0.5 * qt.sigmax() for pulse in self.pulse_list: H.append([Hr_real, pulse._pulse_real]) H.append([Hr_imag, pulse._pulse_imag]) # decoherence if self.decoherence_rate != 0: gamma = self.decoherence_rate c_ops = [np.sqrt(0.5 * gamma) * qt.sigmaz()] else: c_ops = [] # propagator U = qt.propagator(H, T, c_op_list=c_ops, options=ode_options) # -- get phase and amplitude amp = {} phase = {} for i in [0, 1]: for j in [0, 1]: key = '%i%i' % (i, j) amp[key] = np.array([np.abs(u[i, j])**2 for u in U]) phase[key] = np.array([np.angle(u[i, j]) for u in U]) phase['R'] = phase['01'] - phase['10'] phase['T'] = phase['00'] - phase['11'] amp['R'] = amp['01'] amp['T'] = amp['00'] result = {'amplitude': amp, 'phase': phase, 'time': T} return result
def test2(): N = 6 U0 = qeye(N) U0np = np.array(U0.full()) H0 = rand_herm(N) H0np = np.array(H0.full()) def Ht(t, *args): return H0 * t def Htnp(t, *args): return H0np * t T = np.pi U1 = getUnitary(U0np, Htnp, T) U2 = propagator(Ht, T).full() diff = np.mean(np.abs(U1 - U2)) print(diff)
def simulate_quantities_of_interest(H_0, tlist, eps_vec, sim_step: float=0.1e-9, verbose: bool=True): """ Calculates the quantities of interest from the propagator U Args: H_0 (Qobj): static hamiltonian, see "coupled_transmons_hamiltonian" for the expected form of the Hamiltonian. tlist (array): times in s, describes the x component of the trajectory to simulate eps_vec(array): detuning describes the y-component of the trajectory to simulate. Returns phi_cond (float): conditional phase (deg) L1 (float): leakage L2 (float): seepage # TODO: return the Fidelity in the comp subspace with and without correcting for phase errors. """ eps_interp = interp1d(tlist, eps_vec, fill_value='extrapolate') # function only exists to wrap def eps_t(t, args=None): return eps_interp(t) H_c = n_q0 H_t = [H_0, [H_c, eps_t]] tlist_sim = (np.arange(0, np.max(tlist), sim_step)) t0 = time.time() U_t = qtp.propagator(H_t, tlist_sim) t1 = time.time() if verbose: print('simulation took {:.2f}s'.format(t1-t0)) U_final = U_t[-1] phases = phases_from_unitary(U_final) phi_cond = phases[-1] L1 = leakage_from_unitary(U_final) L2 = seepage_from_unitary(U_final) return {'phi_cond': phi_cond, 'L1': L1, 'L2': L2}
def task(w, H, c): T = 200 Hdr_p = (0.0001 * 2 * np.pi) * c.dag() Hdr_m = (0.0001 * 2 * np.pi) * c Hargs = {'H0': H, 'wd': w, 'Hdr_p': Hdr_p, 'Hdr_m': Hdr_m} U = qt.propagator(H_t, T, c_ops, Hargs) rho_ss = qt.propagator_steadystate(U) I = (1 / np.sqrt(2)) * (c + c.dag()) Q = (1j / np.sqrt(2)) * (c - c.dag()) Iavg = qt.expect(I, rho_ss) Qavg = qt.expect(Q, rho_ss) Mag = np.sqrt(Iavg**2 + Qavg**2) try: Phase = np.arctan2(Iavg, Qavg) * 180 / np.pi except: Phase = np.nan Pow = qt.expect(I**2 + Q**2, rho_ss) return [Pow, Mag, Phase]
def test_rotating_frame(self): w_q0 = 5e9 w_q1 = 6e9 H_0 = czu.coupled_transmons_hamiltonian(5e9, 6e9, alpha_q0=.1, J=0) tlist = np.arange(0, 10e-9, .1e-9) U_t = qtp.propagator(H_0, tlist) for t_idx in [3, 5, 11]: # with rotating term, single qubit terms have phase U = U_t[t_idx] self.assertTrue(abs(np.angle(U[1, 1])) > .1) self.assertTrue(abs(np.angle(U[3, 3])) > .1) U = czu.rotating_frame_transformation(U_t[t_idx], tlist[t_idx], w_q0=w_q0, w_q1=w_q1) # after removing rotating term, single qubit terms have static phase self.assertTrue(abs(np.angle(U[1, 1])) < .1) self.assertTrue(abs(np.angle(U[3, 3])) < .1)
def _integrate(L, E0, ti, tf, integrator='propagator', parallel=False, opt=qt.Options()): """ Basic ode integrator """ if tf > ti: if integrator == 'mesolve': if parallel: warnings.warn('parallelization not implemented for "mesolve"') opt.store_final_state = True sol = qt.mesolve(L, E0, [ti, tf], [], [], options=opt) return sol.final_state elif integrator == 'propagator': return qt.propagator(L, (tf-ti), [], [], parallel=parallel, options=opt)*E0 else: raise ValueError('integrator keyword must be either "propagator"' + 'or "mesolve"') else: return E0
def propagator(self, T=None, free=False, ode_options={}): ''' Computes the propagator (evolution operator) for the pulse ''' # -- get parameters delta = self.global_detuning if T is None: T_end = [p.time_offset + p.pulse_duration for p in self.pulse_list] T = np.max(T_end) msg = 'No time provided, use total duration (T=%.2f)' % T self._p(msg) # -- define Hamiltonian # free Hamiltonian H0 = 0.5 * delta * qt.sigmaz() # pulses if not free: H = [H0] Hr_imag = 0.5 * qt.sigmay() Hr_real = 0.5 * qt.sigmax() for pulse in self.pulse_list: H.append([Hr_real, pulse._pulse_real]) H.append([Hr_imag, pulse._pulse_imag]) else: H = H0 # decoherence if self.decoherence_rate != 0: # FIXME: not working yet gamma = self.decoherence_rate c_ops = [np.sqrt(0.5 * gamma) * qt.sigmaz()] else: c_ops = [] # -- compute propagator and return U = qt.propagator(H, T, c_op_list=c_ops, options=qt.Options(**ode_options)) return U
def evolution_operator_microwave(system, H_drive, t_points=None, parallel=False, **kwargs): """ Calculates the evolution operator for the gate activated by a microwave drive. Parameters ---------- system : :class:`coupobj.CoupledObjects` or similar An object of a quantum system supporting system.H() method for the Hamiltonian. H_drive : :class:`qutip.Qobj` The time-independent part of the driving term. Example: f * (a + a.dag()) or f * qubit.n() Normalization: see `H_drive_coeff_gate` function. t_points : *array* of float (optional) Times at which the evolution operator is returned. If None, it is generated from `kwargs['T_gate']`. parallel : True or False Run the qutip propagator function in parallel mode **kwargs: Contains gate parameters such as pulse shape and gate time. Returns ------- U_t : *array* of :class:`qutip.Qobj` The evolution operator at time(s) defined in `t_points` written in the basis used by `system`. """ if t_points is None: T_gate = kwargs['T_gate'] t_points = np.linspace(0, T_gate, 2 * int(T_gate) + 1) H_nodrive = system.H() H = [2 * np.pi * H_nodrive, [H_drive, H_drive_coeff_gate]] U_t = qt.propagator(H, t_points, [], args=kwargs, parallel=parallel) return U_t
def transmission(omega, ampD, ampP): # omega[0]: cavity drive frequency # omega[1]: flux pump frequency # ampD: cavity drive amplitude # ampP: flux pump frequency # Returns: expectation value of adag*a of the steady state omegaD = omega[0] omegaP = omega[1] Ht = [(omegaR - omegaD) * adag * a + (omegaQ - omegaD) / 2 * sz + g * (adag * sm + a * sp) + ampD * (a + adag), [ampP * sz, lambda t, args: np.sin(args['omegaP'] * t)]] # Calculate propagator for one pump period T = 2pi/omegaP U = qt.propagator(H=Ht, t=2 * np.pi / omegaP, c_op_list=[np.sqrt(kappa) * a, np.sqrt(gamma) * sm], args={'omegaP': omegaP}) # Calucate steady state density matrix rhoss = qt.propagator_steadystate(U) # Return photon number for steady state return np.real(qt.expect(adag * a, rhoss))
def prop(self, tf, ti): """Compute U[t2,t1] where t2 > t1 or return the cached operator. Parameters ---------- tf : float Final time to compute the propagator U[tf, ti]. ti : float Initial time to compute the propagator U[tf,ti]. Returns ------- propagator : :class: qutip.Qobj The propagation operator. """ left, right = np.searchsorted(self.tlist, [ti, tf], side='left') t1, t2 = self.tlist[left], self.tlist[right] if self.propagators[t2][t1] is None: self.propagators[t2][t1] = propagator(self.H, [t1, t2], options=self.options, unitary_mode='single') # Something is still broken about batch unitary mode (see #807) return self.propagators[t2][t1]
def test_resonant_sudden_CZ(self): alpha_q0 = 250e6 * 2 * np.pi J = 2.5e6 * 2 * np.pi w_q0 = 6e9 * 2 * np.pi w_q1 = w_q0 + alpha_q0 H_0 = czu.coupled_transmons_hamiltonian(w_q0, w_q1, alpha_q0=alpha_q0, J=J) tlist = np.arange(0, 150e-9, .1e-9) U_t = qtp.propagator(H_0, tlist) time_idx = [0, 500, 1000] # 0, 50 and 100ns # time_idx = range(len(tlist)) phases = np.asanyarray([ czu.phases_from_unitary( czu.rotating_frame_transformation(U_t[t_idx], tlist[t_idx], w_q0, w_q1)) for t_idx in time_idx ]) # f, ax = plt.subplots() # ax.plot(tlist, phases[:,0], label='Phi_00') # ax.plot(tlist, phases[:,1], label='Phi_01') # ax.plot(tlist, phases[:,2], label='Phi_10') # ax.plot(tlist, phases[:,3], label='Phi_11') # ax.plot(tlist, phases[:,4], label='Phi_cond') # ax.legend() # plt.show() np.testing.assert_almost_equal(phases[0, 3], 0, decimal=-1) np.testing.assert_almost_equal(phases[1, 3], 0, decimal=-1) np.testing.assert_almost_equal(phases[2, 3], 180, decimal=-1)
def test_time_dependent_fast_adiabatic_pulse(self): # Hamiltonian pars alpha_q0 = 250e6 * 2 * np.pi J = 2.5e6 * 2 * np.pi w_q0 = 6e9 * 2 * np.pi w_q1 = 7e9 * 2 * np.pi H_0 = czu.coupled_transmons_hamiltonian(w_q0, w_q1, alpha_q0=alpha_q0, J=J) # Parameters f_interaction = w_q0 + alpha_q0 f_01_max = w_q1 length = 240e-9 sampling_rate = 2.4e9 lambda_2 = 0 lambda_3 = 0 V_per_phi0 = 2 E_c = 250e6 theta_f = 85 J2 = J * np.sqrt(2) tlist = (np.arange(0, length, 1 / sampling_rate)) f_pulse = martinis_flux_pulse(length, lambda_2=lambda_2, lambda_3=lambda_3, theta_f=theta_f, f_01_max=f_01_max, E_c=E_c, V_per_phi0=V_per_phi0, f_interaction=f_interaction, J2=J2, return_unit='f01', sampling_rate=sampling_rate) eps_vec = f_pulse - w_q1 def eps_t(t, args=None): idx = np.argmin(abs(tlist - t)) return float(eps_vec[idx]) H_c = czu.n_q1 H_t = [H_0, [H_c, eps_t]] # Calculate the trajectory t0 = time.time() U_t = qtp.propagator(H_t, tlist) t1 = time.time() print('simulation took {:.2f}s'.format(t1 - t0)) test_indices = range(len(tlist))[::50] phases = np.asanyarray([ czu.phases_from_unitary( czu.rotating_frame_transformation(U_t[t_idx], tlist[t_idx], w_q0, w_q1)) for t_idx in test_indices ]) t2 = time.time() print('Extracting phases took {:.2f}s'.format(t2 - t1)) cond_phases = phases[:, 4] expected_phases = np.array([ 0., 356.35610703, 344.93107947, 326.69596131, 303.99108914, 279.5479871, 254.95329258, 230.67722736, 207.32417721, 186.68234108, 171.38527544, 163.55444707 ]) np.testing.assert_array_almost_equal(cond_phases, expected_phases) L1 = [czu.leakage_from_unitary(U_t[t_idx]) for t_idx in test_indices] L2 = [czu.seepage_from_unitary(U_t[t_idx]) for t_idx in test_indices] expected_L1 = np.array([ 0.0, 0.026757049282008727, 0.06797292824458401, 0.09817896580396734, 0.11248845556751286, 0.11574586085284067, 0.11484563049326857, 0.11243390482702287, 0.1047153697736567, 0.08476542786503238, 0.04952861565413047, 0.00947869831231718 ]) # This condition holds for unital (and unitary) processes and depends # on the dimension of the subspace see Woods Gambetta 2018 expected_L2 = 2 * expected_L1 np.testing.assert_array_almost_equal(L1, expected_L1) np.testing.assert_array_almost_equal(L2, expected_L2)
Hq2_t_ind = qt.tensor(Iq1, rot2) #Hq2_rot(constant term) Hq2_t_dep = qt.tensor(Iq1, q2Freqs) #Hq2_rot(modulation term) Hint = QQ.Hint12 * (2 * pi) H_rot = [Hq1_lab + Hq2_t_ind + Hint, [Hq2_t_dep, MW_shaped]] tgstart = 48 tgend = 48 for gt in range(tgstart, tgend + 1): pulsesystem = CZpulse(Q1, Q2, g, the_f=0.88, lambda2=0.13, gatetime=gt) tg = pulsesystem.tg t_list, adiabaticpulse = pulsesystem.netzeropulse() degeneracy_freq = pulsesystem.qFreq20 args = {'mwamp': 1.0, 'shape': adiabaticpulse} #res = qt.sesolve(H_rot, ini_state, t_list, e_ops=[], args=args, options=opts, progress_bar=None) _res = qt.propagator(H_rot, t_list, e_ops=[], args=args, options=opts, progress_bar=None) res = [] for i in range(len(_res)): sp = qt.to_super(_res[i]) res.append(sp) res = np.array(res) print(len(res)) print(res[1].dims) print(res[1].shape)