Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
ignore = E127,E201,E202,E203,E231,E252,E266,E402,E999,F841,W503,W605
ignore = E127,E201,E202,E203,E231,E252,E266,E402,E999,F841,W503,W605,E704
max-line-length = 80
exclude = .git,docs,docsrc,scripts,cmdstanpy_tutorial.py,rtd_change_default_version.py
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ exclude: 'docsrc'
fail_fast: true
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v6.0.0
hooks:
- id: check-yaml
# isort should run before black as black sometimes tweaks the isort output
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 7.0.0
hooks:
- id: isort
# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 25.9.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
rev: v1.18.2
hooks:
- id: mypy
additional_dependencies: [ numpy >= 1.22]
Expand Down
136 changes: 68 additions & 68 deletions cmdstanpy/cmdstan_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import os
from enum import Enum, auto
from time import time
from typing import Any, Mapping, Optional, Union
from typing import Any, Mapping

import numpy as np
from numpy.random import default_rng

from cmdstanpy.utils import cmdstan_path, cmdstan_version_before, get_logger

OptionalPath = Union[str, os.PathLike, None]
OptionalPath = str | os.PathLike | None


class Method(Enum):
Expand Down Expand Up @@ -52,19 +52,19 @@ class SamplerArgs:

def __init__(
self,
iter_warmup: Optional[int] = None,
iter_sampling: Optional[int] = None,
iter_warmup: int | None = None,
iter_sampling: int | None = None,
save_warmup: bool = False,
thin: Optional[int] = None,
max_treedepth: Optional[int] = None,
metric_type: Optional[str] = None,
metric_file: Union[str, list[str], None] = None,
step_size: Union[float, list[float], None] = None,
thin: int | None = None,
max_treedepth: int | None = None,
metric_type: str | None = None,
metric_file: str | list[str] | None = None,
step_size: float | list[float] | None = None,
adapt_engaged: bool = True,
adapt_delta: Optional[float] = None,
adapt_init_phase: Optional[int] = None,
adapt_metric_window: Optional[int] = None,
adapt_step_size: Optional[int] = None,
adapt_delta: float | None = None,
adapt_init_phase: int | None = None,
adapt_metric_window: int | None = None,
adapt_step_size: int | None = None,
fixed_param: bool = False,
num_chains: int = 1,
) -> None:
Expand All @@ -74,8 +74,8 @@ def __init__(
self.save_warmup = save_warmup
self.thin = thin
self.max_treedepth = max_treedepth
self.metric_type: Optional[str] = metric_type
self.metric_file: Union[str, list[str], None] = metric_file
self.metric_type: str | None = metric_type
self.metric_file: str | list[str] | None = metric_file
self.step_size = step_size
self.adapt_engaged = adapt_engaged
self.adapt_delta = adapt_delta
Expand All @@ -86,7 +86,7 @@ def __init__(
self.diagnostic_file = None
self.num_chains = num_chains

def validate(self, chains: Optional[int]) -> None:
def validate(self, chains: int | None) -> None:
"""
Check arguments correctness and consistency.

Expand Down Expand Up @@ -295,16 +295,16 @@ class OptimizeArgs:

def __init__(
self,
algorithm: Optional[str] = None,
init_alpha: Optional[float] = None,
iter: Optional[int] = None,
algorithm: str | None = None,
init_alpha: float | None = None,
iter: int | None = None,
save_iterations: bool = False,
tol_obj: Optional[float] = None,
tol_rel_obj: Optional[float] = None,
tol_grad: Optional[float] = None,
tol_rel_grad: Optional[float] = None,
tol_param: Optional[float] = None,
history_size: Optional[int] = None,
tol_obj: float | None = None,
tol_rel_obj: float | None = None,
tol_grad: float | None = None,
tol_rel_grad: float | None = None,
tol_param: float | None = None,
history_size: int | None = None,
jacobian: bool = False,
) -> None:
self.algorithm = algorithm or ""
Expand All @@ -319,7 +319,7 @@ def __init__(
self.history_size = history_size
self.jacobian = jacobian

def validate(self, _chains: Optional[int] = None) -> None:
def validate(self, _chains: int | None = None) -> None:
"""
Check arguments correctness and consistency.
"""
Expand Down Expand Up @@ -383,13 +383,13 @@ class LaplaceArgs:
"""Arguments needed for laplace method."""

def __init__(
self, mode: str, draws: Optional[int] = None, jacobian: bool = True
self, mode: str, draws: int | None = None, jacobian: bool = True
) -> None:
self.mode = mode
self.jacobian = jacobian
self.draws = draws

def validate(self, _chains: Optional[int] = None) -> None:
def validate(self, _chains: int | None = None) -> None:
"""Check arguments correctness and consistency."""
if not os.path.exists(self.mode):
raise ValueError(f'Invalid path for mode file: {self.mode}')
Expand All @@ -411,18 +411,18 @@ class PathfinderArgs:

def __init__(
self,
init_alpha: Optional[float] = None,
tol_obj: Optional[float] = None,
tol_rel_obj: Optional[float] = None,
tol_grad: Optional[float] = None,
tol_rel_grad: Optional[float] = None,
tol_param: Optional[float] = None,
history_size: Optional[int] = None,
num_psis_draws: Optional[int] = None,
num_paths: Optional[int] = None,
max_lbfgs_iters: Optional[int] = None,
num_draws: Optional[int] = None,
num_elbo_draws: Optional[int] = None,
init_alpha: float | None = None,
tol_obj: float | None = None,
tol_rel_obj: float | None = None,
tol_grad: float | None = None,
tol_rel_grad: float | None = None,
tol_param: float | None = None,
history_size: int | None = None,
num_psis_draws: int | None = None,
num_paths: int | None = None,
max_lbfgs_iters: int | None = None,
num_draws: int | None = None,
num_elbo_draws: int | None = None,
save_single_paths: bool = False,
psis_resample: bool = True,
calculate_lp: bool = True,
Expand All @@ -445,7 +445,7 @@ def __init__(
self.psis_resample = psis_resample
self.calculate_lp = calculate_lp

def validate(self, _chains: Optional[int] = None) -> None:
def validate(self, _chains: int | None = None) -> None:
"""
Check arguments correctness and consistency.
"""
Expand Down Expand Up @@ -514,7 +514,7 @@ def __init__(self, csv_files: list[str]) -> None:

def validate(
self,
chains: Optional[int] = None, # pylint: disable=unused-argument
chains: int | None = None, # pylint: disable=unused-argument
) -> None:
"""
Check arguments correctness and consistency.
Expand Down Expand Up @@ -543,16 +543,16 @@ class VariationalArgs:

def __init__(
self,
algorithm: Optional[str] = None,
iter: Optional[int] = None,
grad_samples: Optional[int] = None,
elbo_samples: Optional[int] = None,
eta: Optional[float] = None,
adapt_iter: Optional[int] = None,
algorithm: str | None = None,
iter: int | None = None,
grad_samples: int | None = None,
elbo_samples: int | None = None,
eta: float | None = None,
adapt_iter: int | None = None,
adapt_engaged: bool = True,
tol_rel_obj: Optional[float] = None,
eval_elbo: Optional[int] = None,
output_samples: Optional[int] = None,
tol_rel_obj: float | None = None,
eval_elbo: int | None = None,
output_samples: int | None = None,
) -> None:
self.algorithm = algorithm
self.iter = iter
Expand All @@ -567,7 +567,7 @@ def __init__(

def validate(
self,
chains: Optional[int] = None, # pylint: disable=unused-argument
chains: int | None = None, # pylint: disable=unused-argument
) -> None:
"""
Check arguments correctness and consistency.
Expand Down Expand Up @@ -633,23 +633,23 @@ def __init__(
self,
model_name: str,
model_exe: str,
chain_ids: Optional[list[int]],
method_args: Union[
SamplerArgs,
OptimizeArgs,
GenerateQuantitiesArgs,
VariationalArgs,
LaplaceArgs,
PathfinderArgs,
],
data: Union[Mapping[str, Any], str, None] = None,
seed: Union[int, np.integer, list[int], list[np.integer], None] = None,
inits: Union[int, float, str, list[str], None] = None,
chain_ids: list[int] | None,
method_args: (
SamplerArgs
| OptimizeArgs
| GenerateQuantitiesArgs
| VariationalArgs
| LaplaceArgs
| PathfinderArgs
),
data: Mapping[str, Any] | str | None = None,
seed: int | np.integer | list[int] | list[np.integer] | None = None,
inits: int | float | str | list[str] | None = None,
output_dir: OptionalPath = None,
sig_figs: Optional[int] = None,
sig_figs: int | None = None,
save_latent_dynamics: bool = False,
save_profile: bool = False,
refresh: Optional[int] = None,
refresh: int | None = None,
) -> None:
"""Initialize object."""
self.model_name = model_name
Expand Down Expand Up @@ -839,8 +839,8 @@ def compose_command(
idx: int,
csv_file: str,
*,
diagnostic_file: Optional[str] = None,
profile_file: Optional[str] = None,
diagnostic_file: str | None = None,
profile_file: str | None = None,
) -> list[str]:
"""
Compose CmdStan command for non-default arguments.
Expand Down
Loading