def evolve(L, Lx, T, dt, R, r, V, IC, BC, E=0, totalistic=False, hamiltonian=False, symmetric=False, initstate=None, **kwargs): """ Generator of qca dynamics yields state at each time step """ if Lx == 1: d = 1 elif Lx > 1: assert Lx < L d = 2 Ly = int(L/Lx) Us = rule_unitaries(V, R, r, d, BC, dt, totalistic=totalistic, hamiltonian=hamiltonian) ts = np.arange(dt, T + dt, dt) if initstate is None: initstate = make_state(L, IC) yield initstate state = initstate get_U = get_Ufunc(Us, Ly, Lx, r, d, BC) for t in ts: for s in range(r+1): for i in range(s, L): j, k = np.unravel_index(i, (Ly, Lx)) if (j+k) % (r+1) == s: Nj, u = get_U(j, k) state = mx.op_on_state(u, Nj, state) yield state
def time_evolve(U): psi = make_state(L, "c1_f0") ts = np.arange(0, 60, dt) zs = np.zeros((len(ts), L)) ss = np.zeros((len(ts), L)) fig, axs = plt.subplots(1, 2, figsize=(6, 8)) for ti, t in enumerate(ts): rhos = ms.get_local_rhos(psi) zs[ti, :] = ms.local_exp_vals_from_rhos(rhos, ops["Z"]) ss[ti, :] = ms.local_entropies_from_rhos(rhos, order=2) psi = U.dot(psi) axs[0].imshow(zs, origin="lower", interpolation=None) axs[0].set_title(r"$\langle \sigma_z \rangle$") axs[0].set_ylabel("$t$") axs[0].set_xlabel("$j$") axs[0].xaxis.set_major_locator(MaxNLocator(integer=True)) axs[1].imshow(ss, origin="lower", interpolation=None) axs[1].set_yticks([]) axs[1].set_title(r"$s_2$") axs[1].set_xlabel("$j$") axs[1].xaxis.set_major_locator(MaxNLocator(integer=True)) fig.subplots_adjust(top=0.8) fig.tight_layout()
def get_time_step_gen(params): L, T, V, r, S, M, IC, BC_type, BC_conf = validate_params(params) state = ss.make_state(L, IC) mode_list = get_mode(M, L) lUs, U, rUs = get_Us(V, r, S, BC_conf) time_step_gen = gen_time_step(state, U, lUs, rUs, mode_list, L, T, r, BC_type) return time_step_gen
row = a_row * b_nrows + b_row col = a_col * a_ncols + b_col M[(row, col)] = a_val * b_val return M if __name__ == "__main__": import states as ss L = 7 IC = "f0-3" js = [2, 0, 3] op = listkron([ops["X"]] * (len(js) - 1) + [ops["H"]]) print() print("op = XXH,", "js = ", str(js) + ", ", "IC = ", IC) print() init_state3 = ss.make_state(L, IC) init_rj = [rdms(init_state3, [j]) for j in range(L)] init_Z_exp = [np.trace(r.dot(ops["Z"]).real) for r in init_rj] init_Y_exp = [np.trace(r.dot(ops["Y"]).real) for r in init_rj] print("initial Z exp vals:", init_Z_exp) print("initial Y exp vals:", init_Y_exp) final_state = op_on_state(op, js, init_state3) final_rj = [rdms(final_state, [j]) for j in range(L)] final_Z_exp = [np.trace(r.dot(ops["Z"])).real for r in final_rj] final_Y_exp = [np.trace(r.dot(ops["Y"])).real for r in final_rj] print("final Z exp vals:", final_Z_exp) print("final Y exp vals:", final_Y_exp) # okay decompiling matrix.cpython-37.pyc
def evolve(L, T, dt, R, r, V, IC, BC, E=0, totalistic=False, hamiltonian=False, symmetric=False, trotter=True, initstate=None, **kwargs): """ Generator of qca dynamics yields state at each time step """ Us = rule_unitaries(V, R, r, BC, L, dt, totalistic=totalistic, hamiltonian=hamiltonian, trotter=trotter) ts = np.arange(dt, T + dt, dt) if initstate is None: initstate = make_state(L, IC) yield initstate state = initstate if not trotter: u = Us for t in ts: state = u.dot(state) yield state else: # trotter get_U = get_Ufunc(Us, r, L, BC) if symmetric: sqrtUs = [[fractional_matrix_power(u, 0.5) for u in us] for us in (Us[0], Us[2])] sqrtUs = (sqrtUs[0], fractional_matrix_power(Us[1], 0.5), sqrtUs[1]) get_sqrtU = get_Ufunc(sqrtUs, r, L, BC) for t in ts: # forward for k in range(r): for j in range(k, L, r + 1): Nj, u = get_sqrtU(j) state = mx.op_on_state(u, Nj, state) state = depolarize(state, Nj, E) # center for j in range(r, L, r + 1): Nj, u = get_U(j) state = mx.op_on_state(u, Nj, state) state = depolarize(state, Nj, E) # backward for k in range(r - 1, -1, -1): for j in range(k, L, r + 1): Nj, u = get_sqrtU(j) state = mx.op_on_state(u, Nj, state) state = depolarize(state, Nj, E) yield state else: # not symmetric for t in ts: for k in range(r + 1): for j in range(k, L, r + 1): Nj, u = get_U(j) state = mx.op_on_state(u, Nj, state) state = depolarize(state, Nj, E) yield state
for t in [10, 50, 100, 500, 1000]: fig, axs = plt.subplots(1, 8, figsize=(4.75, 0.8)) for col, R in enumerate(Rkey): sim = select(L=18, S=R, IC="c1_f0", V="H", BC="0") if sim is None: print("No sim!") L = sim["L"] h5file = sim["h5file"] Ms = h5file["MI"] M = Ms[t] draw_MI(M, axs[col], layout=layout) axs[col].set_title(r"$T_{%d}$" % R) for col, statestr in enumerate(["C6-3", "GHZ", "W", "R"]): state = make_state(L, statestr) M = ms.get_MI(state, order=1) draw_MI(M, axs[4 + col], layout=layout) if statestr[0] == "C": axs[4 + col].set_title(ket("C")) else: axs[4 + col].set_title(ket(statestr)) C = ms.network_clustering(M) Y = ms.network_disparity(M) print(statestr, " C:", C, " Y:", Y) fig.subplots_adjust(wspace=0.4, top=0.7, left=0.05, right=1, bottom=0) plot_fname = f"figures/figure3/{layout}_layout_medclip.pdf" print(plot_fname) multipage(plot_fname, clip=False)
def netviz( Skey, L=19, t=250, statestrs=["R123", "W", "GHZ", "C19-1_45"], layout="spring", IC="c3_f1", V="H", BC="1-00", T=1000, axs=None, order=1, ): legend_elements = [] if axs is None: fig, axs = plt.subplots(1, 8, figsize=(4.75, 0.8)) for col, S in enumerate(Skey): Q = QCA( dict(L=L, T=T, dt=1, R=S, r=1, V=V, IC=IC, BC=BC, E=0, N=1, totalistic=False, hamiltonian=False, trotter=True, symmetric=False)) Ms = Q.get_measure(f"MI_{order}", save=True) M = Ms[t] draw_MI(M, axs[col], layout=layout) # axs[col].set_title(r"$T_{%d}$" % S, pad=-0.3) legend_elements += [ Patch(facecolor=colors[S], edgecolor=None, label=r"$T_{%d}$" % S) ] for col, statestr in enumerate(statestrs): state = make_state(L, statestr) rhoj = ms.get_rhoj(state) rhojk = ms.get_rhojk(state) s1 = ms.get_entropy(rhoj, order) s2 = ms.get_entropy2(rhojk, order) M = ms.get_MI(s1, s2) draw_MI(M, axs[len(Skey) + col], layout=layout) if statestr[0] in ["C", "R", "G"]: label = ket(statestr[0]) else: label = ket(statestr) m = markers[statestr[0]] if m in ("x", "."): facecolor = "k" else: facecolor = "none" legend_elements += [ Line2D( [0], [0], marker=m, color="k", markersize=7, markeredgecolor="k", markerfacecolor=facecolor, label=label, linestyle='None', ) ] C = ms.network_clustering(M) Y = ms.network_disparity(M) print(statestr, " C:", C, " Y:", Y) axs[4].legend( handles=legend_elements, ncol=(len(Skey) + len(statestrs)), frameon=False, loc="upper center", bbox_to_anchor=(-0.1, 0.1), markerfirst=False, handlelength=0.71, handletextpad=0.1, columnspacing=2.7, )
import networkmeasures as nm from itertools import product, cycle import copy import matplotlib as mpl from matplotlib.backends.backend_pdf import PdfPages import json from collections import namedtuple, Iterable, OrderedDict from numpy import sin, cos, log, pi import matrix as mx import states as ss import processing as pp import fio as io import sweep_eca as sweep init_state = ss.make_state(3, [('E0_1', 1.0)]) r0 = mx.rdms(init_state, [0]) r1 = mx.rdms(init_state, [1]) r2 = mx.rdms(init_state, [2]) state_1 = mx.op_on_state(mx.listkron([ss.pauli['1']] * 2), [0, 2], init_state) r0_1 = mx.rdms(state_1, [0]) r1_1 = mx.rdms(state_1, [1]) r2_1 = mx.rdms(state_1, [2]) rd = mx.rdms(state_1, [1, 2]) # sx and sz entropies # -------------------