Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whoburg committed Jan 5, 2024
1 parent a21deca commit 4b648a8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions gpkit/tools/autosweep.py
@@ -1,5 +1,6 @@
"Tools for optimal fits to GP sweeps"
from time import time
import pickle
import numpy as np
from ..small_classes import Count
from ..small_scripts import mag
Expand Down Expand Up @@ -154,8 +155,8 @@ def save(self, filename="autosweep.p"):
>>> import cPickle as pickle
>>> pickle.load(open("autosweep.p"))
"""
import pickle
pickle.dump(self, open(filename, "wb"))
with open(filename, "wb") as f:
pickle.dump(self, f)


class SolutionOracle:
Expand Down Expand Up @@ -201,6 +202,7 @@ def cost_ub(self):

def plot(self, posys=None, axes=None):
"Plots the sweep for each posy"
#pylint: disable=import-outside-toplevel
import matplotlib.pyplot as plt
from ..interactive.plot_sweep import assign_axes
from .. import GPBLU
Expand Down Expand Up @@ -236,15 +238,15 @@ def autosweep_1d(model, logtol, sweepvar, bounds, **solvekwargs):
try:
model.solve(**solvekwargs)
firstsols.append(model.program.result)
except InvalidGPConstraint:
raise InvalidGPConstraint("only GPs can be autoswept.")
except InvalidGPConstraint as exc:
raise InvalidGPConstraint("only GPs can be autoswept.") from exc
sols()
bst = BinarySweepTree(bounds, firstsols, sweepvar, model.cost)
tol = recurse_splits(model, bst, sweepvar, logtol, solvekwargs, sols)
bst.nsols = sols() # pylint: disable=attribute-defined-outside-init
if solvekwargs["verbosity"] > -1:
print("Solved in %2i passes, cost logtol +/-%.3g" % (bst.nsols, tol))
print("Autosweeping took %.3g seconds." % (time() - start_time))
print(f"Solved in {bst.nsols:2} passes, cost logtol +/-{tol:.3g}")
print(f"Autosweeping took {time() - start_time:.3g} seconds.")
if original_val:
model.substitutions[sweepvar] = original_val
else:
Expand All @@ -253,6 +255,7 @@ def autosweep_1d(model, logtol, sweepvar, bounds, **solvekwargs):


def recurse_splits(model, bst, variable, logtol, solvekwargs, sols):
# pylint: disable=too-many-arguments
"Recursively splits a BST until logtol is reached"
x, lb, ub = get_tol(bst.costs, bst.bounds, bst.sols, variable)
tol = (ub-lb)/2.0
Expand Down

0 comments on commit 4b648a8

Please sign in to comment.