Skip to content

Commit

Permalink
Merge pull request #370 from mj-will/update--to-black-2024
Browse files Browse the repository at this point in the history
Update to black 2024
  • Loading branch information
mj-will authored Feb 24, 2024
2 parents 24e8e5b + 736e95d commit 8925035
Show file tree
Hide file tree
Showing 31 changed files with 60 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions nessai/samplers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 27 additions & 27 deletions nessai/samplers/importancesampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2227,33 +2227,33 @@ 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
d["log_evidence_error"] = self.final_log_evidence_error

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
Expand Down
3 changes: 2 additions & 1 deletion nessai/utils/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Utilities for determing the settings available in nessai.
"""Utilities for determining the settings available in nessai.
Used for bilby and pycbc-inference.
"""

from inspect import signature
from typing import List, Callable, Tuple

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dev = [
"pre-commit",
"ray[default]",
"corner",
"black>=24.0",
]
docs = [
"sphinx",
Expand Down Expand Up @@ -104,4 +105,3 @@ target-version = [
extend-ignore = [
"E203",
]

1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""General configuration for the test suite"""

import sys

from numpy.random import seed
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the config module"""

from nessai.config import LivepointsConfig
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions tests/test_evidence/test_ins_evidence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the INS evidence"""

from unittest.mock import MagicMock, create_autospec

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tests/test_flowmodel/test_flowmodel_importance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the ImportanceFlowModel.
"""

import os
import pickle
from unittest.mock import MagicMock, create_autospec, patch
Expand Down
1 change: 1 addition & 0 deletions tests/test_gw/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for the GW tests"""

from typing import Callable

from nessai.livepoint import dict_to_live_points
Expand Down
1 change: 1 addition & 0 deletions tests/test_gw/test_reparameterisation_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Integration test for the reparameterisation in GWFlowProposal"""

from nessai.gw.proposal import GWFlowProposal
import numpy as np
import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_livepoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for livepoint functions"""

import sys

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions tests/test_priors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the prior functions.
"""

import numpy as np
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for ImportanceFlowProposal tests"""

import pytest
from unittest.mock import MagicMock, create_autospec

Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the general configuration for ImportanceFlowProposal"""

import pytest
from unittest.mock import MagicMock, patch

Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_prob.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_properties.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_rescaling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the rescaling functions in ImportanceFlowProposal"""

from unittest.mock import MagicMock, patch

from nessai import config
Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_resume.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the properties defined in ImportanceFlowProposal"""

import pickle
from unittest.mock import MagicMock, patch

Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_sampling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to sampling from ImportanceFlowProposal"""

from unittest.mock import MagicMock, create_autospec

from nessai.flowmodel.importance import ImportanceFlowModel
Expand Down
1 change: 1 addition & 0 deletions tests/test_proposal/test_importance/test_training.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test training functions in ImportanceFlowProposal"""

import os

from nessai.proposal.importance import ImportanceFlowProposal as IFP
Expand Down
1 change: 1 addition & 0 deletions tests/test_reparameterisations/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configuration for the reparameterisation tests"""

from dataclasses import dataclass
from typing import List

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test configuration of INS"""

from unittest.mock import MagicMock

from nessai import config as nessai_config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the proposals and meta-proposal"""

import datetime
from unittest.mock import MagicMock

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests related to the results returned by the sampler"""

import datetime
from unittest.mock import MagicMock, create_autospec

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for level-related methods"""

import os
from unittest.mock import MagicMock

Expand Down
1 change: 1 addition & 0 deletions tests/test_sampling/test_ins_sampling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test sampling with the importance nested sampler"""

import os
import pickle

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils/test_sorting_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the sorting utilities"""

from dataclasses import dataclass
from typing import List

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils/test_testing_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the testing utilities
"""

import numpy as np
import pytest

Expand Down

0 comments on commit 8925035

Please sign in to comment.