Skip to content

Commit

Permalink
Merge pull request #449 from mj-will/update-ruff
Browse files Browse the repository at this point in the history
MAINT: update ruff
  • Loading branch information
mj-will authored Jan 9, 2025
2 parents 152b437 + d08f001 commit 17db788
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
- uses: astral-sh/ruff-action@v3
with:
version: "0.9.x"
args: 'format --check'
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.4
rev: v0.9.0
hooks:
# Run the linter.
- id: ruff
Expand Down
5 changes: 2 additions & 3 deletions src/nessai/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def logsubexp(x, y):
"""
if np.any(x < y):
raise RuntimeError(
"cannot take log of negative number " f"{str(x)!s} - {str(y)!s}"
f"cannot take log of negative number {str(x)!s} - {str(y)!s}"
)

return x + np.log1p(-np.exp(y - x))
Expand Down Expand Up @@ -237,8 +237,7 @@ def plot(self, filename=None):
fig = plt.figure()
plt.plot(self.log_vols, self.logLs)
plt.title(
f"log Z={self.logZ:.2f} "
f"H={self.info[-1] * np.log2(np.e):.2f} bits"
f"log Z={self.logZ:.2f} H={self.info[-1] * np.log2(np.e):.2f} bits"
)
plt.grid(which="both")
plt.xlabel("log prior-volume")
Expand Down
4 changes: 2 additions & 2 deletions src/nessai/flows/realnvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def create_net(in_features, out_features):
)
if dropout_probability:
logger.warning(
"Dropout not supported for MLP, " "will be ignored"
"Dropout not supported for MLP, will be ignored"
)
hidden_features = num_blocks_per_layer * [hidden_features]

Expand All @@ -169,7 +169,7 @@ def create_net(in_features, out_features):

else:
raise ValueError(
f"Unknown nn type: {net}. " "Choose from: {resnet, mlp}."
f"Unknown nn type: {net}. Choose from: {{resnet, mlp}}."
)

layers = []
Expand Down
8 changes: 3 additions & 5 deletions src/nessai/flowsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,9 @@ def _resume_from_file(
)
except RuntimeError as e:
logger.error(
"Could not load old resume " f"file from: {self.output}"
)
raise RuntimeError(
"Could not resume sampler " f"with error: {e}"
f"Could not load old resume file from: {self.output}"
)
raise RuntimeError(f"Could not resume sampler with error: {e}")
return ns

def _resume_from_data(
Expand Down Expand Up @@ -398,7 +396,7 @@ def run_standard_sampler(
rng=self.rng,
)
logger.info(
f"Returned {self.posterior_samples.size} " "posterior samples"
f"Returned {self.posterior_samples.size} posterior samples"
)

if save:
Expand Down
4 changes: 2 additions & 2 deletions src/nessai/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,11 @@ def verify_model(self):

if self.log_prior(x) is None:
raise RuntimeError(
"Log-prior function did not return " "a prior value"
"Log-prior function did not return a prior value"
)
if self.log_likelihood(x) is None:
raise RuntimeError(
"Log-likelihood function did not return " "a likelihood value"
"Log-likelihood function did not return a likelihood value"
)

if self.allow_multi_valued_likelihood:
Expand Down
8 changes: 2 additions & 6 deletions src/nessai/proposal/flowproposal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ def configure_reparameterisations(self, reparameterisations):
for k, cfg in _reparameterisations.items():
if k in self.model.names:
logger.debug(
f"Found parameter {k} in model, "
"assuming it is a parameter"
f"Found parameter {k} in model, assuming it is a parameter"
)
if isinstance(cfg, str) or cfg is None:
rc, default_config = self.get_reparameterisation(cfg)
Expand Down Expand Up @@ -575,10 +574,7 @@ def names(self):
@property
def rescaled_names(self):
warn(
(
"`rescaled_names` is deprecated, use `prime_parameters` "
"instead"
),
("`rescaled_names` is deprecated, use `prime_parameters` instead"),
FutureWarning,
)
return self.prime_parameters
Expand Down
5 changes: 2 additions & 3 deletions src/nessai/samplers/importancesampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,8 +1156,7 @@ def draw_n_samples(self, n: int, **kwargs):
unit_hypercube=True,
)
logger.debug(
"Min. log-likelihood of new samples: "
f"{np.min(new_points['logL'])}"
f"Min. log-likelihood of new samples: {np.min(new_points['logL'])}"
)
if not np.isfinite(new_points["logL"]).all():
logger.warning("Log-likelihood contains infs")
Expand Down Expand Up @@ -1221,7 +1220,7 @@ def add_and_update_points(self, n: int):
self._current_proposal_entropy = differential_entropy(-log_q[:, -1])

logger.debug(
"New samples ESS: " f"{effective_sample_size(new_samples['logW'])}"
f"New samples ESS: {effective_sample_size(new_samples['logW'])}"
)

if self.plot and self.plot_pool:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gw/test_gw_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_augmented_reparameterisation_prime_prior(augmented_proposal):
augmented_proposal._reparameterisation = MagicMock()

with patch(
"nessai.proposal.flowproposal.FlowProposal." "x_prime_log_prior"
"nessai.proposal.flowproposal.FlowProposal.x_prime_log_prior"
) as mock:
AugmentedGWFlowProposal.x_prime_log_prior(augmented_proposal, 1)

Expand Down

0 comments on commit 17db788

Please sign in to comment.