Skip to content

Commit

Permalink
Fixed style and version number in files (#42)
Browse files Browse the repository at this point in the history
v0.8.1 passes tests and conforms to style
  • Loading branch information
lucpeterson authored Mar 8, 2023
1 parent 7ca9482 commit bad1eb9
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push-pr_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
Lint:
runs-on: ubuntu-latest
env:
MAX_LINE_LENGTH: 127
MAX_COMPLEXITY: 15
MAX_LINE_LENGTH: 88
MAX_COMPLEXITY: 18

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to Merlin Spellbook will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.1]

### Fixed
- style and version number
- testing for make-samples

## [0.8.0]

### Added
Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ clean:
-rm -rf build

fix-style:
isort -rc $(PROJ)
isort -rc $(TEST)
isort *.py
black --target-version py36 $(PROJ)
black --target-version py36 $(TEST)
black --target-version py36 *.py
python3 -m isort --line-length 88 $(PROJ)
python3 -m isort --line-length 88 $(TEST)
python3 -m isort --line-length 88 *.py
python3 -m black --line-length 88 --target-version py36 $(PROJ)
python3 -m black --line-length 88 --target-version py36 $(TEST)
python3 -m black --line-length 88 --target-version py36 *.py

check-style:
python3 -m black --check --line-length 88 --target-version py36 $(PROJ)
python3 -m black --check --line-length 88 --target-version py36 $(TEST)
python3 -m pylint $(PROJ) --rcfile=setup.cfg --exit-zero
python3 -m pylint *.py --rcfile=setup.cfg --exit-zero
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# LLNL-CODE-797170
# All rights reserved.
# This file is part of Merlin-Spellbook, Version: 0.7.4.
# This file is part of Merlin-Spellbook, Version: 0.8.1.
#
# For details, see https://github.com/LLNL/merlin-spellbook.
#
Expand Down Expand Up @@ -58,7 +58,10 @@ def _pip_requirement(req):
def _reqs(*f):
return [
_pip_requirement(r)
for r in (_strip_comments(line) for line in open(os.path.join(os.getcwd(), "requirements", *f)).readlines())
for r in (
_strip_comments(line)
for line in open(os.path.join(os.getcwd(), "requirements", *f)).readlines()
)
if r
]

Expand Down
2 changes: 1 addition & 1 deletion spellbook/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.7.4"
__version__ = "0.8.1"

VERSION = __version__
4 changes: 3 additions & 1 deletion spellbook/commands/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
type=str,
help="whitespace separated list of files to collect",
)
@click.option("-outfile", required=False, default="results.hdf5", type=str, help="output file")
@click.option(
"-outfile", required=False, default="results.hdf5", type=str, help="output file"
)
def cli(instring, outfile):
"""
Collect many json files into a single json file
Expand Down
4 changes: 3 additions & 1 deletion spellbook/commands/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ def cli(infile, x, y, outfile, regressor):
"""
from spellbook.ml import learn_alt as learn

