cpp-pd-code-simplify-interface 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp +34 -0
- cpp_pd_code_simplify_interface/data/src/native_interface.cpp +32 -54
- cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp +840 -78
- cpp_pd_code_simplify_interface/main.py +47 -5
- {cpp_pd_code_simplify_interface-0.1.2.dist-info → cpp_pd_code_simplify_interface-0.1.4.dist-info}/METADATA +7 -5
- {cpp_pd_code_simplify_interface-0.1.2.dist-info → cpp_pd_code_simplify_interface-0.1.4.dist-info}/RECORD +8 -8
- {cpp_pd_code_simplify_interface-0.1.2.dist-info → cpp_pd_code_simplify_interface-0.1.4.dist-info}/WHEEL +0 -0
- {cpp_pd_code_simplify_interface-0.1.2.dist-info → cpp_pd_code_simplify_interface-0.1.4.dist-info}/entry_points.txt +0 -0
|
@@ -402,6 +402,9 @@ def _load_library() -> ctypes.CDLL:
|
|
|
402
402
|
ctypes.c_char_p,
|
|
403
403
|
ctypes.c_int,
|
|
404
404
|
ctypes.c_int,
|
|
405
|
+
ctypes.c_int,
|
|
406
|
+
ctypes.c_int,
|
|
407
|
+
ctypes.c_int,
|
|
405
408
|
ctypes.c_ulonglong,
|
|
406
409
|
ctypes.POINTER(ctypes.c_int),
|
|
407
410
|
ctypes.c_ulonglong,
|
|
@@ -419,9 +422,16 @@ def _run_one(
|
|
|
419
422
|
*,
|
|
420
423
|
max_paths: int = -1,
|
|
421
424
|
ban_heuristic: bool = False,
|
|
425
|
+
reduction_round: int = -1,
|
|
426
|
+
max_thread: int = -1,
|
|
427
|
+
verbose: bool = False,
|
|
422
428
|
known_crossingless_components: int = 0,
|
|
423
429
|
remove_crossings: Optional[Sequence[int]] = None,
|
|
424
430
|
) -> dict[str, Any]:
|
|
431
|
+
if reduction_round < -1:
|
|
432
|
+
raise ValueError("reduction_round must be -1 or a non-negative integer")
|
|
433
|
+
if max_thread < -1 or max_thread == 0:
|
|
434
|
+
raise ValueError("max_thread must be -1 or a positive integer")
|
|
425
435
|
library = _load_library()
|
|
426
436
|
removed_count = 0 if remove_crossings is None else len(remove_crossings)
|
|
427
437
|
removed_array = None
|
|
@@ -432,6 +442,9 @@ def _run_one(
|
|
|
432
442
|
pd_text.encode("utf-8"),
|
|
433
443
|
int(max_paths),
|
|
434
444
|
1 if ban_heuristic else 0,
|
|
445
|
+
int(reduction_round),
|
|
446
|
+
int(max_thread),
|
|
447
|
+
1 if verbose else 0,
|
|
435
448
|
int(known_crossingless_components),
|
|
436
449
|
removed_array,
|
|
437
450
|
int(removed_count),
|
|
@@ -457,6 +470,9 @@ def simplify(
|
|
|
457
470
|
*,
|
|
458
471
|
max_paths: int = -1,
|
|
459
472
|
ban_heuristic: bool = False,
|
|
473
|
+
reduction_round: int = -1,
|
|
474
|
+
max_thread: int = -1,
|
|
475
|
+
verbose: bool = False,
|
|
460
476
|
known_crossingless_components: int = 0,
|
|
461
477
|
remove_crossings: Optional[Sequence[int]] = None,
|
|
462
478
|
) -> dict[str, Any]:
|
|
@@ -466,6 +482,9 @@ def simplify(
|
|
|
466
482
|
normalize_pd_code(pd_code),
|
|
467
483
|
max_paths=max_paths,
|
|
468
484
|
ban_heuristic=ban_heuristic,
|
|
485
|
+
reduction_round=reduction_round,
|
|
486
|
+
max_thread=max_thread,
|
|
487
|
+
verbose=verbose,
|
|
469
488
|
known_crossingless_components=known_crossingless_components,
|
|
470
489
|
remove_crossings=remove_crossings,
|
|
471
490
|
)
|
|
@@ -476,6 +495,9 @@ def simplify_many(
|
|
|
476
495
|
*,
|
|
477
496
|
max_paths: int = -1,
|
|
478
497
|
ban_heuristic: bool = False,
|
|
498
|
+
reduction_round: int = -1,
|
|
499
|
+
max_thread: int = -1,
|
|
500
|
+
verbose: bool = False,
|
|
479
501
|
known_crossingless_components: int = 0,
|
|
480
502
|
remove_crossings: Optional[Sequence[int]] = None,
|
|
481
503
|
) -> list[dict[str, Any]]:
|
|
@@ -486,6 +508,9 @@ def simplify_many(
|
|
|
486
508
|
pd_text,
|
|
487
509
|
max_paths=max_paths,
|
|
488
510
|
ban_heuristic=ban_heuristic,
|
|
511
|
+
reduction_round=reduction_round,
|
|
512
|
+
max_thread=max_thread,
|
|
513
|
+
verbose=verbose,
|
|
489
514
|
known_crossingless_components=known_crossingless_components,
|
|
490
515
|
remove_crossings=remove_crossings,
|
|
491
516
|
)
|
|
@@ -496,16 +521,27 @@ def simplify_many(
|
|
|
496
521
|
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
497
522
|
parser = argparse.ArgumentParser(description="Run cpp-pd-code-simplify through the Python interface.")
|
|
498
523
|
parser.add_argument("pd_code", nargs="?", help="PD code as PD[...] text or a Python-style list of crossings.")
|
|
524
|
+
parser.add_argument("--pd-code", "-c", dest="pd_code_option", help="literal PD[...] string")
|
|
499
525
|
parser.add_argument("--pd-file", "-f", help="read one file containing one or more labelled PD-code lines")
|
|
500
526
|
parser.add_argument("--max-paths", type=int, default=-1)
|
|
501
527
|
parser.add_argument("--ban-heuristic", action="store_true")
|
|
528
|
+
parser.add_argument("--reduction-round", type=int, default=-1)
|
|
529
|
+
parser.add_argument("--max-thread", type=int, default=-1)
|
|
530
|
+
parser.add_argument("--verbose", action="store_true")
|
|
502
531
|
parser.add_argument("--known-crossingless-components", type=int, default=0)
|
|
503
532
|
parser.add_argument("--remove-crossings", help="comma-separated zero-based crossing indices")
|
|
504
533
|
args = parser.parse_args(argv)
|
|
505
|
-
if args.
|
|
506
|
-
parser.error("
|
|
507
|
-
if
|
|
508
|
-
parser.error("
|
|
534
|
+
if args.reduction_round < -1:
|
|
535
|
+
parser.error("--reduction-round must be -1 or a non-negative integer")
|
|
536
|
+
if args.max_thread < -1 or args.max_thread == 0:
|
|
537
|
+
parser.error("--max-thread must be -1 or a positive integer")
|
|
538
|
+
if args.pd_code and args.pd_code_option:
|
|
539
|
+
parser.error("pass either a positional PD code or --pd-code, not both")
|
|
540
|
+
pd_code_text = args.pd_code_option or args.pd_code
|
|
541
|
+
if args.pd_file and pd_code_text:
|
|
542
|
+
parser.error("pass either a PD code or --pd-file, not both")
|
|
543
|
+
if not args.pd_file and not pd_code_text:
|
|
544
|
+
parser.error("a PD code or --pd-file is required")
|
|
509
545
|
remove_crossings = None
|
|
510
546
|
if args.remove_crossings:
|
|
511
547
|
remove_crossings = [int(token) for token in re.findall(r"-?\d+", args.remove_crossings)]
|
|
@@ -521,6 +557,9 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
521
557
|
line,
|
|
522
558
|
max_paths=args.max_paths,
|
|
523
559
|
ban_heuristic=args.ban_heuristic,
|
|
560
|
+
reduction_round=args.reduction_round,
|
|
561
|
+
max_thread=args.max_thread,
|
|
562
|
+
verbose=args.verbose,
|
|
524
563
|
known_crossingless_components=args.known_crossingless_components,
|
|
525
564
|
remove_crossings=remove_crossings,
|
|
526
565
|
)
|
|
@@ -536,9 +575,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
536
575
|
payload: Any = batch_payload
|
|
537
576
|
else:
|
|
538
577
|
payload = simplify(
|
|
539
|
-
|
|
578
|
+
pd_code_text or "",
|
|
540
579
|
max_paths=args.max_paths,
|
|
541
580
|
ban_heuristic=args.ban_heuristic,
|
|
581
|
+
reduction_round=args.reduction_round,
|
|
582
|
+
max_thread=args.max_thread,
|
|
583
|
+
verbose=args.verbose,
|
|
542
584
|
known_crossingless_components=args.known_crossingless_components,
|
|
543
585
|
remove_crossings=remove_crossings,
|
|
544
586
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cpp-pd-code-simplify-interface
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Python interface for cpp-pd-code-simplify with runtime C++ compilation.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Author: GGN_2015
|
|
@@ -35,7 +35,7 @@ use, the package compiles a cached local dynamic library through
|
|
|
35
35
|
compiler compatible with `g++` must be available at runtime.
|
|
36
36
|
|
|
37
37
|
Calls use the C++ library's default preprocessing pipeline: R1-move removal
|
|
38
|
-
followed by nugatory-crossing removal.
|
|
38
|
+
followed by nugatory-crossing removal, then iterative mid-simplification.
|
|
39
39
|
|
|
40
40
|
## Example
|
|
41
41
|
|
|
@@ -44,12 +44,14 @@ import cpp_pd_code_simplify_interface as simplify
|
|
|
44
44
|
|
|
45
45
|
pd_code = "PD[X[1,5,2,4],X[3,1,4,6],X[5,3,6,2]]"
|
|
46
46
|
result = simplify.simplify(pd_code)
|
|
47
|
-
print(result["
|
|
47
|
+
print(result["final_pd_code"])
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
The default `max_paths=-1` uses deterministic heuristic green-path sampling in
|
|
51
51
|
the C++ backend. Use `ban_heuristic=True` to request exhaustive green-path
|
|
52
|
-
enumeration for a manageable input.
|
|
52
|
+
enumeration for a manageable input. Use `reduction_round=K` to cap applied
|
|
53
|
+
mid-simplification rounds; the default `-1` runs until stable. Use
|
|
54
|
+
`verbose=True` to forward C++ progress logs to stderr.
|
|
53
55
|
|
|
54
56
|
Batch use:
|
|
55
57
|
|
|
@@ -76,7 +78,7 @@ Python process needs a 64-bit compiler target.
|
|
|
76
78
|
Command-line use also supports multi-line PD-code files:
|
|
77
79
|
|
|
78
80
|
```sh
|
|
79
|
-
python -m cpp_pd_code_simplify_interface --pd-file inputs.pd --max-paths -1
|
|
81
|
+
python -m cpp_pd_code_simplify_interface --pd-file inputs.pd --max-paths -1 --verbose
|
|
80
82
|
```
|
|
81
83
|
|
|
82
84
|
## Build And Publish
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
cpp_pd_code_simplify_interface/__init__.py,sha256=aaNwD--zgQX13xiU1hpuvgXy8vVTFGRk-r5zLm8zIRY,447
|
|
2
2
|
cpp_pd_code_simplify_interface/__main__.py,sha256=fdA1QWBe5LNX0fbtaJXa1-dwEhrg_4sS_5UnjaajcMo,80
|
|
3
|
-
cpp_pd_code_simplify_interface/main.py,sha256=
|
|
3
|
+
cpp_pd_code_simplify_interface/main.py,sha256=_7dPNfbtUxAC8o9cZOOwicU04zIFIA55nHIzQ_UZunw,20624
|
|
4
4
|
cpp_pd_code_simplify_interface/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
-
cpp_pd_code_simplify_interface-0.1.
|
|
6
|
-
cpp_pd_code_simplify_interface-0.1.
|
|
7
|
-
cpp_pd_code_simplify_interface-0.1.
|
|
8
|
-
cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp,sha256=
|
|
9
|
-
cpp_pd_code_simplify_interface/data/src/native_interface.cpp,sha256=
|
|
10
|
-
cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp,sha256=
|
|
11
|
-
cpp_pd_code_simplify_interface-0.1.
|
|
5
|
+
cpp_pd_code_simplify_interface-0.1.4.dist-info/entry_points.txt,sha256=ThorC4Enxp317TKITsXm9pE0gUp7pt-pP6Dl5mEPUR8,91
|
|
6
|
+
cpp_pd_code_simplify_interface-0.1.4.dist-info/METADATA,sha256=CIMcDMWX0fa01RY04zPmN-B1D_YSKCGyNRdVWoDIrHI,2905
|
|
7
|
+
cpp_pd_code_simplify_interface-0.1.4.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
|
|
8
|
+
cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp,sha256=P8XgFxLelCFesArCrKJ_UwqG7LlpoXiegNHLOV-DhG8,5162
|
|
9
|
+
cpp_pd_code_simplify_interface/data/src/native_interface.cpp,sha256=LnffzIhwbGbw4xDTp5QXd-Vx23Nc9y5Xgr0AdbULlF0,6077
|
|
10
|
+
cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp,sha256=ptDTjjSlx_Lq_2snHYWgjnIbr-mGsDG7rqTevuqoSEc,94195
|
|
11
|
+
cpp_pd_code_simplify_interface-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|