Skip to content

[Code scan] Fix normal-distribution random disturbances #1914

Description

@njzjz

This issue is from a Codex global scan of the repository.

create_random_disturb.py accepts -dstyle normal, but that path raises a NumPy argument error.

Evidence:

def gen_random_disturb(dmax, a, b, dstyle="uniform"):
d0 = np.random.rand(3) * (b - a) + a
dnorm = np.linalg.norm(d0)
if dstyle == "normal":
dmax = np.random.standard_normal(0, 0.5) * dmax
elif dstyle == "constant":
pass
else:
# use if we just wanna a disturb in a range of [0, dmax),
dmax = np.random.random() * dmax

parser = argparse.ArgumentParser(
description="Script to generate random disturb configurations"
)
parser.add_argument("fin", type=str, help="input file name")
parser.add_argument("nfile", type=int, help="number of files to be created")
parser.add_argument("dmax", type=float, help="dmax")
parser.add_argument(
"-etmax",
type=float,
default=0,
help="etmax for random strain tensor generations",
)
parser.add_argument(
"-diag",
type=int,
default=0,
help="only diagonal elements of strain tensors are randomized?",
)
parser.add_argument("-ofmt", type=str, default="lmp", help="output fileformat")
parser.add_argument(
"-dstyle",
type=str,
default="uniform",
help="random distribution style [uniform?]",
)
parser.add_argument(
"-wd",

The parser exposes -dstyle and gen_random_disturb() checks for dstyle == "normal", but calls np.random.standard_normal(0, 0.5). NumPy's standard_normal accepts only the optional size positional argument, so this raises TypeError instead of generating a normally distributed disturbance.

Expected behavior: use an API such as np.random.normal(loc=0, scale=0.5) or otherwise implement the intended normal-distribution scaling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions