def plot_basis_state_populations_3d(e_qs: EvolvingQubitSystem): if e_qs.solve_result is None: e_qs.solve() states = get_states(e_qs.N) times = [] heights = [] xs = [] for i, _solve_result_state in enumerate(e_qs.solve_result.states): plt.ylim(0, 1) plt.grid(axis='y') solve_result_state_populations = np.abs(_solve_result_state.data.toarray().flatten()) ** 2 for _x, state in enumerate(states): state_product_basis_index = get_product_basis_states_index(state) basis_state_population = solve_result_state_populations[state_product_basis_index] times.append(e_qs.solve_result.times[i]) xs.append(_x) heights.append(basis_state_population) fig = plt.figure(figsize=(15, 8)) ax = fig.add_subplot(111, projection="3d") dt = e_qs.solve_result.times[1] - e_qs.solve_result.times[0] ax.bar3d(xs, times, z=0, dx=0.8, dy=dt, dz=heights) labels = [get_label_from_state(state) for state in states] x = np.arange(len(labels)) plt.xticks(x, labels) ax.yaxis.set_major_formatter(ticker.EngFormatter('s')) plt.ylabel('Time') plt.show()
def solve_and_print_stats(e_qs: EvolvingQubitSystem): import time start_time = time.time() e_qs.solve() print(f"Solved in {time.time() - start_time:.2f}s") fidelity_with_ghz = e_qs.get_fidelity_with("ghz") fidelity_with_ghz_asymmetric = e_qs.get_fidelity_with("ghz_antisymmetric") print(f"fidelity with GHZ: {fidelity_with_ghz:.4f} (with antisymmetric: {fidelity_with_ghz_asymmetric:.4f})") fidelity_with_ground = e_qs.get_fidelity_with("ground") fidelity_with_excited = e_qs.get_fidelity_with("excited") superposition_probability = fidelity_with_ground + fidelity_with_excited print( f"superposition probability: {superposition_probability:.4f} (g: {fidelity_with_ground:.4f}, e: {fidelity_with_excited:.4f})") e_qs.plot(with_antisymmetric_ghz=True)
def solve_and_print_stats(e_qs: EvolvingQubitSystem): e_qs.solve() fidelity_with_ghz = e_qs.get_fidelity_with("ghz") fidelity_with_ghz_asymmetric = e_qs.get_fidelity_with("ghz_antisymmetric") print( f"fidelity with GHZ: {fidelity_with_ghz:.4f} (with antisymmetric: {fidelity_with_ghz_asymmetric:.4f})" ) fidelity_with_ground = e_qs.get_fidelity_with("ground") fidelity_with_excited = e_qs.get_fidelity_with("excited") superposition_probability = fidelity_with_ground + fidelity_with_excited print( f"superposition probability: {superposition_probability:.4f} (g: {fidelity_with_ground:.4f}, e: {fidelity_with_excited:.4f})" ) e_qs.plot(with_antisymmetric_ghz=True, savefig_name="evolving_fidelities.png", show=True)
def rescale_evolving_qubit_system(): t = 1.1e-6 N = 4 e_qs = EvolvingQubitSystem( N=N, V=paper_data.V, geometry=RegularLattice1D(), Omega=paper_data.get_hamiltonian_coeff_fn(paper_data.Omega, N), Delta=paper_data.get_hamiltonian_coeff_fn(paper_data.Delta, N), t_list=np.linspace(0, t, 100), ghz_state=AlternatingGHZState(N)) e_qs.solve() # e_qs.plot() print(e_qs.get_fidelity_with("ghz")) max_Omega = 50e6 e_qs = EvolvingQubitSystem( N=N, V=paper_data.V / max_Omega, geometry=RegularLattice1D(), Omega=paper_data.get_hamiltonian_coeff_fn( { k: {_k * max_Omega: _v / max_Omega for _k, _v in v.items()} for k, v in paper_data.Omega.items() }, N), Delta=paper_data.get_hamiltonian_coeff_fn( { k: {_k * max_Omega: _v / max_Omega for _k, _v in v.items()} for k, v in paper_data.Delta.items() }, N), t_list=np.linspace(0, t * max_Omega, 100), ghz_state=AlternatingGHZState(N)) e_qs.solve() e_qs.plot() print(e_qs.get_fidelity_with("ghz"))
def solve_and_print_stats(e_qs: EvolvingQubitSystem, **kwargs): import time start_time = time.time() e_qs.solve() print(f"Solved in {time.time() - start_time:.2f}s") fidelity_with_ghz = e_qs.get_fidelity_with("ghz") fidelity_with_ghz_asymmetric = e_qs.get_fidelity_with("ghz_antisymmetric") print( f"fidelity with GHZ: {fidelity_with_ghz:.4f} (with antisymmetric: {fidelity_with_ghz_asymmetric:.4f})" ) fidelity_with_ground = e_qs.get_fidelity_with("ground") fidelity_with_excited = e_qs.get_fidelity_with("excited") superposition_probability = fidelity_with_ground + fidelity_with_excited print( f"superposition probability: {superposition_probability:.4f} (g: {fidelity_with_ground:.4f}, e: {fidelity_with_excited:.4f})" ) e_qs.plot(with_antisymmetric_ghz=True, **kwargs, fig_kwargs={'figsize': (6, 4)}, plot_titles=False, plot_others_as_sum=True)
def plot_basis_state_populations_2d(e_qs: EvolvingQubitSystem, log=False, log_limit=1e-6): if e_qs.solve_result is None: e_qs.solve() quartile_index = int(len(e_qs.t_list) / 4) indices = [0, quartile_index, quartile_index * 2, quartile_index * 3, -1] states = get_states(e_qs.N) labels = [get_label_from_state(state) for state in states] x = np.arange(len(labels)) fig, axs = plt.subplots(len(indices) , 1, sharex='all', figsize=(10, 8)) for _i, i in enumerate(indices): ax = axs[_i] if not log: ax.set_ylim(0, 1) else: ax.set_ylim(log_limit, 1) ax.set_yscale('log', basey=10) ax.grid(axis='y') ax.set_ylabel(f"{e_qs.solve_result.times[i]:.2e}s") basis_state_populations = [] _solve_result_state = e_qs.solve_result.states[i] solve_result_state_populations = np.abs(_solve_result_state.data.toarray().flatten()) ** 2 for state in states: state_product_basis_index = get_product_basis_states_index(state) basis_state_population = solve_result_state_populations[state_product_basis_index] basis_state_populations.append(basis_state_population) if log: basis_state_population += log_limit ax.bar(x=x, height=basis_state_populations) plt.xticks(x, labels) plt.tight_layout() plt.show()