<commit_before>from future.builtins import range
import os

import numpy as np

import modred as mr


# Create directory for output files
out_dir = 'tutorial_ex4_out'
if not os.path.isdir(out_dir):
    os.makedirs(out_dir)

# Uniform grid and corresponding inner product weights
num_vecs = 100
nx = 80
ny = 100
x_grid = 1. - np.cos(np.linspace(0, np.pi, nx))
y_grid = np.linspace(0, 1., ny) ** 2
Y, X = np.meshgrid(y_grid, x_grid)

snapshots = [
    mr.VecHandlePickle('%s/vec%d.pkl' % (out_dir, i)) for i in range(num_vecs)]
parallel = mr.parallel_default_instance
if parallel.is_rank_zero():
    for i,snap in enumerate(snapshots):
        snap.put(np.sin(X * i) + np.cos(Y * i))
        parallel.barrier()

weighted_IP = mr.InnerProductTrapz(x_grid, y_grid)

# Calculate DMD modes and save them to pickle files
my_DMD = mr.DMDHandles(weighted_IP)
my_DMD.compute_decomp(snapshots)
my_DMD.put_decomp(<commit_msg>Fixed race condition.<commit_after>from future.builtins import range
import os

import numpy as np

import modred as mr


# Create directory for output files
out_dir = 'tutorial_ex4_out'
if not os.path.isdir(out_dir):
    os.makedirs(out_dir)

# Uniform grid and corresponding inner product weights
num_vecs = 100
nx = 80
ny = 100
x_grid = 1. - np.cos(np.linspace(0, np.pi, nx))
y_grid = np.linspace(0, 1., ny) ** 2
Y, X = np.meshgrid(y_grid, x_grid)

snapshots = [
    mr.VecHandlePickle('%s/vec%d.pkl' % (out_dir, i)) for i in range(num_vecs)]
parallel = mr.parallel_default_instance
if parallel.is_rank_zero():
    for i,snap in enumerate(snapshots):
        snap.put(np.sin(X * i) + np.cos(Y * i))
parallel.barrier()

weighted_IP = mr.InnerProductTrapz(x_grid, y_grid)

# Calculate DMD modes and save them to pickle files
my_DMD = mr.DMDHandles(weighted_IP)
my_DMD.compute_decomp(snapshots)
my_DMD.put_decomp(
{'fraction_non_alphanumeric': 0.11555312157721796, 'fraction_numerical': 0.01533406352683461, 'mean_word_length': 4.4375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '2623468', 'n_tokens_mistral': 748, 'n_tokens_neox': 710, 'n_words': 179}