Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
reverendbedford committed Sep 14, 2023
1 parent 95a33be commit 30cc355
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pyoptmat/chunktime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions pyoptmat/hardening.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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
"""
Expand Down
2 changes: 1 addition & 1 deletion pyoptmat/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions pyoptmat/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyoptmat/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def scale_mean(self, loc, scale):
"""
return self.scale(loc)


class LogBoundedScalingFunction(ScalingFunction):
"""
Scaling function where the unscaled parameters are
Expand Down
8 changes: 6 additions & 2 deletions test/test_hardening.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 30cc355

Please sign in to comment.