def non_herm_model(request): datadir = os.path.splitext(request.module.__file__)[0] w1 = 6000.0 # MHz w2 = 5900.0 # MHz wc = 6200.0 # MHz wd = 5932.5 # MHz alpha1 = -290.0 # MHz alpha2 = -310.0 # MHz g = 70.0 # MHz n_qubit = 5 n_cavity = 6 kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [ 10000.0, ] # MHz gamma = [0.012, 0.024, 0.033, 10000.0] # MHz pulse = QDYN.pulse.Pulse.read(os.path.join(datadir, "pulse.dat")) return model.transmon_model(n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=0.93, pulse=pulse, dissipation_model='non-Hermitian')
def liouville_model(request): datadir = os.path.splitext(request.module.__file__)[0] w1 = 6000.0 # MHz w2 = 5900.0 # MHz wc = 6200.0 # MHz wd = 5932.5 # MHz alpha1 = -290.0 # MHz alpha2 = -310.0 # MHz g = 70.0 # MHz n_qubit = 5 n_cavity = 6 kappa = 0.05 # MHz gamma = 0.012 # MHz pulse = QDYN.pulse.Pulse.read(os.path.join(datadir, "pulse.dat")) gate = QDYN.gate2q.Gate2Q.read(os.path.join(datadir, 'target_gate.dat'), name='O', format='array') return model.transmon_model(n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=0.93, pulse=pulse, dissipation_model='dissipator', gate=gate)
def get_U(pulse, wd, gate=None, J_T=None, dissipation=True, keep_runfolder=None): """Propagate pulse in the given rotating frame, using the non-Hermitian Schrödinger equation, and return the resulting (non-unitary, due to population loss) gate U""" assert 5000 < wd < 7000 assert isinstance(pulse, QDYN.pulse.Pulse) rf = get_temp_runfolder('evaluate_universal_hs') n_qubit = 5 n_cavity = 6 kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [10000.0, ] # MHz gamma = [0.012, 0.024, 0.033, 10000.0] # MHz if not dissipation: kappa = list(np.arange(n_cavity) * 0.0)[1:-1] + [0.0, ] # MHz gamma = [0.0, 0.0, 0.0, 0.0] # MHz if gate is None: gate = GATE['BGATE'] assert isinstance(gate, QDYN.gate2q.Gate2Q) if J_T is None: J_T = 'sm' model = transmon_model( n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=1.0, pulse=pulse, dissipation_model='non-Hermitian', gate=gate, J_T=J_T, iter_stop=1) # write to runfolder model.write_to_runfolder(rf) np.savetxt( os.path.join(rf, 'rwa_vector.dat'), model.rwa_vector, header='rwa vector [MHz]') gate.write(os.path.join(rf, 'target_gate.dat'), format='array') # propagate env = os.environ.copy() env['OMP_NUM_THREADS'] = '4' try: stdout = sp.check_output( ['qdyn_prop_gate', '--internal-units=GHz_units.txt', rf], env=env, universal_newlines=True) except sp.CalledProcessError as exc_info: from IPython.core.debugger import Tracer Tracer()() print(exc_info) # evaluate error for U_t in get_prop_gate_of_t(os.path.join(rf, 'U_over_t.dat')): U = U_t if keep_runfolder is not None: if os.path.isdir(keep_runfolder): rmtree(keep_runfolder) copytree(rf, keep_runfolder) rmtree(rf) return U
def generate_runfolder(rf_orig, rf_new, gate): """Generate runfolder""" w1 = 6000.0 # MHz w2 = 5900.0 # MHz wc = 6200.0 # MHz wd = 5932.5 # MHz alpha1 = -290.0 # MHz alpha2 = -310.0 # MHz g = 70.0 # MHz n_qubit = 5 n_cavity = 6 kappa = 0.0 gamma = 0.0 #kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [10000.0, ] # MHz #gamma = [0.012, 0.024, 0.033, 10000.0] # MHz pulse = Pulse.read(join(rf_orig, "pulse.dat"), freq_unit='MHz') pulse.config_attribs['is_complex'] = True #pulse.config_attribs['oct_spectral_filter'] = 'filter.dat' assert isinstance(gate, Gate2Q) model = transmon_model(n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=1.0, pulse=pulse, dissipation_model='non-Hermitian', gate=gate, iter_stop=9000) model.write_to_runfolder(rf_new) def filter(freq): """Filter to ±200 MHz window. Relies on pulse freq_unit being MHz""" return np.abs(freq) < 200 #pulse.write_oct_spectral_filter(join(rf_new, 'filter.dat'), #filter_func=filter, freq_unit='MHz') np.savetxt(join(rf_new, 'rwa_vector.dat'), model.rwa_vector, header='rwa vector [MHz]') gate.write(join(rf_new, 'target_gate.dat'), format='array')
def evaluate_pulse_rho(pulse, gate, wd, n_qubit=5, n_cavity=6, silent=False): """Propagate pulse in Liouville space""" n_qubit = n_qubit n_cavity = n_cavity kappa = 0.05 # MHz gamma = 0.012 # MHz rf = get_temp_runfolder('evaluate_universal_rho') if isinstance(gate, str): gate = GATE[gate] assert isinstance(gate, QDYN.gate2q.Gate2Q) if not silent: print("preprocessing in %s" % rf) model = transmon_model( n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=1.0, pulse=pulse, dissipation_model='dissipator', gate=gate) # write to runfolder model.write_to_runfolder(rf) np.savetxt( os.path.join(rf, 'rwa_vector.dat'), model.rwa_vector, header='rwa vector [MHz]') gate.write(os.path.join(rf, 'target_gate.dat'), format='array') # propagate if not silent: print("starting propagation in %s" % rf) env = os.environ.copy() env['OMP_NUM_THREADS'] = '16' try: stdout = sp.check_output( ['qdyn_prop_gate', '--rho', '--internal-units=GHz_units.txt', rf], env=env, universal_newlines=True) except sp.CalledProcessError as exc_info: from IPython.core.debugger import Tracer Tracer()() print(exc_info) err = float(re.search(r'1-F_avg\(U, O\)\s*=\s*([Ee.0-9+-]*)', stdout).group(1)) if not silent: print("err_avg = %.4e" % err) return err
def oct_filter_model(request): """Model for optimization with a spectral filter.""" datadir = os.path.splitext(request.module.__file__)[0] w1 = 6000.0 # MHz w2 = 5900.0 # MHz wc = 6200.0 # MHz wd = 5932.5 # MHz alpha1 = -290.0 # MHz alpha2 = -310.0 # MHz g = 70.0 # MHz n_qubit = 5 n_cavity = 6 kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [ 10000.0, ] # MHz gamma = [0.012, 0.024, 0.033, 10000.0] # MHz pulse = QDYN.pulse.Pulse.read(os.path.join(datadir, "pulse.guess"), freq_unit='MHz') pulse.config_attribs['is_complex'] = True pulse.config_attribs['oct_spectral_filter'] = 'filter.dat' gate = QDYN.gate2q.Gate2Q.read(os.path.join(datadir, 'target_gate.dat'), name='O', format='array') return model.transmon_model(n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=1.0, pulse=pulse, dissipation_model='non-Hermitian', gate=gate, iter_stop=1)
def krotov_from_pulse( gate, wd, pulse, iter_stop=100, dissipation=True, ens_pulse_scale=None, freq_window=200, lambda_a=1.0, g_a_int_converged=1.0e-7): """Run a Krotov optimization from the given guess pulse""" n_qubit = 5 n_cavity = 6 kappa = list(np.arange(n_cavity) * 0.05)[1:-1] + [10000.0, ] # MHz gamma = [0.012, 0.024, 0.033, 10000.0] # MHz if not dissipation: kappa = list(np.arange(n_cavity) * 0.0)[1:-1] + [10000.0, ] # MHz gamma = [0.0, 0.0, 0.0, 10000.0] # MHz assert 5000 < wd < 7000 assert isinstance(pulse, QDYN.pulse.Pulse) pulse.config_attribs['is_complex'] = True if freq_window is not None: pulse.config_attribs['oct_spectral_filter'] = 'filter.dat' if isinstance(gate, QDYN.gate2q.Gate2Q): rf = get_temp_runfolder('krotov_O') O = gate gate = 'O' else: rf = get_temp_runfolder('krotov_%s' % gate) O = GATE[gate] J_T = 'sm' if gate == 'BGATE': J_T = 'LI' use_threads = True if ens_pulse_scale is not None: use_threads = (len(ens_pulse_scale) + 1) * 4 model = transmon_model( n_qubit, n_cavity, w1, w2, wc, wd, alpha1, alpha2, g, gamma, kappa, lambda_a=lambda_a, pulse=pulse, dissipation_model='non-Hermitian', gate=O, iter_stop=iter_stop, J_T=J_T, ens_pulse_scale=ens_pulse_scale) model.write_to_runfolder(rf) np.savetxt( os.path.join(rf, 'rwa_vector.dat'), model.rwa_vector, header='rwa vector [MHz]') O.write(os.path.join(rf, 'target_gate.dat'), format='array') def filter(freq): """Filter to ± `freq_window` MHz window.""" return np.abs(freq) < freq_window if freq_window is not None: pulse.write_oct_spectral_filter( os.path.join(rf, 'filter.dat'), filter_func=filter, freq_unit='MHz') print("Runfolder: %s" % rf) run_oct(rf, scratch_root=rf, monotonic=False, use_threads=use_threads, g_a_int_converged=g_a_int_converged) print("Runfolder: %s" % rf) opt_pulse = Pulse.read(os.path.join(rf, "pulse.oct.dat")) err = evaluate_pulse(opt_pulse, O, wd, dissipation=dissipation) print("1-F_avg = %.5e" % err) return opt_pulse