Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
himkwtn committed Sep 11, 2024
1 parent b854621 commit 6209cad
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 39 deletions.
2 changes: 2 additions & 0 deletions examples/1_feature_overview/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def ignore_specific_warnings():
# ### Discrete time dynamical system (map)

# In[14]:


def f(x):
return 3.6 * x * (1 - x)

Expand Down
16 changes: 11 additions & 5 deletions examples/8_trapping_sindy_examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
# compute relative Frobenius error in the model coefficients
terms = sindy_library.get_feature_names()
Xi_meanfield = np.zeros(Xi.shape)
Xi_meanfield[1: r + 1, :] = np.asarray([[0.01, -1, 0], [1, 0.01, 0], [0, 0, -1]]).T
Xi_meanfield[1 : r + 1, :] = np.asarray([[0.01, -1, 0], [1, 0.01, 0], [0, 0, -1]]).T
Xi_meanfield[terms.index("x0 x2"), 0] = -1
Xi_meanfield[terms.index("x1 x2"), 1] = -1
Xi_meanfield[terms.index("x0^2"), 2] = 1
Expand Down Expand Up @@ -275,7 +275,7 @@
# compute relative Frobenius error in the model coefficients
terms = sindy_library.get_feature_names()
Xi_oscillator = np.zeros(Xi.shape)
Xi_oscillator[1: r + 1, :] = np.asarray(
Xi_oscillator[1 : r + 1, :] = np.asarray(
[[mu1, 0, 0], [0, mu2, omega], [0, -omega, mu2]]
).T
Xi_oscillator[terms.index("x0 x1"), 0] = sigma
Expand Down Expand Up @@ -426,7 +426,7 @@
beta = 8.0 / 3.0
terms = sindy_library.get_feature_names()
Xi_lorenz = np.zeros(Xi.shape)
Xi_lorenz[1: r + 1, :] = np.asarray(
Xi_lorenz[1 : r + 1, :] = np.asarray(
[[-sigma, sigma, 0], [rho, -1, 0], [0, 0, -beta]]
).T
Xi_lorenz[terms.index("x0 x2"), 1] = -1
Expand Down Expand Up @@ -637,7 +637,10 @@

# get analytic L and Q operators and galerkin model
L, Q = burgers_galerkin(sigma, nu, U)
def rhs(t, a): return galerkin_model(a, L, Q) # noqa: E731


def rhs(t, a):
return galerkin_model(a, L, Q) # noqa: E731


# Generate initial condition from unstable eigenvectors
Expand Down Expand Up @@ -740,7 +743,10 @@ def rhs(t, a): return galerkin_model(a, L, Q) # noqa: E731
galerkin5["L"] = galerkin9["L"][inds5]
inds5 = np.ix_([0, 1, 2, 3, -1], [0, 1, 2, 3, -1], [0, 1, 2, 3, -1])
galerkin5["Q"] = galerkin9["Q"][inds5]
def model5(t, a): return galerkin_model(a, galerkin5["L"], galerkin5["Q"]) # noqa: E731


def model5(t, a):
return galerkin_model(a, galerkin5["L"], galerkin5["Q"]) # noqa: E731


# make the 3D, 5D, and 9D POD-Galerkin trajectories
Expand Down
2 changes: 1 addition & 1 deletion examples/8_trapping_sindy_examples/trapping_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@

terms = sindy_library.get_feature_names()
Xi_lorenz = np.zeros(Xi.shape)
Xi_lorenz[1: r + 1, :] = np.array([[-sigma, sigma, 0], [rho, -1, 0], [0, 0, -beta]]).T
Xi_lorenz[1 : r + 1, :] = np.array([[-sigma, sigma, 0], [rho, -1, 0], [0, 0, -beta]]).T
Xi_lorenz[terms.index("x0 x2"), 1] = -1
Xi_lorenz[terms.index("x0 x1"), 2] = 1

Expand Down
68 changes: 37 additions & 31 deletions examples/8_trapping_sindy_examples/von_karman_trapping_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,32 @@
#
# ### This notebook will show that both the energy and enstrophy can be used with the trapping theorem to promote global stability.
# %%
from scipy.optimize import dual_annealing as anneal_algo
from trapping_utils import (
galerkin_model,
integrator_keywords,
nel,
nGLL,
interp,
get_velocity,
get_vorticity,
obj_function,
sindy_library_no_bias,
check_stability,
check_local_stability,
make_trap_progress_plots,
make_bar,
nx,
ny,
plot_field,
make_progress_plots,
)
import pymech.neksuite as nek
import warnings

import matplotlib.gridspec as gridspec
import numpy as np
import pymech.neksuite as nek
import scipy.io as sio
from matplotlib import pyplot as plt
from scipy.integrate import solve_ivp
from scipy.optimize import dual_annealing as anneal_algo
from trapping_utils import check_local_stability
from trapping_utils import check_stability
from trapping_utils import galerkin_model
from trapping_utils import get_velocity
from trapping_utils import get_vorticity
from trapping_utils import integrator_keywords
from trapping_utils import interp
from trapping_utils import make_bar
from trapping_utils import make_progress_plots
from trapping_utils import make_trap_progress_plots
from trapping_utils import nel
from trapping_utils import nGLL
from trapping_utils import nx
from trapping_utils import ny
from trapping_utils import obj_function
from trapping_utils import plot_field
from trapping_utils import sindy_library_no_bias

import pysindy as ps

Expand Down Expand Up @@ -85,12 +83,14 @@
)
/ 6.0
)
def model9(t, a): return galerkin_model(a, galerkin9["L"], galerkin9["Q"]) # noqa: E731


