<commit_before>import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.colors import LogNorm, Normalize

from desc.equilibrium import Equilibrium
from desc.grid import LinearGrid
from desc.basis import DoubleFourierSeries
from desc.transform import Transform
from desc.compute import (
    compute_boozer_coords,
    compute_quasisymmetry_error,
    compute_geometry,
)


plt.rcParams["font.size"] = 14
dim = 11

# m=1, n=2 boundary Fourier coefficients
RBC = np.linspace(-0.1, 0, dim)
ZBS = np.linspace(-0.05, 0.05, dim)

# equilibrium
eq = Equilibrium.load("data/initial.h5")

grid = LinearGrid(M=6 * eq.M + 1, N=6 * eq.N + 1, NFP=eq.NFP, sym=False, rho=1.0)

R_transform = Transform(grid, eq.R_basis, derivs=3)
Z_transform = Transform(grid, eq.Z_basis, derivs=3)
L_transform = Transform(grid, eq.L_basis, derivs=3)
B_transform = Transform(
    grid,
    DoubleFourierSeries(M=2 * eq.M, N=2 * eq.N, sym=eq.R_basis.sym, NFP=eq.NFP),
    derivs=0,
    build_pinv=True,
)
w_transform = Transform(
    grid,
    DoubleFourierSeries(M=2 * eq.M, N=2 * eq.N, sym=eq.Z_basis.sym, NFP=eq.NFP),
    derivs=1,
)

iota = eq.iota.copy()
iota.grid = grid


def qs_errors(eq):<commit_msg>change dudt2022 script to use quad grid for computing QS errors<commit_after>import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.colors import LogNorm, Normalize

from desc.equilibrium import Equilibrium
from desc.grid import LinearGrid, QuadratureGrid
from desc.basis import DoubleFourierSeries
from desc.transform import Transform
from desc.compute import (
    compute_boozer_coords,
    compute_quasisymmetry_error,
    compute_geometry,
)


plt.rcParams["font.size"] = 14
dim = 11

# m=1, n=2 boundary Fourier coefficients
RBC = np.linspace(-0.1, 0, dim)
ZBS = np.linspace(-0.05, 0.05, dim)

# equilibrium
eq = Equilibrium.load("data/initial.h5")

grid = LinearGrid(M=6 * eq.M + 1, N=6 * eq.N + 1, NFP=eq.NFP, sym=False, rho=1.0)
qgrid = QuadratureGrid(M=3 * eq.M + 1, N=3 * eq.N + 1,L=3*eq.L+1, NFP=eq.NFP)
R_transform = Transform(qgrid, eq.R_basis, derivs=3)
Z_transform = Transform(qgrid, eq.Z_basis, derivs=3)
L_transform = Transform(qgrid, eq.L_basis, derivs=3)
B_transform = Transform(
    qgrid,
    DoubleFourierSeries(M=2 * eq.M, N=2 * eq.N, sym=eq.R_basis.sym, NFP=eq.NFP),
    derivs=0,
    build_pinv=True,
)
w_transform = Transform(
    qgrid,
    DoubleFourierSeries(M=2 * eq.M, N=2 * eq.N, sym=eq.Z_basis.sym, NFP=eq.NFP),
    derivs=1,
)

iota = eq.iota.copy()
iota.grid = qgrid


def qs_errors(eq):
{'fraction_non_alphanumeric': 0.12485768500948767, 'fraction_numerical': 0.02808349146110057, 'mean_word_length': 4.514644351464435, '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': '2939439', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1030, 'n_words': 234}