From de846d0042edbf04a3f0905351b3b967c16ca635 Mon Sep 17 00:00:00 2001 From: isty2e Date: Tue, 28 Jul 2026 23:50:14 +0900 Subject: [PATCH 1/2] chore: format Markdown examples with Ruff --- .github/workflows/canary.yml | 2 +- .github/workflows/ci.yml | 4 +++- .pre-commit-config.yaml | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml index 40144c24..a60a132a 100644 --- a/.github/workflows/canary.yml +++ b/.github/workflows/canary.yml @@ -20,7 +20,7 @@ jobs: - name: Lint with latest compatible dependencies run: uv run --upgrade --python 3.13 --extra test ruff check --extend-select I,UP pyproject.toml src tests .github/scripts - name: Format check with latest compatible dependencies - run: uv run --upgrade --python 3.13 --extra test ruff format --check pyproject.toml src tests .github/scripts + run: uv run --upgrade --python 3.13 --extra test ruff format --check . - name: Type check with latest compatible dependencies run: uv run --upgrade --python 3.13 --extra test basedpyright src tests .github/scripts - name: Pre-commit with latest compatible dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87a153fc..b6b13bb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: - "tests/**" - "docs/**" - "mkdocs.yml" + - "README.md" - "CHANGELOG.md" - "pyproject.toml" - ".gitignore" @@ -23,6 +24,7 @@ on: - "tests/**" - "docs/**" - "mkdocs.yml" + - "README.md" - "CHANGELOG.md" - "pyproject.toml" - ".gitignore" @@ -53,7 +55,7 @@ jobs: - name: Lint run: uv run --python ${{ matrix.python-version }} --extra test ruff check --extend-select I,UP pyproject.toml src tests .github/scripts - name: Format check - run: uv run --python ${{ matrix.python-version }} --extra test ruff format --check pyproject.toml src tests .github/scripts + run: uv run --python ${{ matrix.python-version }} --extra test ruff format --check . - name: Type check run: uv run --python ${{ matrix.python-version }} --extra test basedpyright src tests .github/scripts - name: Test diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f00bea62..dedd5023 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,7 @@ repos: - id: ruff-check args: ["--fix", "--extend-select=I,UP"] - id: ruff-format + types_or: [python, pyi, jupyter, markdown] - repo: local hooks: - id: basedpyright From 108ef7a4e75db4084df6a687ed4eb7858b1e06d6 Mon Sep 17 00:00:00 2001 From: isty2e Date: Tue, 28 Jul 2026 23:50:27 +0900 Subject: [PATCH 2/2] docs: apply Ruff formatting to Python examples --- docs/getting-started/quickstart.md | 6 +++--- docs/guides/canonical-usage-patterns.md | 7 ++----- docs/guides/choose-an-optimizer.md | 8 ++++++-- docs/guides/customize-optimizer-profile.md | 12 +++--------- docs/index.md | 4 +++- docs/reference/checkpointing.md | 4 +++- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index ead1e06a..e97296c0 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -40,10 +40,10 @@ result, final_state = study.optimize(max_evaluations=40) ```python best = result.best_observation print(best.candidate) # the best candidate found (e.g. 0) -print(best.value) # raw objective value (e.g. 0.0) +print(best.value) # raw objective value (e.g. 0.0) -print(result.evaluation_count) # total evaluations consumed -print(len(result.observations)) # number of observed candidates +print(result.evaluation_count) # total evaluations consumed +print(len(result.observations)) # number of observed candidates ``` `best_observation` is an [`Observation`][variopt.Observation] — it carries the diff --git a/docs/guides/canonical-usage-patterns.md b/docs/guides/canonical-usage-patterns.md index 559d2840..3db784cf 100644 --- a/docs/guides/canonical-usage-patterns.md +++ b/docs/guides/canonical-usage-patterns.md @@ -77,9 +77,7 @@ def evaluate_success( ) -successes = tuple( - evaluate_success(request) for request in requests -) +successes = tuple(evaluate_success(request) for request in requests) assert sum(success.evaluation_count for success in successes) == 2 assert [success.payload.label for success in successes] == [ @@ -258,8 +256,7 @@ records = tuple( ) ) successes = tuple( - EvaluationSuccess(request=record.request, payload=record) - for record in records + EvaluationSuccess(request=record.request, payload=record) for record in records ) report = RunReport[int, ObjectiveVectorRecord[int]].from_successes( diff --git a/docs/guides/choose-an-optimizer.md b/docs/guides/choose-an-optimizer.md index 319d7a6e..c3cb8d52 100644 --- a/docs/guides/choose-an-optimizer.md +++ b/docs/guides/choose-an-optimizer.md @@ -26,7 +26,9 @@ and perturbation schedule from the declared space semantics automatically. from variopt.algorithms.population import CSAOptimizer optimizer = CSAOptimizer.from_space_defaults( - space=space, bank_capacity=12, random_state=0, + space=space, + bank_capacity=12, + random_state=0, ) ``` @@ -41,7 +43,9 @@ Good broad continuous baseline. Requires all leaves to be numeric. from variopt.algorithms.population import DifferentialEvolutionOptimizer optimizer = DifferentialEvolutionOptimizer( - space=space, population_size=20, random_state=0, + space=space, + population_size=20, + random_state=0, ) ``` diff --git a/docs/guides/customize-optimizer-profile.md b/docs/guides/customize-optimizer-profile.md index f62c4896..22538cea 100644 --- a/docs/guides/customize-optimizer-profile.md +++ b/docs/guides/customize-optimizer-profile.md @@ -137,12 +137,8 @@ from variopt.algorithms.population.csa import ( space = IntegerSpace(low=0, high=31) schedule = CSAPerturbationSchedule( - regular_family=( - CSAPerturbationSpec(UniformCrossover(space=space), count=4), - ), - initial_family=( - CSAPerturbationSpec(UniformCrossover(space=space), count=2), - ), + regular_family=(CSAPerturbationSpec(UniformCrossover(space=space), count=4),), + initial_family=(CSAPerturbationSpec(UniformCrossover(space=space), count=2),), mutation_family=( CSAPerturbationSpec(BoundedMutation(space=space), count=3), CSAPerturbationSpec(RandomResetMutation(space=space), count=1), @@ -220,9 +216,7 @@ from variopt.diversity import StructuredSpaceDiversityMetric space = IntegerSpace(low=0, high=99) schedule = CSAPerturbationSchedule( - mutation_family=( - CSAPerturbationSpec(BoundedMutation(space=space), count=3), - ), + mutation_family=(CSAPerturbationSpec(BoundedMutation(space=space), count=3),), ) profile: CSAProfile[int] = CSAProfile( diff --git a/docs/index.md b/docs/index.md index 9f5b39bd..89fd7867 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,9 @@ space = RecordSpace( study = Study( problem=Problem(space=space, objective=SphereObjective()), - run_method=CSAOptimizer.from_space_defaults(space=space, bank_capacity=12, random_state=0), + run_method=CSAOptimizer.from_space_defaults( + space=space, bank_capacity=12, random_state=0 + ), evaluator=SequentialEvaluator(), ) result, _ = study.optimize(max_evaluations=100) diff --git a/docs/reference/checkpointing.md b/docs/reference/checkpointing.md index bd315ecc..575b0280 100644 --- a/docs/reference/checkpointing.md +++ b/docs/reference/checkpointing.md @@ -47,7 +47,9 @@ class SquareObjective(Objective[int]): space = IntegerSpace(0, 20) optimizer = CSAOptimizer.from_space_defaults( - space=space, bank_capacity=8, random_state=0, + space=space, + bank_capacity=8, + random_state=0, ) study = Study( problem=Problem(space=space, objective=SquareObjective()),