def model9_ep(t, a): return galerkin_model( # noqa: E731
a, galerkin9["L"], galerkin9["Q_ep"]
)
def model9(t, a):
return galerkin_model(a, galerkin9["L"], galerkin9["Q"]) # noqa: E731


def model9_ep(t, a):
return galerkin_model(a, galerkin9["L"], galerkin9["Q_ep"]) # noqa: E731


# Generate initial condition from unstable eigenvectors
Expand All @@ -107,7 +107,10 @@ def model9_ep(t, a): return galerkin_model( # noqa: E731
inds5 = np.ix_([0, 1, 2, 3, -1], [0, 1, 2, 3, -1], [0, 1, 2, 3, -1])
galerkin5["Q"] = galerkin9["Q"][inds5]
galerkin5["Q_ep"] = galerkin9["Q_ep"][inds5]
def model5(t, a): return galerkin_model(a, galerkin5["L"], galerkin5["Q"]) # noqa: E731


def model5(t, a):
return galerkin_model(a, galerkin5["L"], galerkin5["Q"]) # noqa: E731


# make the 5D POD-Galerkin model trajectories
Expand Down Expand Up @@ -171,7 +174,8 @@ def model5(t, a): return galerkin_model(a, galerkin5["L"], galerkin5["Q"]) # no
)


def filename(t_idx): return "cyl0.f{0:05d}".format(t_idx) # noqa: E731
def filename(t_idx):
return "cyl0.f{0:05d}".format(t_idx) # noqa: E731


# plot mean + leading POD modes
Expand Down Expand Up @@ -211,12 +215,14 @@ def filename(t_idx): return "cyl0.f{0:05d}".format(t_idx) # noqa: E731

# %%
mass_matrix = np.loadtxt("../data/vonKarman_pod/pod_modes/mass_matrix.dat")
def ip1(a, b): return np.dot(mass_matrix * a, b) # noqa: E731


def ip2(a, b, c, d): return np.dot(a * mass_matrix, c) + np.dot( # noqa: E731
b * mass_matrix, d
)
def ip1(a, b):
return np.dot(mass_matrix * a, b) # noqa: E731


def ip2(a, b, c, d):
return np.dot(a * mass_matrix, c) + np.dot(b * mass_matrix, d) # noqa: E731


energy_integrals = np.zeros((6, 6))
Expand Down
4 changes: 3 additions & 1 deletion pysindy/optimizers/constrained_sr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def _create_var_and_part_cost(
) -> Tuple[cp.Variable, cp.Expression]:
xi = cp.Variable(var_len)
cost = cp.sum_squares(x_expanded @ xi - y.flatten())
penalty = self._calculate_penalty(self.regularizer, np.ravel(self.reg_weight_lam), xi)
penalty = self._calculate_penalty(
self.regularizer, np.ravel(self.reg_weight_lam), xi
)
return xi, cost + penalty

def _update_coef_cvxpy(self, xi, cost, var_len, coef_prev, tol):
Expand Down
4 changes: 3 additions & 1 deletion pysindy/optimizers/stable_linear_sr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def _create_var_and_part_cost(
cost = cost + cp.sum_squares(xi - coef_neg_def.flatten()) / (
2 * self.relax_coeff_nu
)
penalty = self._calculate_penalty(self.thresholder, np.ravel(self.reg_weight_lam), xi)
penalty = self._calculate_penalty(
self.thresholder, np.ravel(self.reg_weight_lam), xi
)
return xi, cost + penalty

def _update_coef_cvxpy(self, x, y, coef_sparse, coef_negative_definite):
Expand Down

0 comments on commit 6209cad

Please sign in to comment.