From 0c437e8b4ecc33b83cbb81a2aa3c8be82f111de8 Mon Sep 17 00:00:00 2001 From: Charles Bennington <45837976+cbennington852@users.noreply.github.com> Date: Mon, 30 Jun 2025 10:32:58 -0700 Subject: [PATCH 01/11] Update mutators.py --- bdms/mutators.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bdms/mutators.py b/bdms/mutators.py index 162ff7a..1c6b514 100644 --- a/bdms/mutators.py +++ b/bdms/mutators.py @@ -200,6 +200,11 @@ def __init__( f"Transition matrix {transition_matrix} is not a valid stochastic" " matrix." ) + #check to make sure the diagonals are all zeros. + # "(not len(transition_matrix) == 1) " is required, because when we initiate the matrix, it looks like [[1.]] + # This requires a edge case. + if (not len(transition_matrix) == 1) and np.diag(transition_matrix).any(): + raise ValueError(f"transition_matrix diagonal must be zero.") super().__init__(attr=attr) self.state_space = state_space self.state_space_idxs: dict[Any, int] = { From 49f72f24d3db247d09c1c472cb8eb3e240391a7f Mon Sep 17 00:00:00 2001 From: Charles Bennington <45837976+cbennington852@users.noreply.github.com> Date: Mon, 30 Jun 2025 10:34:06 -0700 Subject: [PATCH 02/11] Update poisson.py --- bdms/poisson.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bdms/poisson.py b/bdms/poisson.py index 0b4f794..6831bf8 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -196,6 +196,8 @@ class ConstantProcess(HomogeneousProcess): def __init__(self, value: float = 1.0): super().__init__() self.value = value + if self.value < 0: + raise ValueError(f"The constant rate must be a non-negative float") def λ_homogeneous( self, x: Hashable | Sequence[Hashable] | NDArray[Any] @@ -216,6 +218,9 @@ def __init__( self, rates: Mapping[Hashable, float] | Sequence[float], attr: str = "state" ): super().__init__(attr=attr) + for rate in rates: + if rate < 0: + raise ValueError(f"The rate for each state must tbe greater or equal to zero. ") self.rates = rates def λ_homogeneous( From 517d8c73b2bc564be20ae059ed283c516cbce163 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 13:59:54 -0700 Subject: [PATCH 03/11] Update mutators.py --- bdms/mutators.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bdms/mutators.py b/bdms/mutators.py index 1c6b514..99fb0e3 100644 --- a/bdms/mutators.py +++ b/bdms/mutators.py @@ -200,11 +200,8 @@ def __init__( f"Transition matrix {transition_matrix} is not a valid stochastic" " matrix." ) - #check to make sure the diagonals are all zeros. - # "(not len(transition_matrix) == 1) " is required, because when we initiate the matrix, it looks like [[1.]] - # This requires a edge case. if (not len(transition_matrix) == 1) and np.diag(transition_matrix).any(): - raise ValueError(f"transition_matrix diagonal must be zero.") + raise ValueError("transition_matrix diagonal must be zero.") super().__init__(attr=attr) self.state_space = state_space self.state_space_idxs: dict[Any, int] = { From 84d34669532afbbdf9940e295288c21a0ed1a728 Mon Sep 17 00:00:00 2001 From: Charles Bennington <45837976+cbennington852@users.noreply.github.com> Date: Mon, 30 Jun 2025 14:01:23 -0700 Subject: [PATCH 04/11] Update mutators.py --- bdms/mutators.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bdms/mutators.py b/bdms/mutators.py index 1c6b514..6ed3b80 100644 --- a/bdms/mutators.py +++ b/bdms/mutators.py @@ -200,11 +200,8 @@ def __init__( f"Transition matrix {transition_matrix} is not a valid stochastic" " matrix." ) - #check to make sure the diagonals are all zeros. - # "(not len(transition_matrix) == 1) " is required, because when we initiate the matrix, it looks like [[1.]] - # This requires a edge case. if (not len(transition_matrix) == 1) and np.diag(transition_matrix).any(): - raise ValueError(f"transition_matrix diagonal must be zero.") + raise ValueError("transition_matrix diagonal must be zero.") super().__init__(attr=attr) self.state_space = state_space self.state_space_idxs: dict[Any, int] = { From a6962cad59e48f5de6ed71c2075274dc77bcb301 Mon Sep 17 00:00:00 2001 From: Charles Bennington <45837976+cbennington852@users.noreply.github.com> Date: Mon, 30 Jun 2025 14:17:36 -0700 Subject: [PATCH 05/11] Update mutators.py --- bdms/mutators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdms/mutators.py b/bdms/mutators.py index 6ed3b80..99fb0e3 100644 --- a/bdms/mutators.py +++ b/bdms/mutators.py @@ -201,7 +201,7 @@ def __init__( " matrix." ) if (not len(transition_matrix) == 1) and np.diag(transition_matrix).any(): - raise ValueError("transition_matrix diagonal must be zero.") + raise ValueError("transition_matrix diagonal must be zero.") super().__init__(attr=attr) self.state_space = state_space self.state_space_idxs: dict[Any, int] = { From 9746d25c0f658795e1b1aa214bd30495ef7e5bab Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 14:28:46 -0700 Subject: [PATCH 06/11] linter --- .flake8 | 4 ++++ pyproject.toml | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/.flake8 b/.flake8 index 5ff4b7c..5c3d2ba 100644 --- a/.flake8 +++ b/.flake8 @@ -4,7 +4,11 @@ count = True max-line-length = 88 extend-ignore = E203 exclude = + .venv, + venv, .vscode, .conda, + .venv, + tests.venv/, .hatch, __pycache__ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7365981..a692a4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,6 +51,8 @@ packages = ["bdms"] [tool.hatch.version] path = "bdms/__init__.py" + + # this puts hatch envs in a .hatch directory, so vscode can find them @@ -102,3 +104,6 @@ format = [ "black .", "docformatter --black --in-place **/*.py", ] + +[tool.flake8] +exclude = ".venv,venv" \ No newline at end of file From d9bfcba085fa2cd777210a4a64e5b9ee9984e317 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 15:24:07 -0700 Subject: [PATCH 07/11] more changes --- bdms/poisson.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bdms/poisson.py b/bdms/poisson.py index 6831bf8..c351fea 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -197,7 +197,7 @@ def __init__(self, value: float = 1.0): super().__init__() self.value = value if self.value < 0: - raise ValueError(f"The constant rate must be a non-negative float") + raise ValueError("The constant rate must be a non-negative float") def λ_homogeneous( self, x: Hashable | Sequence[Hashable] | NDArray[Any] @@ -220,7 +220,7 @@ def __init__( super().__init__(attr=attr) for rate in rates: if rate < 0: - raise ValueError(f"The rate for each state must tbe greater or equal to zero. ") + raise ValueError("The rate for each state must tbe greater or equal to zero. ") self.rates = rates def λ_homogeneous( From 60bfeeb28c23607a499abc39986466598615c549 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 15:25:40 -0700 Subject: [PATCH 08/11] fighting with the lintier --- bdms/poisson.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bdms/poisson.py b/bdms/poisson.py index c351fea..f74c200 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -220,7 +220,8 @@ def __init__( super().__init__(attr=attr) for rate in rates: if rate < 0: - raise ValueError("The rate for each state must tbe greater or equal to zero. ") + raise ValueError(f"The rate for each state must tbe greater " + "or equal to zero. ") self.rates = rates def λ_homogeneous( From 0393beee99bb79ae4992d87fc22e9be77a25f503 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 15:29:07 -0700 Subject: [PATCH 09/11] more fighting with linter --- bdms/poisson.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdms/poisson.py b/bdms/poisson.py index f74c200..9163752 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -220,7 +220,7 @@ def __init__( super().__init__(attr=attr) for rate in rates: if rate < 0: - raise ValueError(f"The rate for each state must tbe greater " + raise ValueError("The rate for each state must tbe greater " "or equal to zero. ") self.rates = rates From 65511db6743a78a27241ce9bde7281ce64dca034 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Mon, 30 Jun 2025 15:35:39 -0700 Subject: [PATCH 10/11] both linters are happy now --- bdms/poisson.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bdms/poisson.py b/bdms/poisson.py index 9163752..cfb91db 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -220,8 +220,7 @@ def __init__( super().__init__(attr=attr) for rate in rates: if rate < 0: - raise ValueError("The rate for each state must tbe greater " - "or equal to zero. ") + raise ValueError("The rate for each state must be >= 0") self.rates = rates def λ_homogeneous( From aa27a79587e076d30ff0b971c014a9a11e5961e4 Mon Sep 17 00:00:00 2001 From: Charles Bennington Date: Tue, 1 Jul 2025 10:34:11 -0700 Subject: [PATCH 11/11] Fixed type errors --- bdms/poisson.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bdms/poisson.py b/bdms/poisson.py index cfb91db..22d6934 100644 --- a/bdms/poisson.py +++ b/bdms/poisson.py @@ -218,9 +218,14 @@ def __init__( self, rates: Mapping[Hashable, float] | Sequence[float], attr: str = "state" ): super().__init__(attr=attr) - for rate in rates: - if rate < 0: - raise ValueError("The rate for each state must be >= 0") + if isinstance(rates, Mapping): + for rate in rates.values(): + if rate < 0.0: + raise ValueError("The rate for each state must be >= 0") + else: + for rate in rates: + if rate < 0.0: + raise ValueError("The rate for each state must be >= 0") self.rates = rates def λ_homogeneous(