<jupyter_start><jupyter_text>Quenching a Random Product State==================First we'll set up a 20 qubit random product state, and a sparse heisenberg hamiltonian to evolve it with:<jupyter_code>import quimb as qu

n = 18
H = qu.ham_heis(n, sparse=True).real
psi0 = qu.rand_product_state(n)<jupyter_output><empty_output><jupyter_text>We can do a few checks on the system like $\langle \psi | \psi \rangle$:<jupyter_code># check normalization
qu.expectation(psi0, psi0)<jupyter_output><empty_output><jupyter_text>and $\langle \psi | H | \psi \rangle$:<jupyter_code># find the initial energy
qu.expec(H, psi0)<jupyter_output><empty_output><jupyter_text>or $\langle \psi | H^2 | \psi \rangle$:<jupyter_code># find the initial variance in energy
psi0.H @ H @ H @ psi0<jupyter_output><empty_output><jupyter_text>Let's compare this to the total energy spectrum of the Hamiltonian ``H``:<jupyter_code>%%time

en_low, en_high = qu.bound_spectrum(H)

print("Highest energy:", en_high)
print("Lowest energy:", en_low)<jupyter_output>Highest energy: 4.500000000000008
Lowest energy: -8.022749087033766
CPU times: user 313 ms, sys: 249 ms, total: 562 ms
Wall time: 5.25 s<jupyter_text>From which we can infer that our initial state has roughly has overlap between many states in the centre of the spectrum. Evolution---------Now let's set up some things we want to compute while we evolve with the hamiltonian. Namely the logarithmic negativity and mutual information between neighbouring qubits. Since we'll use the default adaptive integrating scheme, we'll return the current time as well:<jupyter_code>def compute(t, pt):
    """Perform computation at time ``t`` with state ``pt``.
    """
    dims = [2] * n
    lns = [qu.logneg_subsys(pt, dims, i, i + 1) for i in range(n - 1)]
    mis = [qu.mutinf_subsys(pt, dims, i, i + 1) for i in range(n - 1)]
    return t, lns, mis<jupyter_output><empty_output><jupyter_text>Set up the evolution with the initial state, hamiltonian and the compute dict:<jupyter_code>evo = qu.Evolution(psi0, H, compute=compute, progbar=True)<jupyter_output><empty_output><jupyter_text>Update the evolution to ``t=5``. The functions in ``compute`` will be called at each step the integrator uses. If we had set ``method='solve'`` or ``method='expm'``, we should use the generator ``evo.at_times(ts)`` to specify the time steps when computation takes place.<jupyter_code>evo.update_to(5)<jupyter_output>100%|██████████| 100/100 [00:10<00:00, 10.18%/s]<jupyter_text>We can extract the results of the computation from ``evo.results`` and plot them:<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt

ts, lns, mis = zip(*evo.results)

fig, axs = plt.subplots(2, 1, sharex=True)
axs[0].plot(ts, lns);
axs[0].set_title("Logarithmic Negativity")
axs[1].plot(ts, mis);
axs[1].set_title("Mutual Information")

plt.show()<jupyter_output><empty_output><jupyter_text>We can see that the classical correlations outlast the quantum correlations.Finally, let's check that energy has been conserved in the current state at ``t=5``:<jupyter_code>qu.expec(H, evo.pt)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12752971410215228, 'fraction_numerical': 0.029232251847092838, 'mean_word_length': 5.935412026726058, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '557429', 'license': 'Apache-2.0', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1058, 'n_words': 334, 'path': 'docs/examples/ex_quench.ipynb', 'repo_name': 'cbwang2016/quimb', 'size': '3113'}