args = SimpleNamespace(**{"infile": infile, "X": x, "y": y, "outfile": outfile, "regressor": regressor})
args = SimpleNamespace(
**{"infile": infile, "X": x, "y": y, "outfile": outfile, "regressor": regressor}
)
learn.random_forest(args)
20 changes: 4 additions & 16 deletions spellbook/commands/make-samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,8 @@
type=int,
help="random number seed for generating samples",
)
@click.option(
"-n",
required=False,
default=100,
type=int,
help="number of samples"
)
@click.option(
"-dims",
required=False,
default=2,
type=int,
help="number of dimensions"
)
@click.option("-n", required=False, default=100, type=int, help="number of samples")
@click.option("-dims", required=False, default=2, type=int, help="number of dimensions")
@click.option(
"-sample_type",
required=False,
Expand Down Expand Up @@ -81,7 +69,7 @@
"will round generated samples with options of False (no rounding), "
"round (nearest integer), floor, or ceil. Format is '[False, ceil, "
"ceil]'."
)
),
)
@click.option(
"-repeat",
Expand All @@ -94,7 +82,7 @@
"PARAMETERS the seed value is located. Format is '[5, -1]' to specify "
"five repeats and the seed column being located at the last column. "
"Can also only specify one value."
)
),
)
@click.option(
"--hard-bounds",
Expand Down
4 changes: 3 additions & 1 deletion spellbook/commands/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


@click.command()
@click.option("--output", required=False, default="output.json", type=str, help="output file")
@click.option(
"--output", required=False, default="output.json", type=str, help="output file"
)
@click.option(
"--vars",
required=False,
Expand Down
11 changes: 8 additions & 3 deletions spellbook/data_formatting/conduit/python/conduit_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# LLNL-CODE-<PENDING>
# All rights reserved.
# This file is part of merlin-spellbook, Version: 0.7.4.
# This file is part of merlin-spellbook, Version: 0.8.1.
#
# For details, see https://github.com/LLNL/merlin-spellbook.
#
Expand Down Expand Up @@ -58,7 +58,9 @@ def determine_protocol(fname):
if ext.startswith("."):
protocol = ext.lower().strip(".")
else:
raise ValueError("{0} needs an ext (eg .hdf5) to determine protocol!".format(fname))
raise ValueError(
"{0} needs an ext (eg .hdf5) to determine protocol!".format(fname)
)
# Map .h5 to .hdf5
if protocol == "h5":
protocol = "hdf5"
Expand Down Expand Up @@ -155,7 +157,10 @@ def dump_node(
try:
conduit.relay.io.save(conduit_node, fname, options=save_options)
except TypeError: # Conduit version needs to be updated.
LOG.error("Unable to customize save: please upgrade conduit to " "expose save options!")
LOG.error(
"Unable to customize save: please upgrade conduit to "
"expose save options!"
)
conduit.relay.io.save(conduit_node, fname)
else:
conduit.relay.io.save(conduit_node, fname)
Expand Down
8 changes: 6 additions & 2 deletions spellbook/data_formatting/conduit/python/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def run(_input, output, schema):
if data_loader.has_path(sample_path):
data_loader.read(filtered_node[path], sample_path)
else:
filtered_node[sample_path] = np.nan # if a value is missing, that could be a problem
filtered_node[
sample_path
] = np.nan # if a value is missing, that could be a problem
make_data_array_dict(all_dict, filtered_node)

for dat in all_dict.keys():
Expand Down Expand Up @@ -127,7 +129,9 @@ def generate_scalar_path_pairs(node, path=""):
children = node.child_names()
for child in children:
if isinstance(node[child], conduit.Node):
for pair in generate_scalar_path_pairs(node[child], path=path + child + "/"):
for pair in generate_scalar_path_pairs(
node[child], path=path + child + "/"
):
yield pair
else:
yield path + child, node[child]
Expand Down
10 changes: 8 additions & 2 deletions spellbook/data_formatting/stack_npz.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def pad_many(arrays, dims, dont_pad_first=False, value=np.nan):
if dont_pad_first:
pad_dist[0] = 0
padder = np.column_stack((zeros, pad_dist))
fixed.append(np.pad(np.atleast_2d(a), padder, mode="constant", constant_values=value))
fixed.append(
np.pad(np.atleast_2d(a), padder, mode="constant", constant_values=value)
)
return fixed


Expand All @@ -46,7 +48,11 @@ def run(self, target, source, force=False):

if not force:
if os.path.isfile(target):
print("stack_npz error opening target file (does {0} exist?).".format(target))
print(
"stack_npz error opening target file (does {0} exist?).".format(
target
)
)
print('Pass "-f" argument to force re-creation of output file.')
return

Expand Down
12 changes: 9 additions & 3 deletions spellbook/data_formatting/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def setup_argparse():
help=".json file with X and y data in each sample",
default="results.json",
)
parser.add_argument("-output", help=".npz file with the arrays", default="results.npz")
parser.add_argument("-schema", help="schema for a single sample data", default="features.json")
parser.add_argument(
"-output", help=".npz file with the arrays", default="results.npz"
)
parser.add_argument(
"-schema", help="schema for a single sample data", default="features.json"
)
return parser


Expand Down Expand Up @@ -47,7 +51,9 @@ def generate_scalar_path_pairs(node, schema, path=""):
if child in schema.keys():
if isinstance(node[child], dict):
if isinstance(schema[child], dict):
for pair in generate_scalar_path_pairs(node[child], schema[child], path=path + child + "/"):
for pair in generate_scalar_path_pairs(
node[child], schema[child], path=path + child + "/"
):
yield pair
else:
if not isinstance(schema[child], dict):
Expand Down
2 changes: 1 addition & 1 deletion spellbook/log_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# LLNL-CODE-797170
# All rights reserved.
# This file is part of Merlin Spellbook, Version: 0.7.4.
# This file is part of Merlin Spellbook, Version: 0.8.1.
#
# For details, see https://github.com/LLNL/merlin.
#
Expand Down
14 changes: 11 additions & 3 deletions spellbook/ml/surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def factory(cls, name, *args, **kwargs):
if name in cls.all_regs:
return cls.all_regs[name](*args, **kwargs)
else:
raise ValueError("Unknown regressor name " + name + "! For valid choices see sklearnRegressors.names()")
raise ValueError(
"Unknown regressor name "
+ name
+ "! For valid choices see sklearnRegressors.names()"
)

@classmethod
def names(cls):
Expand All @@ -81,8 +85,12 @@ def test_factory():

def test_random_forest():

rf1 = sklearnRegressors.factory("RandomForestRegressor", n_estimators=10, max_depth=5)
rf2 = sklearnRegressors.factory("RandomForestRegressor", n_estimators=2, max_depth=3)
rf1 = sklearnRegressors.factory(
"RandomForestRegressor", n_estimators=10, max_depth=5
)
rf2 = sklearnRegressors.factory(
"RandomForestRegressor", n_estimators=2, max_depth=3
)

assert rf1.n_estimators == 10
assert rf1.max_depth == 5
Expand Down
9 changes: 7 additions & 2 deletions spellbook/optimization/qoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def barrier(x, threshold, threshold_type="greater"):
penalty[group2] = (
sign_x[group2]
* xx[group2]
* ((1.0 / g0[group2]) * ((gi[group2] / g0[group2]) ** 2 - 3.0 * (gi[group2] / g0[group2]) + 3.0))
* (
(1.0 / g0[group2])
* ((gi[group2] / g0[group2]) ** 2 - 3.0 * (gi[group2] / g0[group2]) + 3.0)
)
)
penalty[group3] = 0.0

Expand Down Expand Up @@ -131,7 +134,9 @@ def parse_constraints(constraint_args, data):
threshold_type = "greater"
splitter = ">"
else:
raise ValueError('Bad constraint format: must be "name<value" or "name>value"')
raise ValueError(
'Bad constraint format: must be "name<value" or "name>value"'
)
name, value_name = constraint.split(splitter)
value = float(value_name)
constraint_data.append((data[name], value, threshold_type))
Expand Down
14 changes: 7 additions & 7 deletions spellbook/sampling/make_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ def process_scale(scale):

def process_round(round):
if round is not None:
return round.strip('[|]').replace(" ", "").split(",")
return round.strip("[|]").replace(" ", "").split(",")


def process_repeat(repeat):
return repeat.strip('[|]').replace(" ", "").split(",")
return repeat.strip("[|]").replace(" ", "").split(",")


class MakeSamples(CliCommand):
Expand Down Expand Up @@ -130,19 +130,19 @@ def apply_scale(self, x, scales):

def apply_rounding(self, x, round):
if round is not None:
x = x.astype('object')
x = x.astype("object")
# round the samples
round = process_round(round)
values = ['False', 'round', 'floor', 'ceil']
values = ["False", "round", "floor", "ceil"]
# check that the array sizes are the same
if len(round) != self.n_dims:
raise ValueError("length of -round must equal value of -dims.")
for e, r in enumerate(round):
if r.lower() not in [v.lower() for v in values]:
raise ValueError(f"{r} is not an option. Must use {values}.")
if r.lower() != 'false':
if r.lower() != "false":
func = getattr(np, r)
x[:, e] = func(x[:, e].astype('float')).astype('int')
x[:, e] = func(x[:, e].astype("float")).astype("int")
return x

def apply_repeat(self, x, repeat):
Expand All @@ -161,7 +161,7 @@ def apply_repeat(self, x, repeat):
seed_col = repeat[1]
# Generate and fix seed value to specified column
s = np.random.rand(self.n_samples) * 10**6
s = np.round(s).astype('int').tolist()
s = np.round(s).astype("int").tolist()
s = s * num_repeat
s = np.array(s)
# Insert into array for the specified column
Expand Down
Loading

0 comments on commit bad1eb9

Please sign in to comment.