From 9e95cdb5ae45d9a1696e3897070c874987b2792f Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi Date: Thu, 14 Aug 2025 22:17:55 +0900 Subject: [PATCH 1/4] Refine help messages and improve loop control --- README.md | 13 ++++++------- pygridsynth/cli.py | 14 ++++++++++---- pygridsynth/diophantine.py | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 190df1d..0a02b64 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,12 @@ python -m pygridsynth [options] ### Options -- `--dps`: Sets the working precision of the calculation. If `--dps` is not given, then the working precision will - be calculated from `epsilon`. -- `--dtimeout`, `-dt`: Sets the timeout for solving diophantine equations in milliseconds. -- `--ftimeout`, `-ft`: Sets the timeout for factorization in milliseconds. -- `--dloop`, `-dl`: Sets the maximum loop count for the diophantine algorithm (default: `2000`). -- `--floop`, `-fl`: Sets the maximum loop count for the factoring algorithm (default: `500`). -- `--seed`: Sets the random seed for deterministic results (default: `0`). +- `--dps`: Sets the working precision of the calculation. If not specified, the working precision will be calculated from `epsilon`. +- `--dtimeout`, `-dt`: Maximum milliseconds allowed for a single Diophantine equation solving. +- `--ftimeout`, `-ft`: Maximum milliseconds allowed for a single integer factoring attempt. +- `--dloop`, `-dl`: Maximum number of failed integer factoring attempts allowed during Diophantine equation solving (default: `2000`). +- `--floop`, `-fl`: Maximum number of failed integer factoring attempts allowed during the factoring process (default: `500`). +- `--seed`: Random seed for deterministic results. (default: `0`) - `--verbose`, `-v`: Enables detailed output. - `--time`, `-t`: Measures the execution time. - `--showgraph`, `-g`: Displays the decomposition result as a graph. diff --git a/pygridsynth/cli.py b/pygridsynth/cli.py index b585283..d5dab49 100644 --- a/pygridsynth/cli.py +++ b/pygridsynth/cli.py @@ -7,10 +7,16 @@ from .loop_controller import LoopController helps = { - "dt": "Diophantine algorithm timeout in milliseconds", - "ft": "Factoring algorithm timeout in milliseconds", - "dl": "Diophantine algorithm max loop count", - "fl": "Factoring algorithm max loop count", + "dt": "Maximum milliseconds allowed for a single Diophantine equation solving", + "ft": "Maximum milliseconds allowed for a single integer factoring attempt", + "dl": ( + "Maximum number of failed integer factoring attempts " + "allowed during Diophantine equation solving" + ), + "fl": ( + "Maximum number of failed integer factoring attempts " + "allowed during the factoring process" + ), "seed": "Random seed for deterministic results", } diff --git a/pygridsynth/diophantine.py b/pygridsynth/diophantine.py index 9615f82..cdeac76 100644 --- a/pygridsynth/diophantine.py +++ b/pygridsynth/diophantine.py @@ -26,7 +26,7 @@ def _find_factor(n, loop_controller: LoopController, M=128): L = int(10 ** (len(str(n)) / 4) * 1.1774 + 10) loop_controller.start_factoring() - while loop_controller.check_factoring_continue(): + while True: x = y + n while k < r: q = 1 @@ -47,7 +47,7 @@ def _find_factor(n, loop_controller: LoopController, M=128): if g != 1: break return None if g == n else g - if k >= L: + if k >= L and not loop_controller.check_factoring_continue(): return None r <<= 1 From 535d3fd9eb5fabc76f6160ca98be952b458d0437 Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi <78325943+HirokiHamaguchi@users.noreply.github.com> Date: Fri, 15 Aug 2025 05:53:20 +0900 Subject: [PATCH 2/4] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a02b64..dabfb3d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ python -m pygridsynth [options] - `--dps`: Sets the working precision of the calculation. If not specified, the working precision will be calculated from `epsilon`. - `--dtimeout`, `-dt`: Maximum milliseconds allowed for a single Diophantine equation solving. - `--ftimeout`, `-ft`: Maximum milliseconds allowed for a single integer factoring attempt. -- `--dloop`, `-dl`: Maximum number of failed integer factoring attempts allowed during Diophantine equation solving (default: `2000`). +- `--dloop`, `-dl`: Maximum number of failed integer factoring attempts allowed during Diophantine equation solving (default: `2000`). - `--floop`, `-fl`: Maximum number of failed integer factoring attempts allowed during the factoring process (default: `500`). - `--seed`: Random seed for deterministic results. (default: `0`) - `--verbose`, `-v`: Enables detailed output. From 865f113f932719b79a087ddb4baa579d0e0cb4ca Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi <78325943+HirokiHamaguchi@users.noreply.github.com> Date: Fri, 15 Aug 2025 05:53:28 +0900 Subject: [PATCH 3/4] Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dabfb3d..e6b6d61 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ python -m pygridsynth [options] - `--ftimeout`, `-ft`: Maximum milliseconds allowed for a single integer factoring attempt. - `--dloop`, `-dl`: Maximum number of failed integer factoring attempts allowed during Diophantine equation solving (default: `2000`). - `--floop`, `-fl`: Maximum number of failed integer factoring attempts allowed during the factoring process (default: `500`). -- `--seed`: Random seed for deterministic results. (default: `0`) +- `--seed`: Random seed for deterministic results.(default: `0`) - `--verbose`, `-v`: Enables detailed output. - `--time`, `-t`: Measures the execution time. - `--showgraph`, `-g`: Displays the decomposition result as a graph. From 6d203b11a5b215b1f90498ae3d6666a9a8e3d6f5 Mon Sep 17 00:00:00 2001 From: Hiroki Hamaguchi Date: Fri, 15 Aug 2025 08:38:53 +0900 Subject: [PATCH 4/4] Fix Conflict between isort and black due to different line lengths Fixes #14 --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb91275..2868ff2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,7 @@ repos: rev: 5.13.2 hooks: - id: isort + args: ["--profile", "black"] - repo: https://github.com/pycqa/flake8 rev: 7.1.1 hooks: