From 08849c6a9c4734e9fbf339dfc195dfc958b3f148 Mon Sep 17 00:00:00 2001 From: mj-will Date: Sat, 24 Feb 2024 18:01:54 +0000 Subject: [PATCH 1/3] MAINT: update black to v24.x --- .github/workflows/lint.yml | 2 +- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fec6e63e..fbbe4846 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: - uses: psf/black@stable with: options: "--check --diff" - version: "22.12" + version: "24.2" flake8: name: Lint - Flake8 runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 023648c9..1b2d1f48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 24.2.0 hooks: - id: black language_version: python3 diff --git a/pyproject.toml b/pyproject.toml index 18a2b9bb..6f05da90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ dev = [ "pre-commit", "ray[default]", "corner", + "black>=24.0", ] docs = [ "sphinx", @@ -104,4 +105,3 @@ target-version = [ extend-ignore = [ "E203", ] - From 3974750a1c512489a23b83ae799bd2de929c8619 Mon Sep 17 00:00:00 2001 From: mj-will Date: Sat, 24 Feb 2024 18:06:48 +0000 Subject: [PATCH 2/3] STY: apply black 24.x --- nessai/samplers/base.py | 6 +-- nessai/samplers/importancesampler.py | 54 +++++++++---------- nessai/utils/settings.py | 1 + tests/conftest.py | 1 + tests/test_config.py | 1 + tests/test_evidence/test_ins_evidence.py | 1 + .../test_flowmodel_importance.py | 1 + tests/test_gw/conftest.py | 1 + .../test_reparameterisation_integration.py | 1 + tests/test_livepoint.py | 1 + tests/test_priors.py | 1 + .../test_proposal/test_importance/conftest.py | 1 + .../test_importance/test_config.py | 1 + .../test_importance/test_prob.py | 1 + .../test_importance/test_properties.py | 1 + .../test_importance/test_rescaling.py | 1 + .../test_importance/test_resume.py | 1 + .../test_importance/test_sampling.py | 1 + .../test_importance/test_training.py | 1 + tests/test_reparameterisations/conftest.py | 1 + .../test_config.py | 1 + .../test_proposal.py | 1 + .../test_result.py | 1 + .../test_samples.py | 1 + .../test_threshold.py | 1 + tests/test_sampling/test_ins_sampling.py | 1 + tests/test_utils/test_sorting_utils.py | 1 + tests/test_utils/test_testing_utils.py | 1 + 28 files changed, 56 insertions(+), 30 deletions(-) diff --git a/nessai/samplers/base.py b/nessai/samplers/base.py index 7a60c8ba..f0cab943 100644 --- a/nessai/samplers/base.py +++ b/nessai/samplers/base.py @@ -384,9 +384,9 @@ def get_result_dictionary(self): d["seed"] = self.seed d["sampling_time"] = self.sampling_time.total_seconds() d["total_likelihood_evaluations"] = self.model.likelihood_evaluations - d[ - "likelihood_evaluation_time" - ] = self.likelihood_evaluation_time.total_seconds() + d["likelihood_evaluation_time"] = ( + self.likelihood_evaluation_time.total_seconds() + ) d["history"] = self.history if hasattr(self.model, "truth"): d["truth"] = self.model.truth diff --git a/nessai/samplers/importancesampler.py b/nessai/samplers/importancesampler.py index 7e04fa21..523e3bf2 100644 --- a/nessai/samplers/importancesampler.py +++ b/nessai/samplers/importancesampler.py @@ -1219,10 +1219,10 @@ def add_and_update_points(self, n: int): self.training_samples.samples, self.training_samples.log_q ) - self.training_samples.samples[ - "logQ" - ] = self.proposal.compute_meta_proposal_from_log_q( - self.training_samples.log_q + self.training_samples.samples["logQ"] = ( + self.proposal.compute_meta_proposal_from_log_q( + self.training_samples.log_q + ) ) self.training_samples.samples["logW"] = -self.training_samples.samples[ "logQ" @@ -1239,10 +1239,10 @@ def add_and_update_points(self, n: int): self.iid_samples.log_q = self.proposal.update_log_q( self.iid_samples.samples, self.iid_samples.log_q ) - self.iid_samples.samples[ - "logQ" - ] = self.proposal.compute_meta_proposal_from_log_q( - self.iid_samples.log_q + self.iid_samples.samples["logQ"] = ( + self.proposal.compute_meta_proposal_from_log_q( + self.iid_samples.log_q + ) ) self.iid_samples.samples["logW"] = -self.iid_samples.samples[ "logQ" @@ -1316,10 +1316,10 @@ def adjust_final_samples(self, n_batches=5): update_counts=False, ) new_samples["it"] = it - new_samples[ - "logL" - ] = self.model.batch_evaluate_log_likelihood( - new_samples, unit_hypercube=True + new_samples["logL"] = ( + self.model.batch_evaluate_log_likelihood( + new_samples, unit_hypercube=True + ) ) new_loc = np.searchsorted(samples["it"], new_samples["it"]) samples = np.insert(samples, new_loc, new_samples) @@ -2227,20 +2227,20 @@ def get_result_dictionary(self): self.training_samples.samples ) d["training_log_evidence"] = self.training_samples.state.log_evidence - d[ - "training_log_evidence_error" - ] = self.training_samples.state.log_evidence_error - d[ - "training_log_posterior_weights" - ] = self.training_samples.state.log_posterior_weights + d["training_log_evidence_error"] = ( + self.training_samples.state.log_evidence_error + ) + d["training_log_posterior_weights"] = ( + self.training_samples.state.log_posterior_weights + ) # Will all be None if the final samples haven't been drawn d["bootstrap_log_evidence"] = self.bootstrap_log_evidence d["bootstrap_log_evidence_error"] = self.bootstrap_log_evidence_error if self.iid_samples: d["iid_log_evidence"] = self.iid_samples.state.log_evidence - d[ - "iid_log_evidence_error" - ] = self.iid_samples.state.log_evidence_error + d["iid_log_evidence_error"] = ( + self.iid_samples.state.log_evidence_error + ) d["samples"] = self.final_samples d["log_posterior_weights"] = self.final_log_posterior_weights d["log_evidence"] = self.final_log_evidence @@ -2248,12 +2248,12 @@ def get_result_dictionary(self): d["training_time"] = self.training_time.total_seconds() d["draw_samples_time"] = self.draw_samples_time.total_seconds() - d[ - "add_and_update_samples_time" - ] = self.add_and_update_samples_time.total_seconds() - d[ - "draw_final_samples_time" - ] = self.draw_final_samples_time.total_seconds() + d["add_and_update_samples_time"] = ( + self.add_and_update_samples_time.total_seconds() + ) + d["draw_final_samples_time"] = ( + self.draw_final_samples_time.total_seconds() + ) d["proposal_importance"] = self.importance return d diff --git a/nessai/utils/settings.py b/nessai/utils/settings.py index 99aa0add..8ccb5faa 100644 --- a/nessai/utils/settings.py +++ b/nessai/utils/settings.py @@ -2,6 +2,7 @@ Used for bilby and pycbc-inference. """ + from inspect import signature from typing import List, Callable, Tuple diff --git a/tests/conftest.py b/tests/conftest.py index df6fb178..43f59a30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """General configuration for the test suite""" + import sys from numpy.random import seed diff --git a/tests/test_config.py b/tests/test_config.py index a5d95a76..320a3051 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,5 @@ """Tests for the config module""" + from nessai.config import LivepointsConfig import numpy as np diff --git a/tests/test_evidence/test_ins_evidence.py b/tests/test_evidence/test_ins_evidence.py index e6f39073..862c32b5 100644 --- a/tests/test_evidence/test_ins_evidence.py +++ b/tests/test_evidence/test_ins_evidence.py @@ -1,4 +1,5 @@ """Test the INS evidence""" + from unittest.mock import MagicMock, create_autospec import numpy as np diff --git a/tests/test_flowmodel/test_flowmodel_importance.py b/tests/test_flowmodel/test_flowmodel_importance.py index f64e7e28..c5d7c6c6 100644 --- a/tests/test_flowmodel/test_flowmodel_importance.py +++ b/tests/test_flowmodel/test_flowmodel_importance.py @@ -1,6 +1,7 @@ """ Test the ImportanceFlowModel. """ + import os import pickle from unittest.mock import MagicMock, create_autospec, patch diff --git a/tests/test_gw/conftest.py b/tests/test_gw/conftest.py index 614c5eb5..cffa9380 100644 --- a/tests/test_gw/conftest.py +++ b/tests/test_gw/conftest.py @@ -1,4 +1,5 @@ """Configuration for the GW tests""" + from typing import Callable from nessai.livepoint import dict_to_live_points diff --git a/tests/test_gw/test_reparameterisation_integration.py b/tests/test_gw/test_reparameterisation_integration.py index 0a24f6cd..3b689dc0 100644 --- a/tests/test_gw/test_reparameterisation_integration.py +++ b/tests/test_gw/test_reparameterisation_integration.py @@ -1,4 +1,5 @@ """Integration test for the reparameterisation in GWFlowProposal""" + from nessai.gw.proposal import GWFlowProposal import numpy as np import pytest diff --git a/tests/test_livepoint.py b/tests/test_livepoint.py index c4bec4d0..4db1ea00 100644 --- a/tests/test_livepoint.py +++ b/tests/test_livepoint.py @@ -1,4 +1,5 @@ """Tests for livepoint functions""" + import sys import numpy as np diff --git a/tests/test_priors.py b/tests/test_priors.py index 4b84c510..d69e93ce 100644 --- a/tests/test_priors.py +++ b/tests/test_priors.py @@ -1,6 +1,7 @@ """ Test the prior functions. """ + import numpy as np import pytest diff --git a/tests/test_proposal/test_importance/conftest.py b/tests/test_proposal/test_importance/conftest.py index 6a27edc2..70d01f3f 100644 --- a/tests/test_proposal/test_importance/conftest.py +++ b/tests/test_proposal/test_importance/conftest.py @@ -1,4 +1,5 @@ """Configuration for ImportanceFlowProposal tests""" + import pytest from unittest.mock import MagicMock, create_autospec diff --git a/tests/test_proposal/test_importance/test_config.py b/tests/test_proposal/test_importance/test_config.py index d9887f53..bf17c91a 100644 --- a/tests/test_proposal/test_importance/test_config.py +++ b/tests/test_proposal/test_importance/test_config.py @@ -1,4 +1,5 @@ """Test the general configuration for ImportanceFlowProposal""" + import pytest from unittest.mock import MagicMock, patch diff --git a/tests/test_proposal/test_importance/test_prob.py b/tests/test_proposal/test_importance/test_prob.py index 93dae736..bc228b1b 100644 --- a/tests/test_proposal/test_importance/test_prob.py +++ b/tests/test_proposal/test_importance/test_prob.py @@ -1,4 +1,5 @@ """Tests methods for computing log_prob etc""" + from unittest.mock import MagicMock, create_autospec from nessai.livepoint import live_points_to_array diff --git a/tests/test_proposal/test_importance/test_properties.py b/tests/test_proposal/test_importance/test_properties.py index e3b601ef..56388a74 100644 --- a/tests/test_proposal/test_importance/test_properties.py +++ b/tests/test_proposal/test_importance/test_properties.py @@ -1,4 +1,5 @@ """Test the properties defined in ImportanceFlowProposal""" + from unittest.mock import patch from nessai.proposal.importance import ImportanceFlowProposal as IFP import pytest diff --git a/tests/test_proposal/test_importance/test_rescaling.py b/tests/test_proposal/test_importance/test_rescaling.py index dc1889ac..a0ad8167 100644 --- a/tests/test_proposal/test_importance/test_rescaling.py +++ b/tests/test_proposal/test_importance/test_rescaling.py @@ -1,4 +1,5 @@ """Test the rescaling functions in ImportanceFlowProposal""" + from unittest.mock import MagicMock, patch from nessai import config diff --git a/tests/test_proposal/test_importance/test_resume.py b/tests/test_proposal/test_importance/test_resume.py index 2ddd83e0..3fe012b1 100644 --- a/tests/test_proposal/test_importance/test_resume.py +++ b/tests/test_proposal/test_importance/test_resume.py @@ -1,4 +1,5 @@ """Test the properties defined in ImportanceFlowProposal""" + import pickle from unittest.mock import MagicMock, patch diff --git a/tests/test_proposal/test_importance/test_sampling.py b/tests/test_proposal/test_importance/test_sampling.py index 00ba2770..4d626b3b 100644 --- a/tests/test_proposal/test_importance/test_sampling.py +++ b/tests/test_proposal/test_importance/test_sampling.py @@ -1,4 +1,5 @@ """Tests related to sampling from ImportanceFlowProposal""" + from unittest.mock import MagicMock, create_autospec from nessai.flowmodel.importance import ImportanceFlowModel diff --git a/tests/test_proposal/test_importance/test_training.py b/tests/test_proposal/test_importance/test_training.py index dd527e0d..4b927348 100644 --- a/tests/test_proposal/test_importance/test_training.py +++ b/tests/test_proposal/test_importance/test_training.py @@ -1,4 +1,5 @@ """Test training functions in ImportanceFlowProposal""" + import os from nessai.proposal.importance import ImportanceFlowProposal as IFP diff --git a/tests/test_reparameterisations/conftest.py b/tests/test_reparameterisations/conftest.py index 286b964f..2ff66b2f 100644 --- a/tests/test_reparameterisations/conftest.py +++ b/tests/test_reparameterisations/conftest.py @@ -1,4 +1,5 @@ """Configuration for the reparameterisation tests""" + from dataclasses import dataclass from typing import List diff --git a/tests/test_samplers/test_importance_nested_sampler/test_config.py b/tests/test_samplers/test_importance_nested_sampler/test_config.py index a8463c3b..faabeacd 100644 --- a/tests/test_samplers/test_importance_nested_sampler/test_config.py +++ b/tests/test_samplers/test_importance_nested_sampler/test_config.py @@ -1,4 +1,5 @@ """Test configuration of INS""" + from unittest.mock import MagicMock from nessai import config as nessai_config diff --git a/tests/test_samplers/test_importance_nested_sampler/test_proposal.py b/tests/test_samplers/test_importance_nested_sampler/test_proposal.py index 84545b86..0fc26fba 100644 --- a/tests/test_samplers/test_importance_nested_sampler/test_proposal.py +++ b/tests/test_samplers/test_importance_nested_sampler/test_proposal.py @@ -1,4 +1,5 @@ """Tests for the proposals and meta-proposal""" + import datetime from unittest.mock import MagicMock diff --git a/tests/test_samplers/test_importance_nested_sampler/test_result.py b/tests/test_samplers/test_importance_nested_sampler/test_result.py index d02e5431..8ec408c2 100644 --- a/tests/test_samplers/test_importance_nested_sampler/test_result.py +++ b/tests/test_samplers/test_importance_nested_sampler/test_result.py @@ -1,4 +1,5 @@ """Tests related to the results returned by the sampler""" + import datetime from unittest.mock import MagicMock, create_autospec diff --git a/tests/test_samplers/test_importance_nested_sampler/test_samples.py b/tests/test_samplers/test_importance_nested_sampler/test_samples.py index 30d3f7ab..74cdae36 100644 --- a/tests/test_samplers/test_importance_nested_sampler/test_samples.py +++ b/tests/test_samplers/test_importance_nested_sampler/test_samples.py @@ -1,4 +1,5 @@ """Tests related to how samples are handled""" + from unittest.mock import MagicMock, create_autospec from nessai.livepoint import numpy_array_to_live_points diff --git a/tests/test_samplers/test_importance_nested_sampler/test_threshold.py b/tests/test_samplers/test_importance_nested_sampler/test_threshold.py index c9d9e8d1..8b634f3e 100644 --- a/tests/test_samplers/test_importance_nested_sampler/test_threshold.py +++ b/tests/test_samplers/test_importance_nested_sampler/test_threshold.py @@ -1,4 +1,5 @@ """Tests for level-related methods""" + import os from unittest.mock import MagicMock diff --git a/tests/test_sampling/test_ins_sampling.py b/tests/test_sampling/test_ins_sampling.py index e860941a..e0f17ab0 100644 --- a/tests/test_sampling/test_ins_sampling.py +++ b/tests/test_sampling/test_ins_sampling.py @@ -1,4 +1,5 @@ """Test sampling with the importance nested sampler""" + import os import pickle diff --git a/tests/test_utils/test_sorting_utils.py b/tests/test_utils/test_sorting_utils.py index a7a633b9..63f4c3f2 100644 --- a/tests/test_utils/test_sorting_utils.py +++ b/tests/test_utils/test_sorting_utils.py @@ -1,4 +1,5 @@ """Tests for the sorting utilities""" + from dataclasses import dataclass from typing import List diff --git a/tests/test_utils/test_testing_utils.py b/tests/test_utils/test_testing_utils.py index 7abfc935..ca63a90b 100644 --- a/tests/test_utils/test_testing_utils.py +++ b/tests/test_utils/test_testing_utils.py @@ -1,6 +1,7 @@ """ Test the testing utilities """ + import numpy as np import pytest From 736e95d286c5d9a4f4a06790198bfd714d775682 Mon Sep 17 00:00:00 2001 From: mj-will Date: Sat, 24 Feb 2024 18:07:28 +0000 Subject: [PATCH 3/3] MAINT: fix typo in doc-string --- nessai/utils/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nessai/utils/settings.py b/nessai/utils/settings.py index 8ccb5faa..e7e056ac 100644 --- a/nessai/utils/settings.py +++ b/nessai/utils/settings.py @@ -1,4 +1,4 @@ -"""Utilities for determing the settings available in nessai. +"""Utilities for determining the settings available in nessai. Used for bilby and pycbc-inference. """