<jupyter_start><jupyter_text>Define global variablesDefine global variables such as temperature used for determining evolution time<jupyter_code>kBT = 1
evolution_time = 1 / (2 * kBT)
n_hamiltonian_qubits = 4
n_timesteps = 100<jupyter_output><empty_output><jupyter_text>Generate HamiltonianWe generate a transverse field Ising model Hamiltonian of 4 "fully connected" qubits with coefficients sampled from uniform distribution of -2 to 2.<jupyter_code>hamiltonian, problem_qubits = build_ising_model_hamiltonian([n_hamiltonian_qubits], random=True, random_low = -2, random_high=2)
print(hamiltonian)<jupyter_output>-0.680*Z((0, 0))*Z((1, 0))+1.521*Z((0, 0))*Z((2, 0))-0.917*Z((0, 0))*Z((3, 0))-1.057*Z((1, 0))*Z((2, 0))-0.674*Z((1, 0))*Z((3, 0))+1.532*Z((2, 0))*Z((3, 0))+1.122*Z((0, 0))+1.449*X((0, 0))-1.404*Z((1, 0))-0.645*X((1, 0))-0.719*Z((2, 0))-1.674*X((2, 0))-1.043*Z((3, 0))+1.714*X((3, 0))<jupyter_text>Exact thermal stateExact thermal state solved analytically from matrix exponential.<jupyter_code>exact_state = evaluate_exact_state(hamiltonian, evolution_time)
plot_density_matrix_heatmap([exact_state], show = True, size = 6)<jupyter_output><empty_output><jupyter_text>Define a variational circuit for VarQITEDefine a variational quantum circuit for VarQITE with good representation capabilities.<jupyter_code>n_layers = 3
rotations = [cirq.ry, cirq.rz]
entanglers = [cirq.CNOT]
pattern = "chain"
ancillary_qubits = get_ancillary_qubits(problem_qubits)
qubits = [*problem_qubits, *ancillary_qubits]

circuit, symbol_names = build_ansatz(
    qubits, n_layers, rotations, entanglers, pattern
)
initial_symbol_values = initialize_ansatz_symbols(
    len(qubits),
    n_layers,
    len(rotations),
    0,
    np.pi / 2,
    len(entanglers),
    pattern,
)
save_circuit_to_svg(circuit, show = True)<jupyter_output>findfont: Font family ['Arial'] not found. Falling back to DejaVu Sans.<jupyter_text>Run variational quantum imaginary time evolution (VarQITE)<jupyter_code>qite = QITE(verbose = 3)
final_symbol_values, final_state, metrics = qite.run(
    circuit,
    hamiltonian,
    symbol_names,
    initial_symbol_values,
    evolution_time,
    exact_state,
    n_timesteps=n_timesteps
)<jupyter_output><empty_output><jupyter_text>Plot comparisonPlot the density matrices of the VarQITE prepared thermal state and the analytic solution<jupyter_code>plot_density_matrix_heatmap([final_state, exact_state], titles = ["Prepared thermal state", "Analytic solution"], annot = True, size = 10)<jupyter_output><empty_output><jupyter_text>Print metrics from VarQITE<jupyter_code>df = pd.DataFrame.from_dict(metrics)
print(df.head(10))
print(df.tail(10))<jupyter_output>time_step    energy  fidelity  quantum_relative_entropy  trace_distance
0          0  0.000001  0.449730                  1.235851        0.636920
1          1  0.000001  0.459004                  1.205852        0.629933
2          2 -0.097968  0.468317                  1.176315        0.622859
3          3 -0.195877  0.477665                  1.147241        0.615706
4          4 -0.293671  0.487040                  1.118634        0.609460
5          5 -0.391300  0.496434                  1.090494        0.603479
6          6 -0.488710  0.505844                  1.062821        0.597419
7          7 -0.585852  0.515260                  1.035619        0.591283
8          8 -0.682673  0.524676                  1.008887        0.585074
9          9 -0.779127  0.534085                  0.982626        0.578797
     time_step    energy  fidelity  quantum_relative_entropy  trace_distance
91          91 -5.692026  0.964977                  0.091765        0.157806
92          92 -5.720[...]
{'fraction_non_alphanumeric': 0.11231982594506391, 'fraction_numerical': 0.12483002447647538, 'mean_word_length': 3.237327188940092, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '381571', 'license': 'MIT', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1304, 'n_words': 276, 'path': 'varqite_experiment.ipynb', 'repo_name': 'leevilehtonen/tfq-varqbm', 'size': '3677'}