diff --git a/pyoptmat/chunktime.py b/pyoptmat/chunktime.py index 95ebf6d..a84e0c1 100644 --- a/pyoptmat/chunktime.py +++ b/pyoptmat/chunktime.py @@ -19,8 +19,9 @@ from pyoptmat.utility import mbmm -def newton_raphson_chunk(fn, x0, solver, rtol=1e-6, atol=1e-10, miter=100, - throw_on_fail = False): +def newton_raphson_chunk( + fn, x0, solver, rtol=1e-6, atol=1e-10, miter=100, throw_on_fail=False +): """ Solve a nonlinear system with Newton's method with a tensor for a BackwardEuler type chunking operator context manager. @@ -55,8 +56,7 @@ def newton_raphson_chunk(fn, x0, solver, rtol=1e-6, atol=1e-10, miter=100, if i == miter: if throw_on_fail: raise RuntimeError("Implicit solve did not succeed.") - else: - warnings.warn("Implicit solve did not succeed. Results may be inaccurate...") + warnings.warn("Implicit solve did not succeed. Results may be inaccurate...") return x diff --git a/pyoptmat/hardening.py b/pyoptmat/hardening.py index 820ef85..6492e2e 100644 --- a/pyoptmat/hardening.py +++ b/pyoptmat/hardening.py @@ -701,6 +701,7 @@ def dhistory_rate_derate(self, s, h, t, ep, T, e): """ return (self.C(T) - self.g(T) * h[..., 0] * torch.sign(ep))[..., None, None] + class FAKinematicHardeningModelNoRecovery(KinematicHardeningModel): # pylint: disable=line-too-long """ @@ -810,9 +811,9 @@ def dhistory_rate_dhistory(self, s, h, t, ep, T, e): Returns: torch.tensor: derivative with respect to history """ - return ( - -self.g(T) * torch.ones_like(h[..., 0]) * torch.abs(ep) - )[..., None, None] + return (-self.g(T) * torch.ones_like(h[..., 0]) * torch.abs(ep))[ + ..., None, None + ] def dhistory_rate_derate(self, s, h, t, ep, T, e): """ @@ -832,6 +833,7 @@ def dhistory_rate_derate(self, s, h, t, ep, T, e): """ return (self.C(T) - self.g(T) * h[..., 0] * torch.sign(ep))[..., None, None] + class ChabocheHardeningModel(KinematicHardeningModel): # pylint: disable=line-too-long """ diff --git a/pyoptmat/ode.py b/pyoptmat/ode.py index 8982b40..0490471 100644 --- a/pyoptmat/ode.py +++ b/pyoptmat/ode.py @@ -299,7 +299,7 @@ def __init__( direct_solve_min_size=0, adjoint_params=None, guess_type="zero", - throw_on_fail = False, + throw_on_fail=False, **kwargs, ): # Store basic info about the system diff --git a/pyoptmat/optimize.py b/pyoptmat/optimize.py index c4f587c..c9d80e9 100644 --- a/pyoptmat/optimize.py +++ b/pyoptmat/optimize.py @@ -189,7 +189,7 @@ class StatisticalModel(PyroModule): entry i represents the noise in test type i """ - def __init__(self, maker, names, locs, scales, eps, nan_num = False): + def __init__(self, maker, names, locs, scales, eps, nan_num=False): super().__init__() self.maker = maker @@ -242,7 +242,7 @@ def forward(self, exp_data, exp_cycles, exp_types, exp_control, exp_results=None # Setup the full noise, which can be type specific if self.type_noise: - full_noise = torch.empty(exp_data.shape[-1], device = self.eps.device) + full_noise = torch.empty(exp_data.shape[-1], device=self.eps.device) for i in experiments.exp_map.values(): full_noise[exp_types == i] = self.eps[i] else: @@ -470,7 +470,8 @@ def guide(exp_data, exp_cycles, exp_types, exp_control, exp_results=None): # Fix this to init to the mean (or a sample I guess) ll_param = pyro.param( name + self.param_suffix, - val.detach().clone() + val.detach() + .clone() .unsqueeze(0) .repeat((exp_data.shape[2],) + (1,) * dim), ) @@ -553,7 +554,7 @@ def _make_weight_tensor(self, exp_types): Assemble a full tensor for the data weights, based on the self.weights dictionary """ - weights = torch.zeros(exp_types.shape, device = exp_types.device) + weights = torch.zeros(exp_types.shape, device=exp_types.device) for tt, v in self.weights.items(): weights[exp_types == tt] = v diff --git a/pyoptmat/scaling.py b/pyoptmat/scaling.py index 4db563a..132e62f 100644 --- a/pyoptmat/scaling.py +++ b/pyoptmat/scaling.py @@ -208,6 +208,7 @@ def scale_mean(self, loc, scale): """ return self.scale(loc) + class LogBoundedScalingFunction(ScalingFunction): """ Scaling function where the unscaled parameters are diff --git a/test/test_hardening.py b/test/test_hardening.py index 137b149..2a4cb3b 100644 --- a/test/test_hardening.py +++ b/test/test_hardening.py @@ -222,7 +222,9 @@ class TestFAKinematicHardening(unittest.TestCase, HardeningBase): def setUp(self): self.C = torch.tensor(100.0) self.g = torch.tensor(1.2) - self.model = hardening.FAKinematicHardeningModelNoRecovery(CP(self.C), CP(self.g)) + self.model = hardening.FAKinematicHardeningModelNoRecovery( + CP(self.C), CP(self.g) + ) self.nbatch = 10 self.bdim = 1 @@ -239,7 +241,9 @@ class TestFAKinematicHardeningMultiBatch(unittest.TestCase, HardeningBase): def setUp(self): self.C = torch.tensor(100.0) self.g = torch.tensor(1.2) - self.model = hardening.FAKinematicHardeningModelNoRecovery(CP(self.C), CP(self.g)) + self.model = hardening.FAKinematicHardeningModelNoRecovery( + CP(self.C), CP(self.g) + ) self.nbatch = 10 self.bdim = 2