<jupyter_start><jupyter_text>U(1) Model See, for example:- https://www.sciencedirect.com/science/article/abs/pii/0010465581901405<jupyter_code>import numpy as np
import pandas as pd

from pystatplottools.pdf_env.loading_figure_mode import loading_figure_mode
fma, plt = loading_figure_mode(develop=True) # develop=False will export the generated figures as pngs into "./data/RectangleData"
plt.style.use('seaborn-dark-palette')

if 'root_dir' not in locals():
    # Navigate to simulations/U1Model directory as simulation root directory
    import os
    os.chdir("../simulations/U1Model")
    root_dir = os.getcwd()

# To be able to compute custom measures
import sys
sys.path.append("./../../python_scripts")
    
mcmc_model_dir = "U1ModelMetropolis/"
mcmc_data_dir = root_dir + "/data/" + mcmc_model_dir
mcmc_results_dir = root_dir + "/results/" + mcmc_model_dir

data_dir = root_dir + "/data/" + mcmc_model_dir
results_dir = root_dir + "/results/" + mcmc_model_dir<jupyter_output><empty_output><jupyter_text>MCMC Results  Expectation Values<jupyter_code>from mcmctools.modes.expectation_value import load_expectation_value_results
expectation_values = load_expectation_value_results(files_dir="U1ModelMetropolis")
# Insert Beta as column (as floating number)
expectation_values.insert(0, "Beta", expectation_values.index.values.astype(np.float))
expectation_values
average_plaquette = expectation_values.apply(lambda x: x / expectation_values["Beta"])
average_plaquette
x = average_plaquette["ExpVal"]["AveragePlaquetteAction"]
np.cos(-1 * (x - 1))
fig, ax = fma.newfig(1.4, figsize=(10, 7))

ax.plot(expectation_values["Beta"], average_plaquette["ExpVal", "AveragePlaquetteAction"], "o-")

ax.set_xlabel("Beta")
ax.set_ylabel("Average Plaquette")

plt.tight_layout()

fma.savefig(results_dir, "average_plaquette")<jupyter_output><empty_output><jupyter_text>Configurations as Pytorch Dataset We show how the mcmc configurations can be stored and loaded as a .pt file.(See also python_scripts/loading_configurations.py and python_scripts/pytorch_data_generation.py)  Preparation<jupyter_code>data_generator_args = {
    # ConfigDataGenerator Args
    "data_type": "target_param",
    # Args for ConfigurationLoader
    "path": mcmc_data_dir,
    "total_number_of_data_per_file": 500,
    "identifier": "expectation_value",
    "running_parameter": "beta"
    # "chunksize": 100  # If no chunksize is given, all data is loaded at once
}

# Prepare in memory dataset
from pystatplottools.pytorch_data_generation.data_generation.datagenerationroutines import prepare_in_memory_dataset
from mcmctools.pytorch.data_generation.datagenerationroutines import data_generator_factory

prepare_in_memory_dataset(
    root=data_dir,
    batch_size=89,
    data_generator_args=data_generator_args,
    data_generator_name="BatchConfigDataGenerator",
    data_generator_factory=data_generator_factory
)<jupyter_output>Random seed is set by np.random.seed()<jupyter_text>Generating and Loading the Dataset<jupyter_code># Load in memory dataset
from pystatplottools.pytorch_data_generation.data_generation.datagenerationroutines import load_in_memory_dataset

# The dataset is generated and stored as a .pt file in the data_dir/data directory the first time this function is called. Otherwise the .pt is loaded.
data_loader = load_in_memory_dataset(
    root=data_dir, batch_size=16, data_generator_factory=data_generator_factory, slices=None, shuffle=True,
    num_workers=0, rebuild=False
    # sample_data_generator_name="ConfigDataGenerator"  # optional: for a generation of new samples
)

# Load training data
for batch_idx, batch in enumerate(data_loader):
    data, target = batch
    # print(batch_idx, len(data))<jupyter_output>RDKit WARNING: [14:04:28] Enabling RDKit 2019.09.1b1 jupyter extensions<jupyter_text>Inspection of the Dataset - Sample Visualization<jupyter_code>from pystatplottools.visualization import sample_visualization

config_dim = (64, 32)  # Dimension of the data
ab = (-1, 1)  # Data is expected to be in the range (-1, 1)

# Random samples
config, label = data_loader.dataset.get_random_sample()
batch, batch_label = data_loader.dataset.get_random_batch(108)
data[:, 1::2].min(), data[:, 1::2].max(), data[:, 0::2].min(), data[:, 0::2].max()
# Single Sample
fig, axes = fma.newfig(1, nrows=2, ratio=0.5, figsize=(10, 5))

# Real parts
sample_visualization.fd_im_single_sample(sample=config[0::2], label=label, config_dim=(16, 64), ab=ab,
                                         fig=fig, ax=axes[0]);
# Imag parts
sample_visualization.fd_im_single_sample(sample=config[1::2], label=label, config_dim=(16, 64), ab=ab,
                                         fig=fig, ax=axes[1]);
fma.savefig(results_dir, "single_sample")
# Batch with labels
sample_visualization.fd_im_batch(batch[:, 0::2], batch_labels=batch_label, num_samples=16, dim=(4, 4),
                                 config_dim=(16, 64), ab=ab,
                                 fma=fma, filename="batch_real_parts", directory=results_dir, width=2.3, ratio=1.0, figsize=(16, 4));

sample_visualization.fd_im_batch(batch[:, 1::2], batch_labels=batch_label, num_samples=16, dim=(4, 4),
                                 config_dim=(16, 64), ab=ab,
                                 fma=fma, filename="batch_imag_parts", directory=results_dir, width=2.3, ratio=1.0, figsize=(16, 4));
# Batch grid
fig, axes = fma.newfig(1, nrows=2, ratio=0.5, figsize=(16, 5))

# Real parts
sample_visualization.fd_im_batch_grid(batch[:, 0::2], config_dim=(16, 64), ab=ab,
                                      fig=fig, ax=axes[0]);
# Imag parts
sample_visualization.fd_im_batch_grid(batch[:, 1::2], config_dim=(16, 64), ab=ab,
                                      fig=fig, ax=axes[1]);
fma.savefig(results_dir, "batch_grid")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11420708634330926, 'fraction_numerical': 0.02562779497764018, 'mean_word_length': 4.8678102926337035, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '121755', 'license': 'MIT', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1928, 'n_words': 409, 'path': 'jupyter_notebooks/u1_model.ipynb', 'repo_name': 'statphysandml/LatticeModelImplementations', 'size': '5814'}